Search in sources :

Example 86 with RuleMatch

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());
}
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 87 with RuleMatch

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;
}
Also used : PlainTextMapping(org.languagetool.dev.wikipedia.PlainTextMapping) RuleMatch(org.languagetool.rules.RuleMatch)

Example 88 with RuleMatch

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);
}
Also used : RuleMatch(org.languagetool.rules.RuleMatch) JLanguageTool(org.languagetool.JLanguageTool) Test(org.junit.Test)

Example 89 with RuleMatch

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());
}
Also used : RuleMatch(org.languagetool.rules.RuleMatch) JLanguageTool(org.languagetool.JLanguageTool) Test(org.junit.Test)

Example 90 with RuleMatch

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);
}
Also used : RuleMatch(org.languagetool.rules.RuleMatch)

Aggregations

RuleMatch (org.languagetool.rules.RuleMatch)144 Test (org.junit.Test)64 JLanguageTool (org.languagetool.JLanguageTool)54 ArrayList (java.util.ArrayList)30 AnalyzedTokenReadings (org.languagetool.AnalyzedTokenReadings)14 Rule (org.languagetool.rules.Rule)14 Language (org.languagetool.Language)10 PatternRule (org.languagetool.rules.patterns.PatternRule)10 AnalyzedSentence (org.languagetool.AnalyzedSentence)8 Ukrainian (org.languagetool.language.Ukrainian)8 AbstractPatternRule (org.languagetool.rules.patterns.AbstractPatternRule)8 Matcher (java.util.regex.Matcher)7 English (org.languagetool.language.English)7 IOException (java.io.IOException)6 Catalan (org.languagetool.language.Catalan)6 Polish (org.languagetool.language.Polish)6 GermanyGerman (org.languagetool.language.GermanyGerman)5 AnnotatedText (org.languagetool.markup.AnnotatedText)5 PatternToken (org.languagetool.rules.patterns.PatternToken)5 AnalyzedToken (org.languagetool.AnalyzedToken)4