Example #1
0
  private Map<String, Integer> buildWordFrequencies(
      final List<String> texts, final WordTokenizer tokenizer) {
    final Map<String, Integer> wordFrequencies = new HashMap<>();
    for (final String text : texts) {
      final List<String> words = filter(tokenizer.tokenize(text));

      for (final String word : words) {
        final String normalized = normalize(word);
        if (!wordFrequencies.containsKey(normalized)) {
          wordFrequencies.put(normalized, 1);
        }
        wordFrequencies.put(normalized, wordFrequencies.get(normalized) + 1);
      }
    }
    return wordFrequencies;
  }