当前位置: 首页>>代码示例>>Java>>正文


Java PlainTextDictionary类代码示例

本文整理汇总了Java中org.apache.lucene.search.spell.PlainTextDictionary的典型用法代码示例。如果您正苦于以下问题:Java PlainTextDictionary类的具体用法?Java PlainTextDictionary怎么用?Java PlainTextDictionary使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


PlainTextDictionary类属于org.apache.lucene.search.spell包,在下文中一共展示了PlainTextDictionary类的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: suggestEndpointOptions

import org.apache.lucene.search.spell.PlainTextDictionary; //导入依赖的package包/类
@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;
}
 
开发者ID:HydAu,项目名称:Camel,代码行数:26,代码来源:LuceneSuggestionStrategy.java

示例2: initSpellIndex

import org.apache.lucene.search.spell.PlainTextDictionary; //导入依赖的package包/类
/**
 * 初始化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();
}
 
开发者ID:zhaoxi1988,项目名称:sjk,代码行数:15,代码来源:SearchServiceImpl.java

示例3: setProperties

import org.apache.lucene.search.spell.PlainTextDictionary; //导入依赖的package包/类
@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.");
  }
}
 
开发者ID:WestCoastInformatics,项目名称:UMLS-Terminology-Server,代码行数:39,代码来源:AtomClassSearchHandler.java

示例4: SpellImpl

import org.apache.lucene.search.spell.PlainTextDictionary; //导入依赖的package包/类
/**
    * 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")));
   }
 
开发者ID:seekme94,项目名称:magicspells,代码行数:26,代码来源:SpellImpl.java

示例5: MathNamesSuggester

import org.apache.lucene.search.spell.PlainTextDictionary; //导入依赖的package包/类
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);
    }
}
 
开发者ID:martinliska,项目名称:WebMIaS,代码行数:9,代码来源:MathNamesSuggester.java

示例6: prepare

import org.apache.lucene.search.spell.PlainTextDictionary; //导入依赖的package包/类
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());
    }
}
 
开发者ID:domenicosolazzo,项目名称:tfidf-topology,代码行数:16,代码来源:TermFilter.java

示例7: makeIndex

import org.apache.lucene.search.spell.PlainTextDictionary; //导入依赖的package包/类
public void makeIndex() throws Exception{
    spellchecker.indexDictionary(new PlainTextDictionary(fileDict),iwc,true);        
}
 
开发者ID:angelodel80,项目名称:CophiAlignment,代码行数:4,代码来源:LuceneIndexMaker.java


注:本文中的org.apache.lucene.search.spell.PlainTextDictionary类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。