Class LongestCommonSubsequenceDistance
java.lang.Object
org.apache.commons.text.similarity.LongestCommonSubsequenceDistance
- All Implemented Interfaces:
BiFunction<CharSequence,,CharSequence, Integer> EditDistance<Integer>,ObjectSimilarityScore<CharSequence,,Integer> SimilarityScore<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 -
Method Summary
Modifier and TypeMethodDescriptionapply(CharSequence left, CharSequence right) Calculates an edit distance between twoCharSequence'sleftandrightas:left.length() + right.length() - 2 * LCS(left, right), whereLCSis given inLongestCommonSubsequence.apply(CharSequence, CharSequence).Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface java.util.function.BiFunction
andThen
-
Constructor Details
-
LongestCommonSubsequenceDistance
public LongestCommonSubsequenceDistance()Creates a new instance.
-
-
Method Details
-
apply
Calculates an edit distance between twoCharSequence'sleftandrightas:left.length() + right.length() - 2 * LCS(left, right), whereLCSis given inLongestCommonSubsequence.apply(CharSequence, CharSequence).- Specified by:
applyin interfaceBiFunction<CharSequence,CharSequence, Integer> - Specified by:
applyin interfaceObjectSimilarityScore<CharSequence,Integer> - Specified by:
applyin interfaceSimilarityScore<Integer>- Parameters:
left- first character sequenceright- second character sequence- Returns:
- distance
- Throws:
IllegalArgumentException- if either String inputnull
-