public class Levenshtein extends Object
| Constructor and Description |
|---|
Levenshtein() |
| Modifier and Type | Method and Description |
|---|---|
static int |
getLevenshteinDistance(CharSequence s,
CharSequence t,
int threshold)
Find the Levenshtein distance between two Strings if it's less than or equal to a given
threshold.
|
public static int getLevenshteinDistance(CharSequence s, CharSequence t, int threshold)
Find the Levenshtein distance between two Strings if it's less than or equal to a given threshold.
This is the number of changes needed to change one String into another, where each change is a single character modification (deletion, insertion or substitution).
This implementation follows from Algorithms on Strings, Trees and Sequences by Dan Gusfield and Chas Emerick's implementation of the Levenshtein distance algorithm from http://www.merriampark.com/ld.htm
StringUtils.getLevenshteinDistance(null, *, *) = IllegalArgumentException
StringUtils.getLevenshteinDistance(*, null, *) = IllegalArgumentException
StringUtils.getLevenshteinDistance(*, *, -1) = IllegalArgumentException
StringUtils.getLevenshteinDistance("","", 0) = 0
StringUtils.getLevenshteinDistance("aaapppp", "", 8) = 7
StringUtils.getLevenshteinDistance("aaapppp", "", 7) = 7
StringUtils.getLevenshteinDistance("aaapppp", "", 6)) = -1
StringUtils.getLevenshteinDistance("elephant", "hippo", 7) = 7
StringUtils.getLevenshteinDistance("elephant", "hippo", 6) = -1
StringUtils.getLevenshteinDistance("hippo", "elephant", 7) = 7
StringUtils.getLevenshteinDistance("hippo", "elephant", 6) = -1
s - the first String, must not be nullt - the second String, must not be nullthreshold - the target threshold, must not be negative-1 if the distance would be greater than the thresholdIllegalArgumentException - if either String input null or negative thresholdCopyright © 2017. All Rights Reserved.