public final class LevenshteinDistance extends Object
Modifier and Type | Field and Description |
---|---|
static int |
MAX_DISTANCE |
Modifier and Type | Method and Description |
---|---|
static int |
levenshteinDistanceK(CharSequence s1,
CharSequence s2)
K-bounded Levenshtein distance with threshold
MAX_DISTANCE (maximum allowed
distance). |
static double |
normalizedLevenshteinDistance(CharSequence s1,
CharSequence s2)
Calculates Levenshtein distance normalized to range [0,1].
|
public static final int MAX_DISTANCE
public static double normalizedLevenshteinDistance(CharSequence s1, CharSequence s2)
s1
- the fist string to compares2
- the second string to comparepublic static int levenshteinDistanceK(CharSequence s1, CharSequence s2)
MAX_DISTANCE
(maximum allowed
distance).
Algorithnm was adapted from
https://github.com/jmcejuela/Levenshtein-MySQL-UDF/blob/master/levenshtein.c#L269
with kind permission of its author Juan Miguel Cejuela
Time O(MAX_DISTANCE * L) where L = min(s1.length(), s2.length());
space O(MAX_DISTANCE), constant.s1
- the first string to compares2
- the second string to compareMAX_DISTANCE
if the distance is
>= MAX_DISTANCECopyright © 2013. All Rights Reserved.