コード例 #1
0
  /** Load synonyms with the given {@link SynonymMap.Parser} class. */
  private SynonymMap loadSynonyms(
      ResourceLoader loader, String cname, boolean dedup, Analyzer analyzer)
      throws IOException, ParseException {
    CharsetDecoder decoder =
        Charset.forName("UTF-8")
            .newDecoder()
            .onMalformedInput(CodingErrorAction.REPORT)
            .onUnmappableCharacter(CodingErrorAction.REPORT);

    SynonymMap.Parser parser;
    Class<? extends SynonymMap.Parser> clazz = loader.findClass(cname, SynonymMap.Parser.class);
    try {
      parser =
          clazz
              .getConstructor(boolean.class, boolean.class, Analyzer.class)
              .newInstance(dedup, expand, analyzer);
    } catch (Exception e) {
      throw new RuntimeException(e);
    }

    File synonymFile = new File(synonyms);
    if (synonymFile.exists()) {
      decoder.reset();
      parser.parse(new InputStreamReader(loader.openResource(synonyms), decoder));
    } else {
      List<String> files = splitFileNames(synonyms);
      for (String file : files) {
        decoder.reset();
        parser.parse(new InputStreamReader(loader.openResource(file), decoder));
      }
    }
    return parser.build();
  }
コード例 #2
0
 // (there are no tests for this functionality)
 private TokenizerFactory loadTokenizerFactory(ResourceLoader loader, String cname)
     throws IOException {
   Class<? extends TokenizerFactory> clazz = loader.findClass(cname, TokenizerFactory.class);
   try {
     TokenizerFactory tokFactory = clazz.getConstructor(Map.class).newInstance(tokArgs);
     if (tokFactory instanceof ResourceLoaderAware) {
       ((ResourceLoaderAware) tokFactory).inform(loader);
     }
     return tokFactory;
   } catch (Exception e) {
     throw new RuntimeException(e);
   }
 }