Exemple #1
0
  /**
   * Core sentiment detection method. doNota = none of the above
   *
   * @param captions (null/none = all)
   */
  public Map<String, Collection<Document>> getEmotions(
      Indexer indexer,
      Collection<Document> docs,
      boolean doNota,
      boolean originalContentOnly,
      String... captions) {
    Collection<Lexicon1Lang> lexicons = getRelevantLexicon1Langs(docs);
    Map<String, Collection<Document>> result = new LinkedHashMap<>();
    Set<Document> docs_set = Util.castOrCloneAsSet(docs);
    // aggregate results for each lang into result
    for (Lexicon1Lang lex : lexicons) {
      Map<String, Collection<Document>> resultsForThisLang =
          (doNota
              ? lex.getEmotionsWithNOTA(indexer, docs_set, originalContentOnly)
              : lex.getEmotions(indexer, docs_set, originalContentOnly, captions));
      if (resultsForThisLang == null) continue;

      for (String caption : resultsForThisLang.keySet()) {
        Collection<Document> resultDocsThisLang = resultsForThisLang.get(caption);
        Collection<Document> resultDocs = 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 (resultDocs == null) result.put(caption, resultDocsThisLang);
        else resultDocs.addAll(resultDocsThisLang);
      }
    }
    // TODO: the result can be cached at server to avoid redundant computation (by concurrent users,
    // which are few for now)
    return result;
  }