|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectnet.sourceforge.wurfl.core.handlers.matchers.strategy.LDMatcher
public final class LDMatcher
Singleton class responsible applying the Levenshtein Distance Algorithm to matching strings. This class use a custom implementation.
| Field Summary | |
|---|---|
static LDMatcher |
INSTANCE
Singleton instance |
| Method Summary | |
|---|---|
static int |
getLevenshteinDistance(String s,
String t,
int tolerance)
Find the Levenshtein distance between two Strings. |
String |
getName()
|
String |
match(SortedSet candidates,
String needle,
int tolerance)
Searches for the string which has the minor Levenshtein distance from given needle. |
String |
toString()
|
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
| Field Detail |
|---|
public static final LDMatcher INSTANCE
| Method Detail |
|---|
public String getName()
public String match(SortedSet candidates,
String needle,
int tolerance)
match in interface StringMatchercandidates - The SortedSet of possible candidates.needle - The String to match.tolerance - the tolerance between needle and candidates.
public static int getLevenshteinDistance(String s,
String t,
int tolerance)
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
StringUtils.getLevenshteinDistance(null, *) = IllegalArgumentException
StringUtils.getLevenshteinDistance(*, null) = IllegalArgumentException
StringUtils.getLevenshteinDistance("","") = 0
StringUtils.getLevenshteinDistance("","a") = 1
StringUtils.getLevenshteinDistance("aaapppp", "") = 7
StringUtils.getLevenshteinDistance("frog", "fog") = 1
StringUtils.getLevenshteinDistance("fly", "ant") = 3
StringUtils.getLevenshteinDistance("elephant", "hippo") = 7
StringUtils.getLevenshteinDistance("hippo", "elephant") = 7
StringUtils.getLevenshteinDistance("hippo", "zzzzzzzz") = 8
StringUtils.getLevenshteinDistance("hello", "hallo") = 1
s - the first String, must not be nullt - the second String, must not be nulltolerance - the minimum distance
IllegalArgumentException - if either String input nullpublic String toString()
toString in class Object
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||