tfIdfMatrix function
Create word-vector matrix using TF-IDF metric
Implementation
List<List<double?>> tfIdfMatrix(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, (_) => []);
List<Map<String, double>> wpList = tfIdfProbability(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(wpList[i][key]);
} else {
matrix2d[i].add(0);
}
}
});
return matrix2d;
}