tfIdfSimilarity function

double tfIdfSimilarity (
  1. String document1,
  2. String document2,
  3. List<String> background,
  4. {dynamic distanceFunction: cosineDistance,
  5. String stemmer(
    1. String
    ),
  6. List<String> stopwords}
)

Check similarity between 2 documents using TF-IDF metric.

Default distanceFunction is cosineDistance

Implementation

double tfIdfSimilarity(
    String document1, String document2, List<String> background,
    {distanceFunction = cosineDistance,
    String Function(String) stemmer,
    List<String> stopwords}) {
  List<List<double>> vectorList = tfIdfMatrix(
      [document1, document2, ...background],
      stemmer: stemmer, stopwords: stopwords);

  return 1.0 - distanceFunction(vectorList[0], vectorList[1]);
}