def mostCommon(spoken, lst, threshold):
highestCountItem = max(lst, key=lst.count)
highestCount = lst.count(highestCountItem)
contenders = []
for item in lst:
if (lst.count(item) == highestCount) and (item not in contenders):
contenders.append(item)
if len(contenders) > 1:
print "\nContending"
bestMatch = [None, 0]
for ayah in contenders:
score = ratio(spoken, ayah)
print ayah
print score
if score > threshold and score > bestMatch[1]:
bestMatch = [ayah, score]
return bestMatch[0]
elif ratio(spoken, highestCountItem) > threshold:
return highestCountItem
else:
return None
# Takes in a query and list of matches
# Returns the match with the highest similarity to the query
评论列表
文章目录