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;
}
use of org.languagetool.rules.RuleMatch in project languagetool by languagetool-org.
the class FalseFriendRuleTest method testHintsForDemoLanguage.
@Test
public void testHintsForDemoLanguage() throws IOException, ParserConfigurationException, SAXException {
JLanguageTool langTool1 = new JLanguageTool(new BritishEnglish(), new German());
langTool1.disableRule(MorfologikBritishSpellerRule.RULE_ID);
List<RuleMatch> matches1 = assertErrors(1, "And forDemoOnly.", langTool1);
assertEquals("DEMO_ENTRY", matches1.get(0).getRule().getId());
JLanguageTool langTool2 = new JLanguageTool(new English(), new German());
langTool2.disableRule(MorfologikBritishSpellerRule.RULE_ID);
List<RuleMatch> matches2 = assertErrors(1, "And forDemoOnly.", langTool2);
assertEquals("DEMO_ENTRY", matches2.get(0).getRule().getId());
JLanguageTool langTool3 = new JLanguageTool(new AmericanEnglish(), new German());
langTool3.disableRule(MorfologikAmericanSpellerRule.RULE_ID);
assertErrors(0, "And forDemoOnly.", langTool3);
}
use of org.languagetool.rules.RuleMatch in project languagetool by languagetool-org.
the class FalseFriendRuleTest method testHintsForGermanSpeakersWithVariant.
@Test
public void testHintsForGermanSpeakersWithVariant() throws IOException, ParserConfigurationException, SAXException {
JLanguageTool langTool = new JLanguageTool(new BritishEnglish(), new SwissGerman());
List<RuleMatch> matches = assertErrors(1, "We will berate you.", langTool);
assertEquals(matches.get(0).getSuggestedReplacements().toString(), "[provide advice, give advice]");
assertErrors(0, "We will give you advice.", langTool);
assertErrors(1, "I go to high school in Berlin.", langTool);
List<RuleMatch> matches2 = assertErrors(1, "The chef", langTool);
assertEquals("[boss, chief]", matches2.get(0).getSuggestedReplacements().toString());
}
use of org.languagetool.rules.RuleMatch in project languagetool by languagetool-org.
the class FalseFriendRuleTest method assertSuggestions.
private void assertSuggestions(int suggestionCount, String text, JLanguageTool langTool) throws IOException {
List<RuleMatch> matches = langTool.check(text);
int suggestionsFound = 0;
for (RuleMatch match : matches) {
int pos = 0;
while (pos != -1) {
pos = match.getMessage().indexOf("<suggestion>", pos + 1);
suggestionsFound++;
}
}
if (suggestionsFound > 0) {
suggestionsFound--;
}
assertEquals(suggestionCount, suggestionsFound);
}
Aggregations