org.apache.lucene.spelt
Class TRStringDistance2
Object
TRStringDistance2
final class TRStringDistance2
- extends Object
Calculates the edit distance between two strings, with special modifications to
score transpositions and double-letter changes as lower cost than
insertion/deletion/replacement.
- Author:
- Martin Haye
Field Summary |
(package private) int[][][] |
cache
|
(package private) int |
n
|
(package private) char[] |
sa
|
Constructor Summary |
TRStringDistance2(String target)
Optimized to run a bit faster than the static getDistance(). |
Method Summary |
private static int[][] |
form(int n,
int m)
|
int |
getDistance(String other)
Compute Damerau-Levenstein distance between the target string and
another string. |
private static int |
min3(int a,
int b,
int c)
|
Methods inherited from class Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
sa
final char[] sa
n
final int n
cache
final int[][][] cache
TRStringDistance2
public TRStringDistance2(String target)
- Optimized to run a bit faster than the static getDistance().
In one benchmark times were 5.3sec using ctr vs 8.5sec w/ static method, thus 37% faster.
getDistance
public final int getDistance(String other)
- Compute Damerau-Levenstein distance between the target string and
another string. Damerau-Levenstein is similar to Levenstein except
that it also accounts for transposition in the set of edit operations.
This more fully reflects a common source of misspellings.
form
private static int[][] form(int n,
int m)
min3
private static int min3(int a,
int b,
int c)