def getStopFromString(self, candidate):
normalizedCandidate = Stop.normalizeStopName(candidate)
if not Tpg.getTodaysStops():
return None
for stop in Tpg.getTodaysStops():
if candidate.upper() == stop.code:
return stop
if normalizedCandidate == stop.normalizedName:
return stop
for stop in Tpg.getTodaysStops():
if normalizedCandidate in stop.normalizedName:
return stop
# calculate the Levenshtein distance to all stop names
codeToLevenshtein = {stop: Levenshtein.distance(
normalizedCandidate, stop.normalizedName) for stop in Tpg.getTodaysStops()}
# smallest Levenshtein distance
minimum = min(codeToLevenshtein, key=codeToLevenshtein.get)
return minimum
评论列表
文章目录