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.
See Also:
  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    final double
    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 Details

    • Damerau

      public Damerau()
  • Method Details

    • 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 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:
      NullPointerException - if s1 or s2 is null.
    • min

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