toKGramsMap method
Returns a hashmap of k-grams to terms from the collection of tokens.
Implementation
Map<String, Set<String>> toKGramsMap([int k = 2]) {
final terms = this;
// print the terms
final Map<String, Set<String>> kGramIndex = {};
for (final term in terms) {
final kGrams = term.kGrams(k);
for (final kGram in kGrams) {
final set = kGramIndex[kGram] ?? {};
set.add(term);
kGramIndex[kGram] = set;
}
}
return kGramIndex;
}