Class OptimalStringAlignment

java.lang.Object
info.debatty.java.stringsimilarity.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.
See Also:
  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

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

    • OptimalStringAlignment

      public OptimalStringAlignment()
  • Method Details

    • 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.
    • min

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