-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
TrueDamerauLevenshtein giving wrong results #3
Comments
Yup, the implementation was wrong, I've corrected it and added the case above in the tests too. |
Thanks for the fix! Unfortunately, the algorithm still doesn’t seem entirely correct (tested with v0.0.2-0.20200403031649-7456955b3f48). Here are a few more samples for input where it spits out the wrong result: params: (3AWPLE, 9C9TEL), stringdist = 6, tdl = 5 |
Out of curiosity, I tried finding other calculators in the wild to check the results, and it seems to match mine... https://planetcalc.com/1721/ Take for example
Both links above returned 6 too. |
I believe the difference lies in this line: It seems like the author forgot to add 1 for each index. Before: d[k][l]+(i-k-1)+1+(j-l-1), // transposition After: d[k][l]+(i-k)+1+(j-l), // transposition |
However:
Are you saying the Perl implementation is also incorrect? |
These links only calculates the levenshtein distance and won't handle transpositions. For fun I ran your code against my tests:
I'm fairly sure your |
I noticed that these 2 Go libraries differ in results for the same input:
(stringdist.TrueDamerauLevenshtein).Calculate(4XHYWD, YLKTW9) = 6
tdl.Distance(4XHYWD, YLKTW9) = 5
Looking at the Perl implementation Text::Levenshtein::Damerau, both implementations (pure perl and XS) return 5:
…hence, I think the issue lies within your implementation. Could you take a look please?
PS: the edge case where
s == t
does not return 0 in your implementation either. Not sure if it’s the same bug or a separate issue.The text was updated successfully, but these errors were encountered: