Search code examples
javastringlevenshtein-distancefuzzy-search

Matching two strings allowing a single swap


I am running a fuzzy match algorithm, that allows two strings to have a single difference by Levenshtein metrics. But there is a frequent misprint when two consequent letters are swapped:

Jonathan -> Joanthan

professional -> profesisonal

but those differencies give 2 by Levenshtein. How do I match those differencies also?


Solution

  • What you describe is the Damerau–Levenshtein distance. It's the Levenshtein distance including adjacent transpositions.