I am trying to correct some misspelled words present in a text file
using LanguageTool Java API. After going through LT wiki and https://languagetool.org/ I tried some example codes -
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());
}
Maven dependency -
<dependency>
<groupId>org.languagetool</groupId>
<artifactId>languagetool</artifactId>
<version>2.0.1</version>
</dependency>
The output is as follows -
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: []
Expected Ouput -
`Starting check in English (American)…
- 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… - 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 … - 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 - 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)`
I got this output from LT standalone Desktop software. I compared its
installation folders and its contents with my source code and API jars
but could not find anything special which is making the former a better
solution.
Also, I want to replace the misspelled words with the first element in suggestion list.
Any kind of help will be highly appreciated.