python-Levenshtein icon indicating copy to clipboard operation
python-Levenshtein copied to clipboard

editops's result do not match the ratio's result

Open brealisty opened this issue 5 years ago • 2 comments

str1 = 'AB1010' str2 = '1010AB' ratio' result --> 0.6666, that means there are 4 steps(2 delete, 2 insert),(12-4)/12; editops' result --> [('replace', 0, 0), ('replace', 1, 1), ('replace', 4, 4), ('replace', 5, 5)], obviously, this anwser not match (12-4)/12, instead of (12-8)/12.

some differences in those two function about the edit distance?

brealisty avatar Apr 13 '20 07:04 brealisty

Not sure, but could be linked to an issue in the editops_from_cost_matrix function. Check a possible solution here: https://github.com/ztane/python-Levenshtein/issues/16#issuecomment-613626787

BobLd avatar Apr 14 '20 19:04 BobLd

Editops uses the normal uniform Levenshtein distance, while ratio uses the InDel Distance (no Substitutions). In this specific implementation this is achived by giving substitutions a weight of 2 which is similar to a Insertion + a Deletion.

maxbachmann avatar Apr 13 '21 03:04 maxbachmann