Class OptimalStringAlignment

  • All Implemented Interfaces:
    StringDistance, java.io.Serializable

    @Immutable
    public final class OptimalStringAlignment
    extends java.lang.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.
    See Also:
    Serialized Form
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      double distance​(java.lang.String s1, java.lang.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.
      private static int min​(int a, int b, int c)  
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • OptimalStringAlignment

        public OptimalStringAlignment()
    • Method Detail

      • distance

        public double distance​(java.lang.String s1,
                               java.lang.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:
        java.lang.NullPointerException - if s1 or s2 is null.
      • min

        private static int min​(int a,
                               int b,
                               int c)