use of org.languagetool.rules.patterns.PatternToken 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.patterns.PatternToken in project languagetool by languagetool-org.
the class IndexerSearcherTest method testWithOneElementWithException.
public void testWithOneElementWithException() throws Exception {
createIndex("How to move back and fourth from linux to xmb?");
PatternToken exceptionElem = new PatternToken("", false, true, false);
exceptionElem.setStringPosException("exception", false, false, false, false, false, "POS", false, false, null);
List<PatternToken> patternTokens = Arrays.asList(exceptionElem);
PatternRule rule1 = new PatternRule("RULE1", new English(), patternTokens, "desc", "msg", "shortMsg");
Searcher errorSearcher = new Searcher(directory);
try {
errorSearcher.findRuleMatchesOnIndex(rule1, new English());
fail();
} catch (UnsupportedPatternRuleException ignored) {
}
}
use of org.languagetool.rules.patterns.PatternToken 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.patterns.PatternToken in project languagetool by languagetool-org.
the class IndexerSearcherTest method testNegatedMatchAtSentenceStart.
public void testNegatedMatchAtSentenceStart() throws Exception {
createIndex("How to move?");
PatternToken negatedPatternToken = new PatternToken("Negated", false, false, false);
negatedPatternToken.setNegation(true);
List<PatternToken> patternTokens = Arrays.asList(negatedPatternToken, new PatternToken("How", false, false, false));
Searcher errorSearcher = new Searcher(directory);
PatternRule rule1 = new PatternRule("RULE1", new English(), patternTokens, "desc", "msg", "shortMsg");
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.patterns.PatternToken in project languagetool by languagetool-org.
the class IndexerSearcherTest method testWithRegexRule.
public void testWithRegexRule() 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("forth|back", false, true, 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());
}
Aggregations