Java 类org.apache.lucene.analysis.hunspell.HunspellDictionary 实例源码

项目:NYBC    文件:TestRandomChains.java   
@Override public Object create(Random random) {
  // TODO: make nastier
  InputStream affixStream = HunspellDictionaryTest.class.getResourceAsStream("test.aff");
  InputStream dictStream = HunspellDictionaryTest.class.getResourceAsStream("test.dic");
  try {
   return new HunspellDictionary(affixStream, dictStream, TEST_VERSION_CURRENT);
  } catch (Exception ex) {
    Rethrow.rethrow(ex);
    return null; // unreachable code
  }
}
项目:Maskana-Gestor-de-Conocimiento    文件:TestRandomChains.java   
@Override public Object create(Random random) {
  // TODO: make nastier
  InputStream affixStream = HunspellDictionaryTest.class.getResourceAsStream("test.aff");
  InputStream dictStream = HunspellDictionaryTest.class.getResourceAsStream("test.dic");
  try {
   return new HunspellDictionary(affixStream, dictStream, TEST_VERSION_CURRENT);
  } catch (Exception ex) {
    Rethrow.rethrow(ex);
    return null; // unreachable code
  }
}
项目:NYBC    文件:HunspellStemFilterFactory.java   
/**
 * Loads the hunspell dictionary and affix files defined in the configuration
 *  
 * @param loader ResourceLoader used to load the files
 */
@Override
public void inform(ResourceLoader loader) throws IOException {
  assureMatchVersion();
  String dictionaryArg = args.get(PARAM_DICTIONARY);
  if (dictionaryArg == null) {
    throw new IllegalArgumentException("Parameter " + PARAM_DICTIONARY + " is mandatory.");
  }
  String dictionaryFiles[] = args.get(PARAM_DICTIONARY).split(",");
  String affixFile = args.get(PARAM_AFFIX);
  String pic = args.get(PARAM_IGNORE_CASE);
  if(pic != null) {
    if(pic.equalsIgnoreCase(TRUE)) ignoreCase = true;
    else if(pic.equalsIgnoreCase(FALSE)) ignoreCase = false;
    else throw new IllegalArgumentException("Unknown value for " + PARAM_IGNORE_CASE + ": " + pic + ". Must be true or false");
  }

  String strictAffixParsingParam = args.get(PARAM_STRICT_AFFIX_PARSING);
  boolean strictAffixParsing = true;
  if(strictAffixParsingParam != null) {
    if(strictAffixParsingParam.equalsIgnoreCase(FALSE)) strictAffixParsing = false;
    else if(strictAffixParsingParam.equalsIgnoreCase(TRUE)) strictAffixParsing = true;
    else throw new IllegalArgumentException("Unknown value for " + PARAM_STRICT_AFFIX_PARSING + ": " + strictAffixParsingParam + ". Must be true or false");
  }

  InputStream affix = null;
  List<InputStream> dictionaries = new ArrayList<InputStream>();

  try {
    dictionaries = new ArrayList<InputStream>();
    for (String file : dictionaryFiles) {
      dictionaries.add(loader.openResource(file));
    }
    affix = loader.openResource(affixFile);

    this.dictionary = new HunspellDictionary(affix, dictionaries, luceneMatchVersion, ignoreCase, strictAffixParsing);
  } catch (ParseException e) {
    throw new IOException("Unable to load hunspell data! [dictionary=" + args.get("dictionary") + ",affix=" + affixFile + "]", e);
  } finally {
    IOUtils.closeWhileHandlingException(affix);
    IOUtils.closeWhileHandlingException(dictionaries);
  }
}