Search in sources :

Example 66 with Rule

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

the class ExampleSentenceCorrectionCreator method checkCorrections.

private void checkCorrections(Rule rule, IncorrectExample incorrectExample, List<String> xmlLines, JLanguageTool tool) throws IOException {
    List<String> corrections = incorrectExample.getCorrections();
    if (corrections.isEmpty()) {
        for (Rule r : tool.getAllActiveRules()) {
            tool.disableRule(r.getId());
        }
        tool.enableRule(rule.getId());
        String incorrectSentence = incorrectExample.getExample().replaceAll("</?marker>", "");
        List<RuleMatch> matches = tool.check(incorrectSentence);
        System.err.println("no corrections: " + rule.getId() + ", " + matches.size() + " matches");
        if (matches.size() == 0) {
            throw new RuntimeException("Got no rule match: " + incorrectSentence);
        }
        List<String> suggestedReplacements = matches.get(0).getSuggestedReplacements();
        String newAttribute = "correction=\"" + String.join("|", suggestedReplacements) + "\"";
        addAttribute(rule, newAttribute, xmlLines);
    }
}
Also used : RuleMatch(org.languagetool.rules.RuleMatch) Rule(org.languagetool.rules.Rule) PatternRule(org.languagetool.rules.patterns.PatternRule) AbstractPatternRule(org.languagetool.rules.patterns.AbstractPatternRule)

Example 67 with Rule

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

the class SimpleRuleCounter method countForLanguage.

private void countForLanguage(List<Rule> allRules, Language language) {
    int simpleCount = 0;
    for (Rule rule : allRules) {
        boolean isSimple = true;
        if (rule instanceof PatternRule) {
            PatternRule patternRule = (PatternRule) rule;
            List<PatternToken> tokens = patternRule.getPatternTokens();
            for (PatternToken token : tokens) {
                if (!isSimple(token)) {
                    isSimple = false;
                    break;
                }
            }
            if (isSimple) {
                simpleCount++;
            //System.out.println("Simple: " + patternRule.getId());
            //System.out.println(patternRule.toXML());
            //System.out.println("-------------------------");
            }
        }
    }
    float percent = (float) simpleCount / allRules.size() * 100;
    //System.out.printf(simpleCount + "/" + allRules.size() + " = %.0f%% for " + language + "\n", percent);
    System.out.printf("%.0f%% for " + language + "\n", percent);
}
Also used : PatternToken(org.languagetool.rules.patterns.PatternToken) PatternRule(org.languagetool.rules.patterns.PatternRule) Rule(org.languagetool.rules.Rule) PatternRule(org.languagetool.rules.patterns.PatternRule)

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