|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectcom.limegroup.gnutella.util.ApproximateMatcher
An approximate string matcher. Two strings are considered "approximately equal" if one can be transformed into the other through some series of inserts, deletes, and substitutions.
The approximate matcher has options to ignore case and whitespace. It also has switches to make it perform better by comparing strings backwards and reusing a buffer. However, these do not affect the match methods directly; they only affect the results of the process(String) method. This method is used to preprocess strings before passing to match(..). Typical use:
String s1, s2; ApproximateMatcher matcher=new ApproximateMatcher(); matcher.setIgnoreCase(true); matcher.setCompareBackwards(true); String s1p=matcher.process(s1); //pre-process s1 String s2p=matcher.process(s2); //pre-process s2 int matches=matcher.match(s1p, s2p); //compare processed strings ...The reason for this design is to reduce the pre-processing overhead when a string is matched against many other strings. Preprocessing really is required to support the ignoreWhitespace option; it is simply not possible to do the k-difference dynamic programming algorithm effienctly in one pass. Note that this class is not thread-safe if the buffering constructor is used.
Constructor Summary | |
ApproximateMatcher()
|
|
ApproximateMatcher(int size)
Like ApproximateMatcher() except that the new matcher can compare strings of the given size without any significant allocations. |
Method Summary | |
int |
match(java.lang.String s1,
java.lang.String s2)
|
boolean |
matches(java.lang.String s1,
java.lang.String s2,
float precision)
Returns true if s1 can be transformed into s2 without changing more than the given fraction of s1's letters. |
boolean |
matches(java.lang.String s1,
java.lang.String s2,
int maxOps)
Returns true if the edit distance between s1 and s2 is less than or equal to maxOps. |
java.lang.String |
process(java.lang.String s)
Returns a version of s suitable for passing to match(..). |
void |
setCompareBackwards(boolean compareBackwards)
|
void |
setIgnoreCase(boolean ignoreCase)
|
void |
setIgnoreWhitespace(boolean ignoreWhitespace)
|
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
public ApproximateMatcher()
public ApproximateMatcher(int size)
Method Detail |
public void setIgnoreCase(boolean ignoreCase)
public void setIgnoreWhitespace(boolean ignoreWhitespace)
public void setCompareBackwards(boolean compareBackwards)
public java.lang.String process(java.lang.String s)
public final int match(java.lang.String s1, java.lang.String s2)
public final boolean matches(java.lang.String s1, java.lang.String s2, int maxOps)
If you want to ignore case or whitespace, or compare backwards, s1 and s2 should be the return values of a call to process(..).
public final boolean matches(java.lang.String s1, java.lang.String s2, float precision)
If you want to ignore case or whitespace, or compare backwards, s1 and s2 should be the return values of a call to process(..).
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |