Top Description Constructors Methods
org.apache.commons.text.similarity

public Class LongestCommonSubsequenceDistance

extends Object
implements EditDistance<Integer>
Class Inheritance
All Implemented Interfaces
org.apache.commons.text.similarity.EditDistance, org.apache.commons.text.similarity.SimilarityScore, org.apache.commons.text.similarity.ObjectSimilarityScore, java.util.function.BiFunction

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

AccessConstructor and Description
public
LongestCommonSubsequenceDistance()

Creates a new instance.

Method Summary

Modifier and TypeMethod and Description
public Integer

Returns:

distance.
apply
(final CharSequence
first character sequence.
left
,
final CharSequence
second character sequence.
right
)

Implements org.apache.commons.text.similarity.SimilarityScore.apply.

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).

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Constructor Detail

LongestCommonSubsequenceDistanceback to summary
public LongestCommonSubsequenceDistance()

Creates a new instance.

Method Detail

applyback to summary
public Integer apply(final CharSequence left, final CharSequence right)

Implements org.apache.commons.text.similarity.SimilarityScore.apply.

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).

Parameters
left:CharSequence

first character sequence.

right:CharSequence

second character sequence.

Returns:Integer

distance.

Annotations
@Override
Exceptions
IllegalArgumentException:
if either String input null.