2013-06-02 4 views
0

나는 lucene.I에서 맞춤법 검사 프로그램을 생각해 보면서 tangentum에서 phonetix 추가 기능 (특히 메타 폰)을 추가하는 데 관심이있었습니다. 내 프로그램에 메타 폰을 통합 할 수있는 방법이 있습니까? 그것을 통합하는 방법?java-lucene의 맞춤법 검사 프로그램에 메타폰을 통합하는 방법은 무엇입니까?

package com.lucene.spellcheck; 
import java.io.File; 
import java.io.IOException; 
import org.apache.lucene.document.Document; 
import org.apache.lucene.document.Field; 
import org.apache.lucene.index.Term; 
import org.apache.lucene.search.IndexSearcher; 
import org.apache.lucene.search.spell.Dictionary; 
import org.apache.lucene.search.spell.PlainTextDictionary; 
import org.apache.lucene.search.spell.SpellChecker; 
import org.apache.lucene.store.Directory; 
import org.apache.lucene.store.FSDirectory; 
public class SimpleSuggestionService { 
private static final String F_WORD = null; 
public static void main(String[] args) throws Exception { 
File dir = new File("e:/spellchecker/"); 
Directory directory = FSDirectory.open(dir); 
SpellChecker spellChecker1 = new SpellChecker(directory); 
spellChecker1.indexDictionary(
new PlainTextDictionary(new File("c:/fulldictionary00.txt"))); 
String wordForSuggestions = "noveil"; 
int suggestionsNumber = 5; 
String[] suggestions = spellChecker1. 
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); 
} 
} 
}  

답변

0

당신이 원하는 음성 알고리즘을 사용하거나 같은 표준 LevensteinDistance 다른 유사 알고리즘 (일부 방법입니다 결합하여 사용자 정의 StringDistance 구현에 전달할 수 있습니다. 당신은 단지 getDistance (문자열을 구현해야합니다, String) 메서드를 StringDistance 구현에 넣습니다. 아마도 다음과 같습니다.

public MetaphoneDistance() { 
    Metaphone metaphone = new Metaphone(); 
} 

//I'm not really familiar with the library you mentioned, but I assume generateKeys performs a double metaphone? 
public float getDistance(String str1, ,String str2) { 
    String[] keys1 = metaphone.getKeys(str1); 
    String[] keys2 = metaphone.getKeys(str2); 
    float result = 0; 
    if (key1[0] == key2[0] || key1[0] == key2[1]) result += .5 
    if (key1[1] == key2[0] || key1[1] == key2[1]) result += .5 
    return result; 
}