use of org.languagetool.rules.patterns.PatternRule 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);
}
use of org.languagetool.rules.patterns.PatternRule in project languagetool by languagetool-org.
the class DashRule method loadCompoundFile.
private void loadCompoundFile(String path) throws IOException {
try (InputStream stream = JLanguageTool.getDataBroker().getFromResourceDirAsStream(path);
InputStreamReader reader = new InputStreamReader(stream, "utf-8");
BufferedReader br = new BufferedReader(reader)) {
String line;
int counter = 0;
while ((line = br.readLine()) != null) {
counter++;
if (line.isEmpty() || line.charAt(0) == '#') {
// ignore comments
continue;
}
if (line.endsWith("+")) {
// skip non-hyphenated suggestions
continue;
} else if (line.endsWith("*")) {
line = removeLastCharacter(line);
}
List<PatternToken> tokList = new ArrayList<PatternToken>();
String[] tokens = line.split("-");
int tokenCounter = 0;
for (String token : tokens) {
tokenCounter++;
// token
tokList.add(new PatternToken(token, true, false, false));
if (tokenCounter < tokens.length) {
// add dash
tokList.add(new PatternToken("[—–]", false, true, false));
}
}
PatternRule dashRule = new PatternRule("DASH_RULE" + counter, Languages.getLanguageForName("Polish"), tokList, "", "Błędne użycie myślnika zamiast myślnika. " + "Poprawnie: <suggestion>" + line.replaceAll("[–—]", "-") + "</suggestion>.", line.replaceAll("[–—]", "-"));
dashRules.add(dashRule);
}
}
}
use of org.languagetool.rules.patterns.PatternRule in project languagetool by languagetool-org.
the class RuleWithMaxFilterTest method testNoFilteringIfNotOverlapping.
@Test
public void testNoFilteringIfNotOverlapping() {
List<PatternToken> fakePatternTokens = new ArrayList<>();
PatternRule rule1 = new PatternRule("id1", language, fakePatternTokens, "desc1", "msg1", "shortMsg1");
PatternRule rule2 = new PatternRule("id1", language, fakePatternTokens, "desc2", "msg2", "shortMsg2");
RuleMatch match1 = new RuleMatch(rule1, 10, 20, "Match1");
RuleMatch match2 = new RuleMatch(rule2, 21, 25, "Match2");
RuleWithMaxFilter filter = new RuleWithMaxFilter();
List<RuleMatch> filteredMatches = filter.filter(Arrays.asList(match1, match2));
assertEquals(2, filteredMatches.size());
}
Aggregations