Search in sources :

Example 31 with Rule

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

the class GermanyGerman method getRelevantRules.

@Override
public List<Rule> getRelevantRules(ResourceBundle messages) throws IOException {
    List<Rule> rules = new ArrayList<>(super.getRelevantRules(messages));
    rules.add(new GermanSpellerRule(messages, this));
    return rules;
}
Also used : ArrayList(java.util.ArrayList) GermanSpellerRule(org.languagetool.rules.de.GermanSpellerRule) Rule(org.languagetool.rules.Rule) GermanSpellerRule(org.languagetool.rules.de.GermanSpellerRule)

Example 32 with Rule

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

the class ResultAreaHelper method getDisabledRulesHtml.

private String getDisabledRulesHtml() {
    StringBuilder sb = new StringBuilder(40);
    sb.append(messages.getString("deactivatedRulesText"));
    int i = 0;
    int deactivatedRuleCount = 0;
    for (String ruleId : ltSupport.getConfig().getDisabledRuleIds()) {
        if (ruleId.trim().isEmpty()) {
            continue;
        }
        Rule rule = ltSupport.getRuleForId(ruleId);
        if (rule == null || rule.isDefaultOff()) {
            continue;
        }
        if (i++ > 0) {
            sb.append(',');
        }
        RuleLink reactivationLink = RuleLink.buildReactivationLink(rule);
        sb.append(" <a href=\"").append(reactivationLink).append("\">").append(rule.getDescription()).append("</a>");
        deactivatedRuleCount++;
    }
    sb.append("<br>");
    if (deactivatedRuleCount == 0) {
        return "";
    } else {
        return sb.toString();
    }
}
Also used : Rule(org.languagetool.rules.Rule)

Example 33 with Rule

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

the class LanguageToolSupport method getDisabledRules.

private List<Rule> getDisabledRules() {
    List<Rule> disabledRules = new ArrayList<>();
    for (String ruleId : languageTool.getDisabledRules()) {
        Rule rule = getRuleForId(ruleId);
        if (rule == null || rule.isDefaultOff()) {
            continue;
        }
        disabledRules.add(rule);
    }
    Collections.sort(disabledRules, (r1, r2) -> r1.getDescription().compareTo(r2.getDescription()));
    return disabledRules;
}
Also used : Rule(org.languagetool.rules.Rule)

Example 34 with Rule

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

the class LanguageToolSupport method createRulesMenu.

private void createRulesMenu(JMenu parent, List<Rule> rules) {
    JMenu menu = parent;
    int count = 0;
    for (Rule rule : rules) {
        count++;
        String id = rule.getId();
        JMenuItem ruleItem = new JMenuItem(rule.getDescription());
        ruleItem.addActionListener(e -> enableRule(id));
        menu.add(ruleItem);
        if (rules.size() <= MAX_RULES_PER_MENU) {
            continue;
        }
        //but only if the remain entries are more than one
        if ((count % (MAX_RULES_PER_MENU - 1) == 0) && (rules.size() - count > 1)) {
            JMenu more = new JMenu(messages.getString("guiActivateRuleMoreRules"));
            menu.add(more);
            menu = more;
        }
    }
}
Also used : Rule(org.languagetool.rules.Rule)

Example 35 with Rule

use of org.languagetool.rules.Rule 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

Rule (org.languagetool.rules.Rule)67 JLanguageTool (org.languagetool.JLanguageTool)16 PatternRule (org.languagetool.rules.patterns.PatternRule)15 ArrayList (java.util.ArrayList)14 RuleMatch (org.languagetool.rules.RuleMatch)14 AbstractPatternRule (org.languagetool.rules.patterns.AbstractPatternRule)12 Test (org.junit.Test)11 Language (org.languagetool.Language)11 IncorrectExample (org.languagetool.rules.IncorrectExample)8 English (org.languagetool.language.English)7 SpellingCheckRule (org.languagetool.rules.spelling.SpellingCheckRule)7 File (java.io.File)6 PatternToken (org.languagetool.rules.patterns.PatternToken)6 AnalyzedSentence (org.languagetool.AnalyzedSentence)5 AmericanEnglish (org.languagetool.language.AmericanEnglish)5 BitextRule (org.languagetool.rules.bitext.BitextRule)5 GermanSpellerRule (org.languagetool.rules.de.GermanSpellerRule)4 DisambiguationPatternRule (org.languagetool.tagging.disambiguation.rules.DisambiguationPatternRule)4 FileReader (java.io.FileReader)3 IOException (java.io.IOException)3