Search in sources :

Example 71 with RuleMatch

use of org.languagetool.rules.RuleMatch in project languagetool by languagetool-org.

the class CompactStdoutHandler method handleResult.

@Override
protected void handleResult(Sentence sentence, List<RuleMatch> ruleMatches, Language language) {
    if (ruleMatches.size() > 0) {
        for (RuleMatch match : ruleMatches) {
            String ruleId = match.getRule().getId();
            if (match.getRule() instanceof AbstractPatternRule) {
                AbstractPatternRule pRule = (AbstractPatternRule) match.getRule();
                ruleId = pRule.getFullId();
            }
            System.out.println(ruleId + ": " + contextTools.getContext(match.getFromPos(), match.getToPos(), sentence.getText()));
            checkMaxErrors(++errorCount);
        }
    }
    checkMaxSentences(++sentenceCount);
}
Also used : RuleMatch(org.languagetool.rules.RuleMatch) AbstractPatternRule(org.languagetool.rules.patterns.AbstractPatternRule)

Example 72 with RuleMatch

use of org.languagetool.rules.RuleMatch in project languagetool by languagetool-org.

the class LanguageToolSupport method updateHighlights.

private void updateHighlights(String disabledRule) {
    List<Span> spans = new ArrayList<>();
    List<RuleMatch> matches = new ArrayList<>();
    for (RuleMatch match : ruleMatches) {
        if (match.getRule().getId().equals(disabledRule)) {
            continue;
        }
        matches.add(match);
        spans.add(new Span(match));
    }
    prepareUpdateHighlights(matches, spans);
}
Also used : RuleMatch(org.languagetool.rules.RuleMatch)

Example 73 with RuleMatch

use of org.languagetool.rules.RuleMatch in project languagetool by languagetool-org.

the class LanguageToolSupport method updateHighlights.

private void updateHighlights(List<RuleMatch> matches) {
    List<Span> spans = new ArrayList<>();
    for (RuleMatch match : matches) {
        spans.add(new Span(match));
    }
    prepareUpdateHighlights(matches, spans);
}
Also used : RuleMatch(org.languagetool.rules.RuleMatch)

Example 74 with RuleMatch

use of org.languagetool.rules.RuleMatch in project languagetool by languagetool-org.

the class MorfologikAsturianSpellerRuleTest method testMorfologikSpeller.

@Test
public void testMorfologikSpeller() throws IOException {
    Asturian language = new Asturian();
    MorfologikAsturianSpellerRule rule = new MorfologikAsturianSpellerRule(TestTools.getMessages("en"), language);
    JLanguageTool langTool = new JLanguageTool(language);
    assertEquals(0, rule.match(langTool.getAnalyzedSentence("¿Festeyate colos correutores gramaticales?")).length);
    RuleMatch[] matches = rule.match(langTool.getAnalyzedSentence("¿Afáyeste colos correutores gramaticales?"));
    assertEquals(1, matches.length);
    assertEquals(1, matches[0].getFromPos());
    assertEquals(9, matches[0].getToPos());
    assertEquals("Afayesti", matches[0].getSuggestedReplacements().get(0));
}
Also used : RuleMatch(org.languagetool.rules.RuleMatch) Asturian(org.languagetool.language.Asturian) JLanguageTool(org.languagetool.JLanguageTool) Test(org.junit.Test)

Example 75 with RuleMatch

use of org.languagetool.rules.RuleMatch in project languagetool by languagetool-org.

the class CommandLineTools method printMatches.

/**
   * Displays matches in a simple text format.
   * @param ruleMatches Matches from rules.
   * @param prevMatches Number of previously found matches.
   * @param contents  The text that was checked.
   * @param contextSize The size of contents displayed.
   * @since 1.0.1
   */
private static void printMatches(List<RuleMatch> ruleMatches, int prevMatches, String contents, int contextSize) {
    int i = 1;
    ContextTools contextTools = new ContextTools();
    contextTools.setContextSize(contextSize);
    for (RuleMatch match : ruleMatches) {
        Rule rule = match.getRule();
        String output = i + prevMatches + ".) Line " + (match.getLine() + 1) + ", column " + match.getColumn() + ", Rule ID: " + rule.getId();
        if (rule instanceof AbstractPatternRule) {
            AbstractPatternRule pRule = (AbstractPatternRule) rule;
            if (pRule.getSubId() != null) {
                output += "[" + pRule.getSubId() + "]";
            }
        }
        System.out.println(output);
        String msg = match.getMessage();
        msg = msg.replaceAll("</?suggestion>", "'");
        System.out.println("Message: " + msg);
        List<String> replacements = match.getSuggestedReplacements();
        if (!replacements.isEmpty()) {
            System.out.println("Suggestion: " + String.join("; ", replacements));
        }
        System.out.println(contextTools.getPlainTextContext(match.getFromPos(), match.getToPos(), contents));
        if (rule.getUrl() != null) {
            System.out.println("More info: " + rule.getUrl());
        }
        if (i < ruleMatches.size()) {
            System.out.println();
        }
        i++;
    }
}
Also used : RuleMatch(org.languagetool.rules.RuleMatch) BitextRule(org.languagetool.rules.bitext.BitextRule) TextLevelRule(org.languagetool.rules.TextLevelRule) Rule(org.languagetool.rules.Rule) AbstractPatternRule(org.languagetool.rules.patterns.AbstractPatternRule) ContextTools(org.languagetool.tools.ContextTools) AbstractPatternRule(org.languagetool.rules.patterns.AbstractPatternRule)

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