Class Damerau
java.lang.Object
info.debatty.java.stringsimilarity.Damerau
- All Implemented Interfaces:
MetricStringDistance
,StringDistance
,Serializable
Implementation of Damerau-Levenshtein distance with transposition (also
sometimes calls unrestricted Damerau-Levenshtein distance).
It is the minimum number of operations needed to transform one string into
the other, where an operation is defined as an insertion, deletion, or
substitution of a single character, or a transposition of two adjacent
characters.
It does respect triangle inequality, and is thus a metric distance.
This is not to be confused with the optimal string alignment distance, which
is an extension where no substring can be edited more than once.
- See Also:
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionfinal double
Compute the distance between strings: the minimum number of operations needed to transform one string into the other (insertion, deletion, substitution of a single character, or a transposition of two adjacent characters).private static int
min
(int a, int b, int c, int d)
-
Constructor Details
-
Damerau
public Damerau()
-
-
Method Details
-
distance
Compute the distance between strings: the minimum number of operations needed to transform one string into the other (insertion, deletion, substitution of a single character, or a transposition of two adjacent characters).- Specified by:
distance
in interfaceMetricStringDistance
- Specified by:
distance
in interfaceStringDistance
- Parameters:
s1
- The first string to compare.s2
- The second string to compare.- Returns:
- The computed distance.
- Throws:
NullPointerException
- if s1 or s2 is null.
-
min
private static int min(int a, int b, int c, int d)
-