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());
}
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());
}
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());
}
}
}
}
}
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");
}
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;
}
Aggregations