本文整理汇总了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;
}
示例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();
}
示例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.");
}
}
示例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")));
}
示例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);
}
}
示例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());
}
}
示例7: makeIndex
import org.apache.lucene.search.spell.PlainTextDictionary; //导入依赖的package包/类
public void makeIndex() throws Exception{
spellchecker.indexDictionary(new PlainTextDictionary(fileDict),iwc,true);
}