I created myGrammar.xml to add new rules as I want. I added these rules with patternRuleLoader() method. when I printed the ID of a rule, there is no problem. But when I want to try these rules, There is no suggested words and it will give an error like java.lang.IndexOutOfBoundsException: Index: 0, Size: 0 to “replaceSentence = sentence.replace(wrongStr, match.getSuggestedReplacements().get(0));”.
Here is myGrammar.xml:
<?xml version="1.0" encoding="UTF-8"?> <?xml-stylesheet type="text/xsl" href="../../../../../../../../../languagetool-core/src/main/resources/org/languagetool/rules/print.xsl" ?> <?xml-stylesheet type="text/css" href="../../../../../../../../../languagetool-core/src/main/resources/org/languagetool/rules/rules.css" title="Easy editing stylesheet" ?> <rules lang="en" >
<!-- ====================================================================== -->
<!-- Possible typo -->
<!-- ====================================================================== -->
<category id="TYPOS" name="Possible Typo" type="misspelling">
<!-- English rule, 2020-11-03 -->
<rule id="FND" name="find">
<pattern>
<token>fnd</token>
</pattern>
<message>Do you mean "find"?</message>
<example correction='find'>How can I <marker>fnd</marker> the application?</example>
</rule>
<!-- English rule, 2020-11-03 -->
<rule id="FAND" name="find">
<pattern>
<token>fand</token>
</pattern>
<message>Do you mean "find"?</message>
<example correction='find'>How can I <marker>fand</marker> the application?</example>
</rule>
</category>
</rules>
and here is my main code that I am loading my rules:
PatternRuleLoader loader = new PatternRuleLoader();
List<AbstractPatternRule> rules = loader.getRules(new File("home/my-grammar.xml"));
//List<AbstractPatternRule> rules = JLanguageTool.loadPatternRules("home/my-grammar.xml");
System.out.println(rules.get(0).getFullId());
for (AbstractPatternRule rule : rules) {
langTool.addRule(rule);
}
My sentence that I tried is “How can I fnd the application”.
Please help me. I did almost everything to add this rule such as importing Language Tool as locally or changing the grammar.xml from maven repository. However ı can not succeed.
Thanks for your help.