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);
}
}
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);
}
Aggregations