Class Damerau

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

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

      Constructors 
      Constructor Description
      Damerau()  
    • 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).
      private static int min​(int a, int b, int c, int d)  
      • Methods inherited from class java.lang.Object

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

      • Damerau

        public Damerau()
    • Method Detail

      • distance

        public final 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).
        Specified by:
        distance in interface MetricStringDistance
        Specified by:
        distance in interface StringDistance
        Parameters:
        s1 - The first string to compare.
        s2 - The second string to compare.
        Returns:
        The computed distance.
        Throws:
        java.lang.NullPointerException - if s1 or s2 is null.
      • min

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