gpt4 book ai didi

java - 无法使用 LanguageTool Java API 正确进行拼写检查

转载 作者:行者123 更新时间:2023-12-01 09:25:55 24 4
gpt4 key购买 nike

我正在尝试使用 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 进行了比较,但找不到任何特殊的东西,这使得前者成为更好的解决方案。

此外,我想用建议列表中的第一个元素替换拼写错误的单词。

任何形式的帮助都将受到高度赞赏。

最佳答案

我使用的是旧的 Languagetool jar。请使用这个 -

<dependency>
<groupId>org.languagetool</groupId>
<artifactId>language-en</artifactId>
<version>3.5</version>
</dependency>

此外,可以通过从(match.getFromPos() 到 match.getToPos())中选择拼写错误的单词并用建议列表中最有说服力的单词替换它来完成拼写纠正(由程序员选择单词) .

希望对您有所帮助。

关于java - 无法使用 LanguageTool Java API 正确进行拼写检查,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39828618/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com