Class JaccardSimilarity

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

    public class JaccardSimilarity
    extends java.lang.Object
    implements SimilarityScore<java.lang.Double>
    Measures the Jaccard similarity (aka Jaccard index) of two sets of character sequence. Jaccard similarity is the size of the intersection divided by the size of the union of the two sets.

    For further explanation about Jaccard Similarity, refer https://en.wikipedia.org/wiki/Jaccard_index

    Since:
    1.0
    • Constructor Summary

      Constructors 
      Constructor Description
      JaccardSimilarity()
      Creates 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)
      Computes the Jaccard Similarity of two set character sequence passed as input.
      <E> java.lang.Double apply​(SimilarityInput<E> left, SimilarityInput<E> right)
      Computes the Jaccard Similarity of two character sequences passed as input.
      • 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
    • Method Detail

      • apply

        public java.lang.Double apply​(java.lang.CharSequence left,
                                      java.lang.CharSequence right)
        Computes the Jaccard Similarity of two set character sequence passed as input.
        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 - first input sequence.
        right - second input sequence.
        Returns:
        The Jaccard Similarity of two set character sequence passed as input.
        Throws:
        java.lang.IllegalArgumentException - if either String input null.
      • apply

        public <E> java.lang.Double apply​(SimilarityInput<E> left,
                                          SimilarityInput<E> right)
        Computes the Jaccard Similarity of two character sequences passed as input. Does the calculation by identifying the union (characters in at least one of the two sets) of the two sets and intersection (characters which are present in set one which are present in set two)
        Type Parameters:
        E - The type of similarity score unit.
        Parameters:
        left - first input sequence.
        right - second input sequence.
        Returns:
        The Jaccard Similarity of two set character sequence passed as input.
        Since:
        1.13.0