org.apache.commons.text.similarity

## Class LongestCommonSubsequenceDistance

- java.lang.Object
- - org.apache.commons.text.similarity.LongestCommonSubsequenceDistance

- All Implemented Interfaces:
    EditDistance<Integer>, SimilarityScore<Integer>

      public class LongestCommonSubsequenceDistance
      extends Object
      implements EditDistance<Integer>

  An edit distance algorithm based on the length of the longest common subsequence between two strings.

  This code is directly based upon the implementation in `LongestCommonSubsequence`.

  For reference see: https://en.wikipedia.org/wiki/Longest_common_subsequence_problem.

  For further reading see:

  Lothaire, M. Applied combinatorics on words. New York: Cambridge U Press, 2005. 12-13

  Since:
    1.0

- - ### Constructor Summary

    Constructors
    Constructor and Description
    `LongestCommonSubsequenceDistance()`

  - ### Method Summary

    All Methods Instance Methods Concrete Methods
    Modifier and Type | Method and Description
    --- | ---
    `Integer` | `apply(CharSequence left, CharSequence right)` Calculates an edit distance between two `CharSequence`'s `left` and `right` as: `left.length() + right.length() - 2 * LCS(left, right)`, where `LCS` is given in `LongestCommonSubsequence.apply(CharSequence, CharSequence)`.

    - ### Methods inherited from class java.lang.Object

      `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- - ### Constructor Detail

    - #### LongestCommonSubsequenceDistance

          public LongestCommonSubsequenceDistance()

  - ### Method Detail

    - #### apply

          public Integer apply(CharSequence left,
                               CharSequence right)

      Calculates an edit distance between two `CharSequence`'s `left` and `right` as: `left.length() + right.length() - 2 * LCS(left, right)`, where `LCS` is given in `LongestCommonSubsequence.apply(CharSequence, CharSequence)`.
      Specified by:
        `apply` in interface `EditDistance<Integer>`
      Specified by:
        `apply` in interface `SimilarityScore<Integer>`
      Parameters:
        `left` - first character sequence
        `right` - second character sequence
      Returns:
        distance
      Throws:
        `IllegalArgumentException` - if either String input `null`

Copyright © 2014–2018 The Apache Software Foundation. All rights reserved.