Search in sources :

Example 56 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)

Example 57 with Rule

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));
}
Also used : SpellingCheckRule(org.languagetool.rules.spelling.SpellingCheckRule) AmericanEnglish(org.languagetool.language.AmericanEnglish) SpellingCheckRule(org.languagetool.rules.spelling.SpellingCheckRule) Rule(org.languagetool.rules.Rule) Test(org.junit.Test)

Example 58 with Rule

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);
}
Also used : BritishEnglish(org.languagetool.language.BritishEnglish) Language(org.languagetool.Language) Rule(org.languagetool.rules.Rule) Test(org.junit.Test)

Example 59 with Rule

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);
}
Also used : Language(org.languagetool.Language) CanadianEnglish(org.languagetool.language.CanadianEnglish) Rule(org.languagetool.rules.Rule) Test(org.junit.Test)

Example 60 with Rule

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);
}
Also used : Language(org.languagetool.Language) SouthAfricanEnglish(org.languagetool.language.SouthAfricanEnglish) Rule(org.languagetool.rules.Rule) Test(org.junit.Test)

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