lucene 맞춤법 검사기를 사용하여 맞춤법 교정기를 작성하려고합니다. 블로그 텍스트 콘텐츠가 포함 된 단일 텍스트 파일을 제공하고 싶습니다. 문제는 사전 파일에 줄당 한 문장 씩 줄 때만 작동한다는 것입니다. 또한 제안 API는 발생 횟수에 어떠한 가중치도주지 않고 결과를 반환합니다. 다음은 소스 코드입니다lucene을 사용하는 맞춤법 검사기
public class SpellCorrector {
SpellChecker spellChecker = null;
public SpellCorrector() {
try {
File file = new File("/home/ubuntu/spellCheckIndex");
Directory directory = FSDirectory.open(file);
spellChecker = new SpellChecker(directory);
StandardAnalyzer analyzer = new StandardAnalyzer(Version.LUCENE_36);
IndexWriterConfig config = new IndexWriterConfig(Version.LUCENE_36, analyzer);
spellChecker.indexDictionary(
new PlainTextDictionary(new File("/home/ubuntu/main.dictionary")), config, true);
//Should I format this file with one sentence/word per line?
} catch (IOException e) {
}
}
public String correct(String query) {
if (spellChecker != null) {
try {
String[] suggestions = spellChecker.suggestSimilar(query, 5);
// This returns the suggestion not based on occurence but based on when it occured
if (suggestions != null) {
if (suggestions.length != 0) {
return suggestions[0];
}
}
} catch (IOException e) {
return null;
}
}
return null;
}
}
일부 변경해야합니까?