| Modifier and Type | Field and Description |
|---|---|
static Pattern |
STANDARD_CHARS |
| Constructor and Description |
|---|
LevenshteinDistance(String baseString,
boolean caseSensitive)
Create a new instance.
|
LevenshteinDistance(String baseString,
boolean caseSensitive,
Pattern replacePattern)
Create a new instance.
|
| Modifier and Type | Method and Description |
|---|---|
Integer |
apply(String input) |
static int |
distance(String s,
String t)
Find the Levenshtein distance between two Strings.
|
public static final Pattern STANDARD_CHARS
public LevenshteinDistance(String baseString, boolean caseSensitive)
baseString - the string to compare tocaseSensitive - true to make case sensitive comparisonspublic LevenshteinDistance(String baseString, boolean caseSensitive, @Nullable Pattern replacePattern)
baseString - the string to compare tocaseSensitive - true to make case sensitive comparisonsreplacePattern - pattern to match characters to be removed in both the input and test strings (may be null)public static int distance(String s, String t)
Find the Levenshtein distance between two Strings.
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).
The previous implementation of the Levenshtein distance algorithm was from http://www.merriampark.com/ld.htm
Chas Emerick has written an implementation in Java, which avoids an OutOfMemoryError
which can occur when my Java implementation is used with very large strings.
This implementation of the Levenshtein distance algorithm
is from http://www.merriampark.com/ldjava.htm
distance(null, *) = IllegalArgumentException
distance(*, null) = IllegalArgumentException
distance("","") = 0
distance("","a") = 1
distance("aaapppp", "") = 7
distance("frog", "fog") = 1
distance("fly", "ant") = 3
distance("elephant", "hippo") = 7
distance("hippo", "elephant") = 7
distance("hippo", "zzzzzzzz") = 8
distance("hello", "hallo") = 1
s - the first String, must not be nullt - the second String, must not be nullIllegalArgumentException - if either String input nullCopyright © 2010-2014. All Rights Reserved.