Problems with Levenshtein algorithm in Java

后端 未结 5 748
情深已故
情深已故 2021-02-08 20:16

I want to use the Levenshtein algorithm for the following task: if a user on my website searches for some value (he enters characters in a input), I want to instantly check for

5条回答
  •  广开言路
    2021-02-08 21:03

    There is an open-source library, java-util (https://github.com/jdereg/java-util) that has a StringUtilities.levenshteinDistance(string1, string2) API that is implemented in O(N^2) complexity and uses memory only proportional to O(N) [as discussed above].

    This library also includes damerauLevenshteinDisance() as well. Damerau-Levenshtein counts the character transposition (swap) as one edit, where as proper levenshtein counts it as two edits. The downside to Damerau-Levenshtein is that it is does not have triangular equality like the original levenshtein.

    Great depiction of triangular equality:

    http://richardminerich.com/2012/09/levenshtein-distance-and-the-triangle-inequality/

提交回复
热议问题