Class OptimalStringAlignment

  • All Implemented Interfaces:
    StringDistance, Serializable

    @Immutable
    public final class OptimalStringAlignment
    extends Object
    implements StringDistance
    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.
    Author:
    Michail Bogdanos
    See Also:
    Serialized Form
    • Constructor Detail

      • OptimalStringAlignment

        public OptimalStringAlignment()
    • Method Detail

      • distance

        public 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) while no substring is edited more than once.
        Specified by:
        distance in interface StringDistance
        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.