0
我正在嘗試使用LanguageTool Java API更正文本文件中存在的一些拼寫錯誤的單詞。通過LT wiki和https://languagetool.org/去後,我嘗試了一些示例代碼 -無法正確使用LanguageTool Java API進行拼寫檢查
JLanguageTool langTool;
String text = "I.- Any reference _in this Section to a panicular genus or species of an anirmgl, cxccpl where the context";
langTool = new JLanguageTool(Language.AMERICAN_ENGLISH);
langTool.activateDefaultPatternRules();
List<RuleMatch> matches = langTool.check(text);
for (RuleMatch match : matches) {
System.out.println("Potential error at line " +
match.getEndLine() + ", column " +
match.getColumn() + ": " + match.getMessage());
System.out.println("Suggested correction: " +
match.getSuggestedReplacements());
}
輸出如下 -
Potential error at line 0, column 19: Possible spelling mistake found
Suggested correction: [Lin, Min, ain, bin, din, fin, gin, in, kin, min, pin, sin, tin, win, yin]
Potential error at line 0, column 41: Possible spelling mistake found
Suggested correction: []
Potential error at line 0, column 74: Possible spelling mistake found
Suggested correction: []
Potential error at line 0, column 83: Possible spelling mistake found
Suggested correction: []
預期輸出繼電器 -
Starting check in English (American)...
1. Line 1, column 19
Message: Possible spelling mistake found (deactivate)
Correction: in; win; bin; pin; tin; min; Lin; din; gin; kin; yin; ain; fin; sin; IN; In; Min; PIN
Context: I.- Any reference _in this Section to a panicular genus or sp...
2. Line 1, column 41
Message: Possible spelling mistake found (deactivate)
Correction: particular; funicular
Context: ...I.- Any reference _in this Section to a panicular genus or species of an anirmgl, cxccpl ...
3. Line 1, column 74
Message: Possible spelling mistake found (deactivate)
Correction: animal
Context: ...n to a panicular genus or species of an anirmgl, cxccpl where the context
4. Line 1, column 83
Message: Possible spelling mistake found (deactivate)
Context: ...nicular genus or species of an anirmgl, cxccpl where the context
Potential problems found: 4 (time: 171ms)
How you can improve LanguageTool
我從LT獨立這個輸出桌面軟件。我將其安裝文件夾及其內容與我的源代碼和API jar進行了比較,但找不到任何特別的東西使前者成爲更好的解決方案。
此外,我想用建議列表中的第一個元素替換拼寫錯誤的單詞。
任何形式的幫助將不勝感激。
'3.5'現在是最新的,它也將在3個月內過期。所以請使用http://wiki.languagetool.org/java-api上給出的版本,我們保持該頁面更新。 (披露:我是LanguageTool的維護者) –
謝謝Daniel .. – Rana