Class LevenshteinEditDistance
java.lang.Object
com.google.errorprone.names.LevenshteinEditDistance
A utility class for finding the Levenshtein edit distance between strings. The edit distance
between two strings is the number of deletions, insertions, and substitutions required to
transform the source to the target. See
https://en.wikipedia.org/wiki/Levenshtein_distance.
- Author:
- eaftan@google.com (Eddie Aftandilian)
-
Method Summary
Modifier and TypeMethodDescriptionstatic int
getEditDistance
(String source, String target) Returns the edit distance between two strings.static int
getEditDistance
(String source, String target, boolean caseSensitive) Returns the edit distance between two strings.static int
getWorstCaseEditDistance
(int sourceLength, int targetLength) Calculate the worst case distance between two strings with the given lengths
-
Method Details
-
getEditDistance
-
getEditDistance
Returns the edit distance between two strings. The algorithm used to calculate this distance has space requirements of len(source)*len(target).- Parameters:
source
- The source string.target
- The target stringcaseSensitive
- If true, case is used in comparisons and 'a' != 'A'.- Returns:
- The edit distance between the source and target strings.
- See Also:
-
getWorstCaseEditDistance
public static int getWorstCaseEditDistance(int sourceLength, int targetLength) Calculate the worst case distance between two strings with the given lengths
-