wordFrequencyMatrix function

List<List<double>> wordFrequencyMatrix (
  1. List<String> documentList,
  2. {String stemmer(
    1. String
    ),
  3. List<String> stopwords}
)

Create word-vector matrix using word-frequency metric

Implementation

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

  List<List<double>> matrix2d = List.generate(documentList.length, (_) => []);

  //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(tokenOut.documentBOW[i][key].toDouble());
      } else {
        matrix2d[i].add(0);
      }
    }
  });

  return matrix2d;
}