hybridTfIdfMatrix function

List<List<double?>> hybridTfIdfMatrix(
  1. List<String> documentList, {
  2. dynamic measureFunction = cosineDistance,
  3. String stemmer(
    1. String
    )?,
  4. List<String>? stopwords,
})

Create word-vector matrix using Hybrid TF-IDF metric

Implementation

List<List<double?>> hybridTfIdfMatrix(List<String> documentList,
    {measureFunction = cosineDistance,
    String Function(String)? stemmer,
    List<String>? stopwords}) {
  TokenizationOutput tokenOut =
      documentTokenizer(documentList, stemmer: stemmer, stopwords: stopwords);

  List<List<double?>> matrix2d = List.generate(documentList.length, (_) => []);
  Map<String, double> wordProbability = hybridTfIdfProbability(tokenOut);

  //for all distinct words
  tokenOut.bagOfWords.forEach((key, val) {
    for (int i = 0; i < documentList.length; i++) {
      if (tokenOut.documentBOW[i].containsKey(key)) {
        matrix2d[i].add(wordProbability[key]);
      } else {
        matrix2d[i].add(0);
      }
    }
  });

  return matrix2d;
}