Class JaccardSimilarity

java.lang.Object
org.apache.commons.text.similarity.JaccardSimilarity
All Implemented Interfaces:
BiFunction<CharSequence,CharSequence,Double>, ObjectSimilarityScore<CharSequence,Double>, SimilarityScore<Double>

public class JaccardSimilarity extends Object implements SimilarityScore<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 Details

  • Method Details

    • apply

      public Double apply(CharSequence left, CharSequence right)
      Computes the Jaccard Similarity of two set character sequence passed as input.
      Specified by:
      apply in interface BiFunction<CharSequence,CharSequence,Double>
      Specified by:
      apply in interface ObjectSimilarityScore<CharSequence,Double>
      Specified by:
      apply in interface SimilarityScore<Double>
      Parameters:
      left - first input sequence.
      right - second input sequence.
      Returns:
      The Jaccard Similarity of two set character sequence passed as input.
      Throws:
      IllegalArgumentException - if either String input null.
    • apply

      public <E> 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