Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to add two-word patterns to be ignored by LanguageTool?

Tags:

Situation:

As a workaround for the not yet implemented feature to add a user dictionary of words to Languagetool, I came up with this code snippet:

JLanguageTool langTool = new JLanguageTool(lang);
langTool.activateDefaultPatternRules();
List<Rule> rules = langTool.getAllActiveRules();
for (Rule rule:rules) {
    // System.out.println(rule.getId());
    if (rule.getId().equals("GERMAN_SPELLER_RULE")) {
        if (rule instanceof SpellingCheckRule) {
            SpellingCheckRule srule=(SpellingCheckRule) rule;
            String [] words={"word1", "word2"};
            List<String> tokens=new ArrayList<String>();
            for (String word:words) {
                tokens.add(word);
            }
            srule.addIgnoreTokens(tokens);
        }
    }
}

which will nicely add the list of words specified by

String [] words={"word1", "word2"};

to the list of ignored words. But how about word combinations/two word patterns like "Guest bathroom", "French word" "test application" - how could I get these ignored without modifying the orginal grammar file? I assume creating some user defined rule could do the trick and might also be a more elegant solution for the above code snippet.

Question:

What would be a working approach to get a user-dictionary work-around going that ignores single and two-word phrases?

like image 390
Wolfgang Fahl Avatar asked Sep 23 '14 19:09

Wolfgang Fahl


1 Answers

An ignore.txt file is supported since version 2.9. see the CHANGES.txt at bullet -Spelling.

Two word phrases are not supported. see the check in method loadWordsToBeIgnored in SpellingCheckRule.java. (if you would do so the check will fail with a "RuntimeException: No space expected in ...")

like image 57
SubOptimal Avatar answered Sep 28 '22 10:09

SubOptimal