jaccardSimilarity method Null safety

double jaccardSimilarity(
  1. Term other,
  2. [int k = 3]
)

Returns the Jaccard Similarity Index between this term and other using a k-gram length of k.

Implementation

double jaccardSimilarity(Term other, [int k = 3]) {
  final termGrams = kGrams(k);
  final otherGrams = other.kGrams(k);
  final intersection = termGrams.intersection(otherGrams);
  final union = termGrams.union(otherGrams);
  return intersection.length / union.length;
}