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);
}
use of org.languagetool.rules.Rule in project languagetool by languagetool-org.
the class SpellIgnoreTest method testIgnore.
// code also used in http://wiki.languagetool.org/java-api
@Test
public void testIgnore() throws IOException {
String text = "This is a text with specialword and myotherword";
JLanguageTool lt = new JLanguageTool(new AmericanEnglish());
assertThat(lt.check(text).size(), is(2));
for (Rule rule : lt.getAllActiveRules()) {
if (rule instanceof SpellingCheckRule) {
List<String> wordsToIgnore = Arrays.asList("specialword", "myotherword");
((SpellingCheckRule) rule).addIgnoreTokens(wordsToIgnore);
}
}
assertThat(lt.check(text).size(), is(0));
}
use of org.languagetool.rules.Rule in project languagetool by languagetool-org.
the class MorfologikBritishSpellerRuleTest method testSuggestions.
@Test
public void testSuggestions() throws IOException {
Language language = new BritishEnglish();
Rule rule = new MorfologikBritishSpellerRule(TestTools.getMessages("en"), language);
super.testNonVariantSpecificSuggestions(rule, language);
}
use of org.languagetool.rules.Rule in project languagetool by languagetool-org.
the class MorfologikCanadianSpellerRuleTest method testSuggestions.
@Test
public void testSuggestions() throws IOException {
Language language = new CanadianEnglish();
Rule rule = new MorfologikCanadianSpellerRule(TestTools.getMessages("en"), language);
super.testNonVariantSpecificSuggestions(rule, language);
}
use of org.languagetool.rules.Rule in project languagetool by languagetool-org.
the class MorfologikSouthAfricanSpellerRuleTest method testSuggestions.
@Test
public void testSuggestions() throws IOException {
Language language = new SouthAfricanEnglish();
Rule rule = new MorfologikSouthAfricanSpellerRule(TestTools.getMessages("en"), language);
super.testNonVariantSpecificSuggestions(rule, language);
}
Aggregations