我正在尝试在java中实现google的“你是说吗”功能。 我在互联网上发现一些代码说它工作正常,但在尝试运行它时却出现错误。我认为这与目录创建有关,这是我不完全理解的代码的唯一部分。
这是代码,您能给我一些关于问题所在的帮助吗? 提前致谢!
public static void main(String[] args) throws Exception {
File dir = new File("C:/Users/Lala");
Directory directory = FSDirectory.open(dir);
SpellChecker spellChecker = new SpellChecker(directory);
spellChecker.indexDictionary(
new PlainTextDictionary(new File("fulldictionary00.txt")));
String wordForSuggestions = "hwllo";
int suggestionsNumber = 5;
String[] suggestions = spellChecker.
suggestSimilar(wordForSuggestions, suggestionsNumber);
if (suggestions!=null && suggestions.length>0) {
for (String word : suggestions) {
System.out.println("Did you mean:" + word);
}
}
else {
System.out.println("No suggestions found for word:"+wordForSuggestions);
}
}
文件 fulldictionary00.txt
是格式正确的纯文本文件。
我得到的错误是在第 18 行:
SpellChecker spellChecker = new SpellChecker(directory);
所以它与目录创建有关。我粘贴了我收到的错误,以防万一您看到它时有任何想法。
Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/lucene/document/Fieldable at did_you_mean.main(did_you_mean.java:18) Caused by:
java.lang.ClassNotFoundException: org.apache.lucene.document.Fieldable
最佳答案
在 lucene 4.0.0 中,拼写检查器被放在名为 lucene-suggest-4.0.0.jar 的包中,而不是 lucene-spellchecker-XXX.jar
关于java - 尝试在java中实现Google的 "did you mean"功能,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13377232/