Java 类org.apache.lucene.search.spell.PlainTextDictionary 实例源码

项目:Camel    文件:LuceneSuggestionStrategy.java   
@Override
public String[] suggestEndpointOptions(Set<String> names, String unknownOption) {
    // each option must be on a separate line in a String
    StringBuilder sb = new StringBuilder();
    for (String name : names) {
        sb.append(name);
        sb.append("\n");
    }
    StringReader reader = new StringReader(sb.toString());

    try {
        PlainTextDictionary words = new PlainTextDictionary(reader);

        // use in-memory lucene spell checker to make the suggestions
        RAMDirectory dir = new RAMDirectory();
        SpellChecker checker = new SpellChecker(dir);
        checker.indexDictionary(words, new IndexWriterConfig(new KeywordAnalyzer()), false);

        return checker.suggestSimilar(unknownOption, maxSuggestions);
    } catch (Exception e) {
        // ignore
    }

    return null;
}
项目:sjk    文件:SearchServiceImpl.java   
/**
 * 初始化SpellIndex
 * 
 * @throws IOException
 */
public void initSpellIndex(boolean isGame) throws IOException {
    FileOPHelper.del(isGame ? appConfig.getGameSpellIndexDir() : appConfig.getSoftSpellIndexDir());
    Directory spellIndexDir = FSDirectory.getDirectory(new File(isGame ? appConfig.getGameSpellIndexDir()
            : appConfig.getSoftSpellIndexDir()));
    SpellChecker spellChecker = new SpellChecker(spellIndexDir);
    spellChecker.indexDictionary(new PlainTextDictionary(new File(isGame ? appConfig.getGameSuggestDict()
            : appConfig.getSoftSuggestDict())));
    spellIndexDir.close();
}
项目:UMLS-Terminology-Server    文件:AtomClassSearchHandler.java   
@Override
public void setProperties(Properties p) throws Exception {

  // Initialize acronyms map
  if (p.containsKey("acronymsFile")) {
    final BufferedReader in = new BufferedReader(
        new FileReader(new File(p.getProperty("acronymsFile"))));
    String line;
    while ((line = in.readLine()) != null) {
      String[] tokens = FieldedStringTokenizer.split(line, "\t");
      if (!acronymExpansionMap.containsKey(tokens[0])) {
        acronymExpansionMap.put(tokens[0], new HashSet<String>(2));
      }
      acronymExpansionMap.get(tokens[0]).add(tokens[1]);
    }
    in.close();
  } else {
    throw new Exception("Required property acronymsFile not present.");
  }

  // Initialize spell checker
  if (p.containsKey("spellingFile") && p.containsKey("spellingIndex")) {
    // expect properties to have "spellingFile" and "spellingIndex"
    final File dir = new File(p.getProperty("spellingIndex"));
    final Directory directory = FSDirectory.open(dir);
    spellChecker =
        new SpellChecker(directory, new LuceneLevenshteinDistance());
    final IndexWriterConfig indexWriterConfig =
        new IndexWriterConfig(Version.LATEST, new WhitespaceAnalyzer());
    spellChecker.indexDictionary(
        new PlainTextDictionary(new File(p.getProperty("spellingFile"))),
        indexWriterConfig, false);

  } else {
    throw new Exception(
        "Required property spellingFile or spellingIndex not present.");
  }
}
项目:magicspells    文件:SpellImpl.java   
/**
    * Constructor. Initializes directory for indexing and dictionary
    * 
    * @param props
    *            properties file Object
    * @throws IOException
    *             when dictionary or directory path is/are invalid or
    *             inaccessible
    */
   public SpellImpl(Properties props) throws IOException {
directory = FSDirectory.open(new File(props.getProperty(
    "index_directory", "res/index")));
dictionary = new PlainTextDictionary(new File(props.getProperty(
    "dictionary_path", "res/dict_en.txt")));
spellChecker = new SpellChecker(directory);
StandardAnalyzer analyzer = new StandardAnalyzer(Version.LUCENE_36);
IndexWriterConfig config = new IndexWriterConfig(Version.LUCENE_36,
    analyzer);
spellChecker.clearIndex();
spellChecker.indexDictionary(dictionary, config, true);
spellChecker.setAccuracy(Float.parseFloat(props.getProperty(
    "default_accuracy", "0.75")));
setMaxSuggestions(Integer.parseInt(props.getProperty("max_suggestions",
    "5")));
   }
项目:WebMIaS    文件:MathNamesSuggester.java   
public MathNamesSuggester() {
    try {
        suggester = new AnalyzingSuggester(new StandardAnalyzer(Version.LUCENE_4_10_2));
        suggester.build(new PlainTextDictionary(getMathNamesReader()));
    } catch (IOException ex) {
        Logger.getLogger(MathNamesSuggester.class.getName()).log(Level.SEVERE, null, ex);
    }
}
项目:tfidf-topology    文件:TermFilter.java   
public void prepare(Map conf, TridentOperationContext context){
    super.prepare(conf, context);
    File dir = new File(System.getProperty("user.home") + "/dictionaries");
    Directory directory;
    try {
        directory = FSDirectory.open(dir);
        spellchecker = new SpellChecker(directory);
        StandardAnalyzer analyzer = new StandardAnalyzer(Version.LUCENE_36);
        IndexWriterConfig config = new IndexWriterConfig(Version.LUCENE_36, analyzer);
        URL dictionaryFile = TermFilter.class.getResource("/dictionaries/fulldictionary00.txt");
        spellchecker.indexDictionary(new PlainTextDictionary(new File(dictionaryFile.toURI())), config, true);
    } catch (Exception e) {
        LOG.error(e.toString());
    }
}
项目:CophiAlignment    文件:LuceneIndexMaker.java   
public void makeIndex() throws Exception{
    spellchecker.indexDictionary(new PlainTextDictionary(fileDict),iwc,true);        
}