Class CosineDistance
java.lang.Object
org.apache.commons.text.similarity.CosineDistance
- All Implemented Interfaces:
BiFunction<CharSequence,,CharSequence, Double> EditDistance<Double>,ObjectSimilarityScore<CharSequence,,Double> SimilarityScore<Double>
Measures the cosine distance between two character sequences.
It utilizes the CosineSimilarity to compute the distance. Character sequences
are converted into vectors through a simple tokenizer that works with a regular expression
to split words in a sentence.
For further explanation about Cosine Similarity and Cosine Distance, refer to https://en.wikipedia.org/wiki/Cosine_similarity.
- Since:
- 1.0
- See Also:
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionapply(CharSequence left, CharSequence right) Compares two CharSequences.Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface java.util.function.BiFunction
andThen
-
Constructor Details
-
CosineDistance
public CosineDistance()Construct a new instance.
-
-
Method Details
-
apply
Description copied from interface:SimilarityScoreCompares two CharSequences.- Specified by:
applyin interfaceBiFunction<CharSequence,CharSequence, Double> - Specified by:
applyin interfaceObjectSimilarityScore<CharSequence,Double> - Specified by:
applyin interfaceSimilarityScore<Double>- Parameters:
left- the "left" or "first" input.right- the "right" or "second" input.- Returns:
- The similarity score between two CharSequences.
-