Exemple #1
0
  // accumulates counts returned by lexicons in each language
  // TODO: It is possible to write a generic accumulator that accumulates sum over all the languages
  public Map<String, Integer> getLexiconCounts(Indexer indexer, boolean originalContentOnly) {
    List<Document> docs = indexer.docs;
    Collection<Lexicon1Lang> lexicons = getRelevantLexicon1Langs(docs);
    Map<String, Integer> result = new LinkedHashMap<String, Integer>();
    Set<Document> docs_set = Util.castOrCloneAsSet(docs);
    // aggregate results for each lang into result
    for (Lexicon1Lang lex : lexicons) {
      Map<String, Integer> resultsForThisLang = lex.getLexiconCounts(indexer, originalContentOnly);
      if (resultsForThisLang == null) continue;

      for (String caption : resultsForThisLang.keySet()) {
        Integer resultCountsThisLang = resultsForThisLang.get(caption);
        Integer resultCounts = result.get(caption);
        // if caption doesn't exist already, create a new entry, or else add to the existing set of
        // docs that match this caption
        if (resultCounts == null) result.put(caption, resultCountsThisLang);
        else result.put(caption, resultCounts + resultCountsThisLang);
      }
    }
    return result;
  }