Class Damerau
- java.lang.Object
-
- info.debatty.java.stringsimilarity.Damerau
-
- All Implemented Interfaces:
MetricStringDistance
,StringDistance
,Serializable
@Immutable public class Damerau extends Object implements MetricStringDistance
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.- Author:
- Thibault Debatty
- See Also:
- Serialized Form
-
-
Constructor Summary
Constructors Constructor Description Damerau()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description double
distance(String s1, String s2)
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).
-
-
-
Method Detail
-
distance
public final double distance(String s1, String s2)
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.
-
-