@Description(value="Levenshtein distance.") @Reference(authors="V. I. Levenshtein", title="Binary codes capable of correcting deletions, insertions and reversals", booktitle="Soviet physics doklady 10", bibkey="journals/misc/Levenshtein66") public class LevenshteinDistanceFunction extends java.lang.Object implements PrimitiveDistanceFunction<java.lang.String>
Reference:
V. I. Levenshtein
Binary codes capable of correcting deletions, insertions and reversals
Soviet physics doklady 10
TODO: add case insensitive flag.
TODO: add an API that can stop early at a maximum distance
Modifier and Type | Class and Description |
---|---|
static class |
LevenshteinDistanceFunction.Parameterizer
Parameterization class.
|
Modifier and Type | Field and Description |
---|---|
static LevenshteinDistanceFunction |
STATIC_SENSITIVE
Static instance, case sensitive.
|
protected static SimpleTypeInformation<? super java.lang.String> |
TYPE
Input data type.
|
Constructor and Description |
---|
LevenshteinDistanceFunction()
Deprecated.
|
Modifier and Type | Method and Description |
---|---|
double |
distance(java.lang.String o1,
java.lang.String o2)
Computes the distance between two given DatabaseObjects according to this
distance function.
|
boolean |
equals(java.lang.Object obj) |
SimpleTypeInformation<? super java.lang.String> |
getInputTypeRestriction()
Get the input data type of the function.
|
int |
hashCode() |
boolean |
isMetric()
Is this distance function metric (satisfy the triangle inequality)
|
static int |
levenshteinDistance(java.lang.String o1,
java.lang.String o2)
Levenshtein distance for two strings.
|
static int |
levenshteinDistance(java.lang.String o1,
java.lang.String o2,
int prefix,
int postfix)
Compute the Levenshtein distance, except for prefix and postfix.
|
private static int |
min(int a,
int b,
int c)
Three-way integer minimum.
|
private static int |
postfixLen(java.lang.String o1,
java.lang.String o2,
int prefix)
Compute the postfix length.
|
private static int |
prefixLen(java.lang.String o1,
java.lang.String o2)
Compute the length of the prefix.
|
clone, finalize, getClass, notify, notifyAll, toString, wait, wait, wait
instantiate
isSquared, isSymmetric
public static final LevenshteinDistanceFunction STATIC_SENSITIVE
protected static final SimpleTypeInformation<? super java.lang.String> TYPE
@Deprecated public LevenshteinDistanceFunction()
public double distance(java.lang.String o1, java.lang.String o2)
PrimitiveDistanceFunction
distance
in interface PrimitiveDistanceFunction<java.lang.String>
o1
- first DatabaseObjecto2
- second DatabaseObjectpublic static int levenshteinDistance(java.lang.String o1, java.lang.String o2)
o1
- First stringo2
- Second stringprivate static int prefixLen(java.lang.String o1, java.lang.String o2)
o1
- First stringo2
- Second stringprivate static int postfixLen(java.lang.String o1, java.lang.String o2, int prefix)
o1
- First objecto2
- Second objectprefix
- Known prefix lengthpublic static int levenshteinDistance(java.lang.String o1, java.lang.String o2, int prefix, int postfix)
o1
- First objecto2
- Second objectprefix
- Prefix lengthpostfix
- Postfix lengthprivate static int min(int a, int b, int c)
a
- First valueb
- Second valuec
- Third value.public SimpleTypeInformation<? super java.lang.String> getInputTypeRestriction()
DistanceFunction
getInputTypeRestriction
in interface DistanceFunction<java.lang.String>
getInputTypeRestriction
in interface PrimitiveDistanceFunction<java.lang.String>
public boolean isMetric()
DistanceFunction
isMetric
in interface DistanceFunction<java.lang.String>
true
when metric.public boolean equals(java.lang.Object obj)
equals
in class java.lang.Object
public int hashCode()
hashCode
in class java.lang.Object
Copyright © 2019 ELKI Development Team. License information.