Class LongestCommonSubsequenceDistance
- java.lang.Object
-
- org.apache.commons.text.similarity.LongestCommonSubsequenceDistance
-
- All Implemented Interfaces:
EditDistance<java.lang.Integer>
,SimilarityScore<java.lang.Integer>
public class LongestCommonSubsequenceDistance extends java.lang.Object implements EditDistance<java.lang.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 Description LongestCommonSubsequenceDistance()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description java.lang.Integer
apply(java.lang.CharSequence left, java.lang.CharSequence right)
Calculates an edit distance between twoCharSequence
'sleft
andright
as:left.length() + right.length() - 2 * LCS(left, right)
, whereLCS
is given inLongestCommonSubsequence.apply(CharSequence, CharSequence)
.
-
-
-
Method Detail
-
apply
public java.lang.Integer apply(java.lang.CharSequence left, java.lang.CharSequence right)
Calculates an edit distance between twoCharSequence
'sleft
andright
as:left.length() + right.length() - 2 * LCS(left, right)
, whereLCS
is given inLongestCommonSubsequence.apply(CharSequence, CharSequence)
.- Specified by:
apply
in interfaceEditDistance<java.lang.Integer>
- Specified by:
apply
in interfaceSimilarityScore<java.lang.Integer>
- Parameters:
left
- first character sequenceright
- second character sequence- Returns:
- distance
- Throws:
java.lang.IllegalArgumentException
- if either String inputnull
-
-