Search in sources :

Example 26 with Rule

use of org.languagetool.rules.Rule in project languagetool by languagetool-org.

the class IndexerSearcherTest method testWithNewRule.

public void testWithNewRule() throws Exception {
    createIndex("How to move back and fourth from linux to xmb?");
    List<PatternToken> patternTokens = Arrays.asList(new PatternToken("move", false, false, false), new PatternToken("back", false, false, false));
    PatternRule rule1 = new PatternRule("RULE1", new English(), patternTokens, "desc", "msg", "shortMsg");
    Searcher errorSearcher = new Searcher(directory);
    SearcherResult searcherResult = errorSearcher.findRuleMatchesOnIndex(rule1, new English());
    assertEquals(1, searcherResult.getCheckedSentences());
    assertEquals(1, searcherResult.getMatchingSentences().size());
    List<RuleMatch> ruleMatches = searcherResult.getMatchingSentences().get(0).getRuleMatches();
    assertEquals(1, ruleMatches.size());
    Rule rule = ruleMatches.get(0).getRule();
    assertEquals("RULE1", rule.getId());
}
Also used : English(org.languagetool.language.English) PatternToken(org.languagetool.rules.patterns.PatternToken) RuleMatch(org.languagetool.rules.RuleMatch) PatternRule(org.languagetool.rules.patterns.PatternRule) PatternRule(org.languagetool.rules.patterns.PatternRule) Rule(org.languagetool.rules.Rule)

Example 27 with Rule

use of org.languagetool.rules.Rule in project languagetool by languagetool-org.

the class IndexerSearcherTest method testWithException.

public void testWithException() throws Exception {
    createIndex("How to move back and fourth from linux to xmb?");
    PatternToken exceptionElem = new PatternToken("forth|back", false, true, false);
    exceptionElem.setStringPosException("exception", false, false, false, false, false, "POS", false, false, null);
    List<PatternToken> patternTokens = Arrays.asList(new PatternToken("move", false, false, false), exceptionElem);
    PatternRule rule1 = new PatternRule("RULE1", new English(), patternTokens, "desc", "msg", "shortMsg");
    Searcher errorSearcher = new Searcher(directory);
    SearcherResult searcherResult = errorSearcher.findRuleMatchesOnIndex(rule1, new English());
    assertEquals(1, searcherResult.getCheckedSentences());
    assertEquals(1, searcherResult.getMatchingSentences().size());
    List<RuleMatch> ruleMatches = searcherResult.getMatchingSentences().get(0).getRuleMatches();
    assertEquals(1, ruleMatches.size());
    Rule rule = ruleMatches.get(0).getRule();
    assertEquals("RULE1", rule.getId());
}
Also used : English(org.languagetool.language.English) PatternToken(org.languagetool.rules.patterns.PatternToken) RuleMatch(org.languagetool.rules.RuleMatch) PatternRule(org.languagetool.rules.patterns.PatternRule) PatternRule(org.languagetool.rules.patterns.PatternRule) Rule(org.languagetool.rules.Rule)

Example 28 with Rule

use of org.languagetool.rules.Rule in project languagetool by languagetool-org.

the class SentenceSourceChecker method activateAdditionalCategories.

private void activateAdditionalCategories(String[] additionalCategoryIds, JLanguageTool languageTool) {
    if (additionalCategoryIds != null) {
        for (String categoryId : additionalCategoryIds) {
            for (Rule rule : languageTool.getAllRules()) {
                if (rule.getCategory().getName().equals(categoryId)) {
                    System.out.println("Activating " + rule.getId() + " in category " + categoryId);
                    languageTool.enableRule(rule.getId());
                }
            }
        }
    }
}
Also used : Rule(org.languagetool.rules.Rule)

Example 29 with Rule

use of org.languagetool.rules.Rule in project languagetool by languagetool-org.

the class SentenceSourceChecker method disableSpellingRules.

private void disableSpellingRules(JLanguageTool languageTool) {
    List<Rule> allActiveRules = languageTool.getAllActiveRules();
    for (Rule rule : allActiveRules) {
        if (rule.isDictionaryBasedSpellingRule()) {
            languageTool.disableRule(rule.getId());
        }
    }
    System.out.println("All spelling rules are disabled");
}
Also used : Rule(org.languagetool.rules.Rule)

Example 30 with Rule

use of org.languagetool.rules.Rule in project languagetool by languagetool-org.

the class AustrianGerman method getRelevantRules.

@Override
public List<Rule> getRelevantRules(ResourceBundle messages) throws IOException {
    List<Rule> rules = new ArrayList<>(super.getRelevantRules(messages));
    rules.add(new GermanSpellerRule(messages, this));
    return rules;
}
Also used : ArrayList(java.util.ArrayList) GermanSpellerRule(org.languagetool.rules.de.GermanSpellerRule) Rule(org.languagetool.rules.Rule) GermanSpellerRule(org.languagetool.rules.de.GermanSpellerRule)

Aggregations

Rule (org.languagetool.rules.Rule)67 JLanguageTool (org.languagetool.JLanguageTool)16 PatternRule (org.languagetool.rules.patterns.PatternRule)15 ArrayList (java.util.ArrayList)14 RuleMatch (org.languagetool.rules.RuleMatch)14 AbstractPatternRule (org.languagetool.rules.patterns.AbstractPatternRule)12 Test (org.junit.Test)11 Language (org.languagetool.Language)11 IncorrectExample (org.languagetool.rules.IncorrectExample)8 English (org.languagetool.language.English)7 SpellingCheckRule (org.languagetool.rules.spelling.SpellingCheckRule)7 File (java.io.File)6 PatternToken (org.languagetool.rules.patterns.PatternToken)6 AnalyzedSentence (org.languagetool.AnalyzedSentence)5 AmericanEnglish (org.languagetool.language.AmericanEnglish)5 BitextRule (org.languagetool.rules.bitext.BitextRule)5 GermanSpellerRule (org.languagetool.rules.de.GermanSpellerRule)4 DisambiguationPatternRule (org.languagetool.tagging.disambiguation.rules.DisambiguationPatternRule)4 FileReader (java.io.FileReader)3 IOException (java.io.IOException)3