def best(inputted_word, suggestions, word_model=None):
""" ? ????????? ????? ??????????? ???????? ??????, ??????????? ???? ?? ?????????? ????????,
???? ?? ??????????? ???? ? ????????? ?????? """
suggestions = list(suggestions)
def comparehamm(one, two):
score1 = hamming_distance(inputted_word, one)
score2 = hamming_distance(inputted_word, two)
return cmp2(score1, score2) # lower is better
def comparefreq(one, two):
score1 = frequency(one, word_model)
score2 = frequency(two, word_model)
return cmp2(score2, score1) # higher is better
freq_sorted = sorted(suggestions, key=functools.cmp_to_key(comparefreq))[:10] # take the top 10
hamming_sorted = sorted(suggestions, key=functools.cmp_to_key(comparehamm))[:10] # take the top 10
return freq_sorted[0]
评论列表
文章目录