我正在尝试使用 LanguageTool Java API 更正文本文件中存在的一些拼写错误的单词。在浏览了 LT wiki 和https://languagetool.org/之后,我尝试了一些示例代码 -
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 进行了比较,但找不到任何特别之处,这使得前者成为更好的解决方案。
另外,我想用建议列表中的第一个元素替换拼写错误的单词。
任何形式的帮助将不胜感激。