Class Levenshtein


  • public class Levenshtein
    extends java.lang.Object
    The Damerau-Levenshtein Algorithm is an extension to the Levenshtein Algorithm which solves the edit distance problem between a source string and a target string with the following operations:
    • Character Insertion
    • Character Deletion
    • Character Replacement
    • Adjacent Character Swap
    Note that the adjacent character swap operation is an edit that may be applied when two adjacent characters in the source string match two adjacent characters in the target string, but in reverse order, rather than a general allowance for adjacent character swaps.

    This implementation allows the client to specify the costs of the various edit operations with the restriction that the cost of two swap operations must not be less than the cost of a delete operation followed by an insert operation. This restriction is required to preclude two swaps involving the same character being required for optimality which, in turn, enables a fast dynamic programming solution.

    The running time of the Damerau-Levenshtein algorithm is O(n*m) where n is the length of the source string and m is the length of the target string. This implementation consumes O(n*m) space.

    • Constructor Summary

      Constructors 
      Constructor Description
      Levenshtein()  
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static int distance​(java.lang.CharSequence lhs, java.lang.CharSequence rhs)  
      static int distance​(java.lang.CharSequence source, java.lang.CharSequence target, int deleteCost, int insertCost, int replaceCost, int swapCost)  
      • Methods inherited from class java.lang.Object

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

      • Levenshtein

        public Levenshtein()
    • Method Detail

      • distance

        public static int distance​(java.lang.CharSequence lhs,
                                   java.lang.CharSequence rhs)
      • distance

        public static int distance​(java.lang.CharSequence source,
                                   java.lang.CharSequence target,
                                   int deleteCost,
                                   int insertCost,
                                   int replaceCost,
                                   int swapCost)