Class OptimalStringAlignment
java.lang.Object
info.debatty.java.stringsimilarity.OptimalStringAlignment
- All Implemented Interfaces:
StringDistance
,Serializable
Implementation of the the Optimal String Alignment (sometimes called the
restricted edit distance) variant of the Damerau-Levenshtein distance.
The difference between the two algorithms consists in that the Optimal String
Alignment algorithm computes the number of edit operations needed to make the
strings equal under the condition that no substring is edited more than once,
whereas Damerau-Levenshtein presents no such restriction.
- See Also:
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptiondouble
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) while no substring is edited more than once.private static int
min
(int a, int b, int c)
-
Constructor Details
-
OptimalStringAlignment
public OptimalStringAlignment()
-
-
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) while no substring is edited more than once.- Specified by:
distance
in interfaceStringDistance
- Parameters:
s1
- The first string to compare.s2
- The second string to compare.- Returns:
- the OSA distance
- Throws:
NullPointerException
- if s1 or s2 is null.
-
min
private static int min(int a, int b, int c)
-