public class EditDistance extends java.lang.Object implements Metric<java.lang.String>, java.io.Serializable
Given two strings x and y of length m and n (suppose n ≥ m), this implementation takes O(ne) time and O(mn) space by an extended Ukkonen's algorithm in case of unit cost, where e is the edit distance between x and y. Thus this algorithm is output sensitive. The smaller the distance, the faster it runs.
For weighted cost, this implements the regular dynamic programming algorithm, which takes O(mn) time and O(m) space.
| Constructor and Description |
|---|
EditDistance(double[][] weight)
Constructor.
|
EditDistance(double[][] weight,
double radius)
Constructor.
|
EditDistance(int maxStringLength)
Constructor.
|
EditDistance(int maxStringLength,
boolean damerau)
Constructor.
|
| Modifier and Type | Method and Description |
|---|---|
double |
d(char[] x,
char[] y)
Edit distance between two strings.
|
double |
d(java.lang.String x,
java.lang.String y)
Edit distance between two strings.
|
static int |
damerau(char[] x,
char[] y)
Damerau-Levenshtein distance between two strings allows insertion,
deletion, substitution, or transposition of characters.
|
static int |
damerau(java.lang.String x,
java.lang.String y)
Damerau-Levenshtein distance between two strings allows insertion,
deletion, substitution, or transposition of characters.
|
static int |
levenshtein(char[] x,
char[] y)
Levenshtein distance between two strings allows insertion, deletion,
or substitution of characters.
|
static int |
levenshtein(java.lang.String x,
java.lang.String y)
Levenshtein distance between two strings allows insertion, deletion,
or substitution of characters.
|
java.lang.String |
toString() |
public EditDistance(double[][] weight)
public EditDistance(double[][] weight,
double radius)
radius - the window width of Sakoe-Chiba band in terms of percentage of sequence length.public EditDistance(int maxStringLength)
maxStringLength - the maximum length of strings that will be
feed to this algorithm.public EditDistance(int maxStringLength,
boolean damerau)
maxStringLength - the maximum length of strings that will be
feed to this algorithm.damerau - if true, calculate Damerau-Levenshtein distance instead
of plain Levenshtein distance.public java.lang.String toString()
toString in class java.lang.Objectpublic double d(java.lang.String x,
java.lang.String y)
public double d(char[] x,
char[] y)
public static int levenshtein(java.lang.String x,
java.lang.String y)
public static int levenshtein(char[] x,
char[] y)
public static int damerau(java.lang.String x,
java.lang.String y)
public static int damerau(char[] x,
char[] y)