Closed PeterPirog closed 3 years ago
What do you mean by adding the Damerau-Levenshtein metric? Technically, the library does the following changes, up to edit distance of 2:
By edit distance of 2, that means, in this case, up to two of these actions.
As I understand basic operations (with distance 1) for Levenshtein metric are insertion, deletion and replacement but for Damerau-Levenshtein additionally basic operation is transposition too. In some practical cases I observed that transposition of letter is common:
weird or werid strength or strenght
These examples above has distance = 1 in Damerau-Levenshtein metric and distance =2 in Levenshtein metric, so it's nice to add option to switch between Levenshtein metric or Damerau-Levenshtein metric.
If you look at the code here you can see that we are already treating transposes as edit distance of 1. Are you not seeing transposition as an edit distance of 1?
Thank you for the info. Maybe I did something wrong in my code.
Sounds good. If you are seeing it not do transpositions as distance 1, please let me know! If there is nothing else, I will close this ticket out in the next few days.
Using this test case, it looks like the transposition is working as expected.
from spellchecker import SpellChecker
spell = SpellChecker(distance=1)
misspelled = spell.unknown(["trhee"])
print(misspelled) # show it isn't correct
for word in misspelled:
print(spell.edit_distance_1(word))
print(spell.correction(word))
Please reopen this issue if you have an example of it not working as expected. Thanks!
Is possibile to add optionally Damerau-Levenshtein metric?