dac98aa891588741857483a68eb7f6eda4d4d4c7,synonyms/__init__.py,,_levenshtein_distance,#Any#Any#,192

Before Change


    Based on:
        http://rosettacode.org/wiki/Levenshtein_distance//Python
    """
    first = sentence1.split()
    second = sentence2.split()
    if len(first) > len(second):
        first, second = second, first
    distances = range(len(first) + 1)

After Change


        http://rosettacode.org/wiki/Levenshtein_distance//Python
    """
    first = any2utf8(sentence1).decode("utf-8", "ignore")
    second = any2utf8(sentence2).decode("utf-8", "ignore")
    sentence1_len, sentence2_len = len(first), len(second)
    maxlen = max(sentence1_len, sentence2_len)
    if sentence1_len > sentence2_len:
        first, second = second, first

    distances = range(len(first) + 1)
    for index2, char2 in enumerate(second):
        new_distances = [index2 + 1]
        for index1, char1 in enumerate(first):
            if char1 == char2:
                new_distances.append(distances[index1])
            else:
                new_distances.append(1 + min((distances[index1],
                                             distances[index1 + 1],
                                             new_distances[-1])))
        distances = new_distances
    levenshtein = distances[-1]
    dis = float((maxlen - levenshtein)/maxlen)
    // smoothing
    s = (sigmoid(dis * 6) - 0.5) * 2
    // print("smoothing[%s| %s]: %s -> %s" % (sentence1, sentence2, dis, s))
    return s
Italian Trulli
In pattern: SUPERPATTERN

Frequency: 4

Non-data size: 3

Instances


Project Name: huyingxi/Synonyms
Commit Name: dac98aa891588741857483a68eb7f6eda4d4d4c7
Time: 2018-03-01
Author: hailiang.hl.wang@gmail.com
File Name: synonyms/__init__.py
Class Name:
Method Name: _levenshtein_distance


Project Name: fxsjy/jieba
Commit Name: 99d0fb1a8a00c80c97271b2cc58d52c4fcff0032
Time: 2015-11-09
Author: abcdoyle888@gmail.com
File Name: jieba/__init__.py
Class Name: Tokenizer
Method Name: load_userdict


Project Name: home-assistant/home-assistant
Commit Name: b6ad0bfbea0fdbdc62de331124908ee49212edf9
Time: 2016-08-28
Author: teagan@aptotude.com
File Name: homeassistant/components/sensor/speedtest.py
Class Name: SpeedtestData
Method Name: update


Project Name: arraiy/torchgeometry
Commit Name: 206798edabf99a8ee4bb03ffba25968d2057bb18
Time: 2020-07-30
Author: anguelos.nicolaou@gmail.com
File Name: setup.py
Class Name:
Method Name: