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