我现在在研究这么一个问题,始终解决不了,我想用java实现,一个类似于word的拼写检查工具, 就是说,你输入错了,它能把类似的词组,汉字等现实出来,在网络上看到了一个JazzyPlugin.jar的包,但是需要,以个中文的字库,系统地字库我不知道,怎么读取,有没有方法得到一个非2进制的汉字/词组的文件么,或者是给提供另外一套实现的方案呢,最好给说的具体点,谢谢了
调试欢乐多
InputStreamReader insr = new InputStreamReader(ins, "XXX");
在"XXX"里面填入你的中文的编码
import java.io.BufferedReader;
import java.io.File;
import java.io.InputStreamReader;
import java.util.Iterator;
import java.util.List;import com.swabunga.spell.engine.SpellDictionary;
import com.swabunga.spell.engine.SpellDictionaryHashMap;
import com.swabunga.spell.event.SpellCheckEvent;
import com.swabunga.spell.event.SpellCheckListener;
import com.swabunga.spell.event.SpellChecker;
import com.swabunga.spell.event.StringWordTokenizer;public class Suggest { public static class SuggestionListener implements SpellCheckListener { public void spellingError(SpellCheckEvent event) {
System.out.println("Misspelling: " + event.getInvalidWord()); List suggestions = event.getSuggestions();
if (suggestions.isEmpty()) {
System.out.println("No suggestions found.");
} else {
System.out.print("Suggestions: "); for (Iterator i = suggestions.iterator(); i.hasNext();) {
System.out.print(i.next());
if (i.hasNext()) {
System.out.print(", ");
}
}
System.out.println();
}
} } public static void main(String[] args) throws Exception {
File file = new File("d:/wang.txt");
System.out.println(file.exists());
SpellDictionary dictionary = new SpellDictionaryHashMap(file);
SpellChecker spellChecker = new SpellChecker(dictionary);
spellChecker.addSpellCheckListener(new SuggestionListener()); BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
while (true) {
System.out.print("Enter line to spell check (return to exit): ");
String line = in.readLine(); if (line.length() == 0) {
break;
}
spellChecker.checkSpelling(new StringWordTokenizer(line));
}
}} 这是一个例子,不过,要求,自己定义一个文件, 里面是字库,还是实现不了啊