Exemple #1
0
  /** gets map for all languages */
  public Map<String, String> getCaptionToQueryMap(Collection<Document> docs) {
    // identify all the langs in the docs, and the corresponding lexicons
    Set<String> languages = IndexUtils.allLanguagesInDocs(docs);
    Set<Lexicon1Lang> lexicons = new LinkedHashSet<Lexicon1Lang>();
    for (String lang : languages) {
      Lexicon1Lang lex = languageToLexicon.get(lang);
      if (lex != null) lexicons.add(lex);
      // this lexicon doesn't know about this language
      else log.warn("Warning: no support for " + lang + " in lexicon " + name);
    }

    Map<String, String> result = new LinkedHashMap<String, String>();
    // aggregate results for each lang into result
    for (Lexicon1Lang lex : lexicons) {
      Map<String, String> resultsForThisLang = lex.captionToExpandedQuery;

      for (String caption : resultsForThisLang.keySet()) {
        String queryThisLang = resultsForThisLang.get(caption);
        String query = 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 (query == null) result.put(caption, queryThisLang);
        else result.put(caption, query + "|" + queryThisLang);
      }
    }
    return result;
  }
Exemple #2
0
  // identify all the langs in the docs, and the corresponding lexicons
  private Collection<Lexicon1Lang> getRelevantLexicon1Langs(Collection<Document> docs) {
    if (docs == null) return languageToLexicon.values(); // just return all lexicons

    Set<String> languages = IndexUtils.allLanguagesInDocs(docs);
    Set<Lexicon1Lang> lexicons = new LinkedHashSet<Lexicon1Lang>();
    for (String lang : languages) {
      Lexicon1Lang lex = languageToLexicon.get(lang);
      if (lex != null) lexicons.add(lex); // this lexicon doesn't know about this language
      else log.warn("Warning: no support for " + lang + " in lexicon " + name);
    }
    return lexicons;
  }