Back to LanguageTool Homepage - Privacy - Imprint

Best way to add new rules when using with Maven in a Java Application


(Michael) #1

Hi,

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?

Regards,
Michael


[Solved] Check-create rules deal with grammar.xml
(Daniel Naber) #2

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).

Regards
Daniel


(Michael) #3

Wow, that was fast :wink:
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?

Regards,
Michael


(Daniel Naber) #4

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?

Yes, see
http://languagetool-user-forum.2306527.n4.nabble.com/Is-there-support-to-add-custom-words-to-the-existing-dictionary-td4641042.html

Regards
Daniel


(Daniel Naber) #5

Actually it's even a bit easier using JLanguageTool.loadPatternRules(File), no need to use PatternRuleLoader directly.


(rishika) #6

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?


(Daniel Naber) #7

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).


(rishika) #8

I am using LanguageTool API .The WordRepeatRule.java code is this https://github.com/languagetool-org/languagetool/blob/master/languagetool-core/src/main/java/org/languagetool/rules/WordRepeatRule.java and i have written a code in java like this http://ideone.com/7S87Pi ,but this doesn't work.It shows error. Kindly help


(Daniel Naber) #9

It looks like your project isn't set up properly yet. There's documentation at http://wiki.languagetool.org/java-api on how to add LanguageTool to your project.