use of org.languagetool.rules.RuleMatch in project languagetool by languagetool-org.
the class ToolsTest method testBitextCheck.
private void testBitextCheck(ResultCache cache) throws IOException, ParserConfigurationException, SAXException {
Language english = Languages.getLanguageForShortCode("en");
JLanguageTool srcTool = new JLanguageTool(english, null, cache);
Language polish = Languages.getLanguageForShortCode("pl");
JLanguageTool trgTool = new JLanguageTool(polish, null, cache);
List<BitextRule> rules = Tools.getBitextRules(english, polish);
int matchCount = Tools.checkBitext("This is a perfectly good sentence.", "To jest całkowicie prawidłowe zdanie.", srcTool, trgTool, rules).size();
assertEquals(0, matchCount);
List<RuleMatch> matches1 = Tools.checkBitext("This is not actual.", "To nie jest aktualne.", srcTool, trgTool, rules);
assertEquals(1, matches1.size());
assertThat(matches1.get(0).getRule().getId(), is("ACTUAL"));
assertThat(matches1.get(0).getFromPos(), is(12));
assertThat(matches1.get(0).getToPos(), is(20));
List<RuleMatch> matches2 = Tools.checkBitext("A sentence. This is not actual.", "Zdanie. To nie jest aktualne.", srcTool, trgTool, rules);
assertEquals(1, matches2.size());
assertThat(matches2.get(0).getRule().getId(), is("ACTUAL"));
assertThat(matches2.get(0).getFromPos(), is(20));
assertThat(matches2.get(0).getToPos(), is(28));
List<RuleMatch> matches3 = Tools.checkBitext("A new sentence. This is not actual.", "Nowa zdanie. To nie jest aktualne.", srcTool, trgTool, rules);
assertEquals(1, matches3.size());
assertThat(matches3.get(0).getRule().getId(), is("ACTUAL"));
assertThat(matches3.get(0).getFromPos(), is(25));
assertThat(matches3.get(0).getToPos(), is(33));
}
use of org.languagetool.rules.RuleMatch 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.RuleMatch 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());
}
use of org.languagetool.rules.RuleMatch in project languagetool by languagetool-org.
the class IndexerSearcherTest method testApostropheElement.
public void testApostropheElement() throws Exception {
createIndex("Daily Bleed's Anarchist Encyclopedia");
List<PatternToken> elements1 = Arrays.asList(new PatternToken("Bleed", false, false, false), new PatternToken("'", false, false, false), new PatternToken("s", false, false, false));
PatternRule rule1 = new PatternRule("RULE1", new English(), elements1, "desc", "msg", "shortMsg");
List<PatternToken> elements2 = Arrays.asList(new PatternToken("Bleed", false, false, false), new PatternToken("'", false, false, false), new PatternToken("x", false, false, false));
PatternRule rule2 = new PatternRule("RULE", new English(), elements2, "desc", "msg", "shortMsg");
SearcherResult searcherResult1 = errorSearcher.findRuleMatchesOnIndex(rule1, new English());
assertEquals(1, searcherResult1.getMatchingSentences().size());
List<RuleMatch> ruleMatches = searcherResult1.getMatchingSentences().get(0).getRuleMatches();
assertEquals(1, ruleMatches.size());
Rule rule = ruleMatches.get(0).getRule();
assertEquals("RULE1", rule.getId());
SearcherResult searcherResult2 = errorSearcher.findRuleMatchesOnIndex(rule2, new English());
assertEquals(0, searcherResult2.getMatchingSentences().size());
}
use of org.languagetool.rules.RuleMatch in project languagetool by languagetool-org.
the class AtomFeedChecker method getMatches.
private List<WikipediaRuleMatch> getMatches(AtomFeedItem item, List<String> texts) throws IOException {
List<WikipediaRuleMatch> oldMatches = new ArrayList<>();
for (String text : texts) {
PlainTextMapping filteredContent = textFilter.filter(text);
List<RuleMatch> ruleMatches = langTool.check(filteredContent.getPlainText());
oldMatches.addAll(toWikipediaRuleMatches(text, filteredContent, ruleMatches, item));
}
return oldMatches;
}
Aggregations