目录
Damerau–Levenshtein distance: another distance
Definition
In information theory, linguistics, and computer science, the Levenshtein distance is a string metric for measuring the difference between two sequences. Informally, the Levenshtein distance between two words is the minimum number of single-character edits (insertions, deletions or substitutions) required to change one word into the other. It is named after the Soviet mathematician Vladimir Levenshtein, who considered this distance in 1965.
——from Wikipedia
——from Wikipedia
Inplementation
def Levenshtein_Distance(a,b):
l1,l2 = len(a),len(b)
if min(l1,l2) == 0:
return max(l1,l2)
elif a[0] == b[0]:
return Levenshtein_Distance(a[1:],b[1:])
else:
return 1 + min(Levenshtein_Distance(a[1:],b),Levenshtein_Distance(a,b[1:]),Levenshtein_Distance(a[1:],b[1:]))
Damerau–Levenshtein distance: another distance
In information theory and computer science, the Damerau–Levenshtein distance (named after Frederick J. Damerau and Vladimir I. Levenshtein) is a string metric for measuring the edit distance between two sequences. Informally, the Damerau–Levenshtein distance between two words is the minimum number of operations (consisting of insertions, deletions or substitutions of a single character, or transposition of two adjacent characters) required to change one word into the other.
The Damerau–Levenshtein distance differs from the classical Levenshtein distance by including transpositions among its allowable operations in addition to the three classical single-character edit operations (insertions, deletions and substitutions).