Class CosineDistance

  • All Implemented Interfaces:
    java.util.function.BiFunction<java.lang.CharSequence,​java.lang.CharSequence,​java.lang.Double>, EditDistance<java.lang.Double>, ObjectSimilarityScore<java.lang.CharSequence,​java.lang.Double>, SimilarityScore<java.lang.Double>

    public class CosineDistance
    extends java.lang.Object
    implements EditDistance<java.lang.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:
    CosineSimilarity
    • Constructor Summary

      Constructors 
      Constructor Description
      CosineDistance()
      Construct a new instance.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      java.lang.Double apply​(java.lang.CharSequence left, java.lang.CharSequence right)
      Compares two CharSequences.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
      • Methods inherited from interface java.util.function.BiFunction

        andThen
    • Constructor Detail

    • Method Detail

      • apply

        public java.lang.Double apply​(java.lang.CharSequence left,
                                      java.lang.CharSequence right)
        Description copied from interface: SimilarityScore
        Compares two CharSequences.
        Specified by:
        apply in interface java.util.function.BiFunction<java.lang.CharSequence,​java.lang.CharSequence,​java.lang.Double>
        Specified by:
        apply in interface ObjectSimilarityScore<java.lang.CharSequence,​java.lang.Double>
        Specified by:
        apply in interface SimilarityScore<java.lang.Double>
        Parameters:
        left - the "left" or "first" input.
        right - the "right" or "second" input.
        Returns:
        The similarity score between two CharSequences.