I want to use LanguageTools (great tool!) in a Java application (in a Maven Mojo) for an automatic check of our DocBook documentation.
What is the best way to add my own rules? With addTemporaryFile? Another question: In the standalone version, one gets the context of an error which is very helpful but RuleMatch has not method for this. So, how can I get the context?
What is the best way to add my own rules? With addTemporaryFile?
addTemporaryFile is an internal method, I will improve its javadoc to
avoid confusion. This should work:
PatternRuleLoader loader = new PatternRuleLoader();
List<PatternRule> rules = loader.getRules(new File("/path/to/myGrammar.xml"));
for (PatternRule rule : rules) {
languageTool.addRule(rule);
}
Another question: In the standalone version, one gets the context of
an error which is very helpful but RuleMatch has not method for this.
So, how can I get the context?
There are methods for that in StringTools, or in ContextTools (if
you’re using the development version).
Wow, that was fast
The PatternRuleLoader worked fine, thanks!
How is it with words for the spellcheck? I’ve added some names etc. to the English ignore.txt file of hunspell. Is there a similar way to add them to the JLanguageTool class?
How is it with words for the spellcheck? I’ve added some names etc.
to the English ignore.txt file of hunspell. Is there a similar way to
add them to the JLanguageTool class?
Suppose i have written a class for a rule by extending the rule class.How do i use that newly built rule in my language tool.How do i add that class? How do i test my formed rule?
Simply call JLanguageTool.addRule(new YourNewRule()) if you’re using LanguageTool via API. If not, you will have to compile LT yourself and add your rule to English.getRelevantRules() (or whatever language your rule is for).
It looks like your project isn’t set up properly yet. There’s documentation at Java API - LanguageTool Wiki on how to add LanguageTool to your project.