コード例 #1
0
def median_word(words, word_counts):
    median = lev.median(words, word_counts)
    while True:
        last_median = median
        median = lev.median_improve(median, words, word_counts)
        if median == last_median:
            break
    return median
コード例 #2
0
def get_median(words, counts):
    median = lev.median(words, counts)
    # print median,
    while True:
        last_median = median
        median = lev.median_improve(median, words, counts)
        # print "-->", median,
        if median == last_median:
            break
    return median
コード例 #3
0
 def median_string(self, strings, string_counts):
     # Find a 'median string' which is a string with the minimal
     # sum of edit distances to each string in a list of strings.
     # see: https://pypi.python.org/pypi/python-Levenshtein/0.11.2
     # Note the python package above also permits the use of
     # weights for each string (e.g. counts of occurances)
     median = Levenshtein.median(strings, string_counts)
     while True:
         last_median = median
         median = Levenshtein.median_improve(median, strings, string_counts)
         if median == last_median:
             break
     return median