Search in sources :

Example 1 with Language

use of org.languagetool.Language in project languagetool by languagetool-org.

the class DisambiguationRuleTest method testDisambiguationRulesFromXML.

private void testDisambiguationRulesFromXML(Set<Language> ignoredLanguages) throws IOException, ParserConfigurationException, SAXException {
    for (Language lang : Languages.getWithDemoLanguage()) {
        if (ignoredLanguages != null && ignoredLanguages.contains(lang)) {
            continue;
        }
        if (lang.isVariant()) {
            System.out.println("Skipping variant: " + lang);
            continue;
        }
        System.out.println("Running disambiguation tests for " + lang.getName() + "...");
        DisambiguationRuleLoader ruleLoader = new DisambiguationRuleLoader();
        JLanguageTool languageTool = new JLanguageTool(lang);
        if (!(languageTool.getLanguage().getDisambiguator() instanceof DemoDisambiguator)) {
            long startTime = System.currentTimeMillis();
            String name = JLanguageTool.getDataBroker().getResourceDir() + "/" + lang.getShortCode() + "/disambiguation.xml";
            validateRuleFile(name);
            List<DisambiguationPatternRule> rules = ruleLoader.getRules(ruleLoader.getClass().getResourceAsStream(name));
            for (DisambiguationPatternRule rule : rules) {
                PatternTestTools.warnIfRegexpSyntaxNotKosher(rule.getPatternTokens(), rule.getId(), rule.getSubId(), lang);
            }
            testDisambiguationRulesFromXML(rules, languageTool, lang);
            long endTime = System.currentTimeMillis();
            System.out.println(rules.size() + " rules tested (" + (endTime - startTime) + "ms)");
        }
    }
}
Also used : DemoDisambiguator(org.languagetool.tagging.disambiguation.xx.DemoDisambiguator) Language(org.languagetool.Language) JLanguageTool(org.languagetool.JLanguageTool)

Example 2 with Language

use of org.languagetool.Language in project languagetool by languagetool-org.

the class RuleOverview method getVariantNames.

private List<String> getVariantNames(List<Language> allLanguages, Language lang) {
    List<Language> variants = getVariants(allLanguages, lang);
    List<String> result = new ArrayList<>();
    for (Language l : variants) {
        result.add(l.getName().replaceAll(".*\\((.*?)\\).*", "$1").trim());
    }
    return result;
}
Also used : Language(org.languagetool.Language)

Example 3 with Language

use of org.languagetool.Language in project languagetool by languagetool-org.

the class StringToolsTest method testAddSpace.

@Test
public void testAddSpace() {
    Language demoLanguage = TestTools.getDemoLanguage();
    assertEquals(" ", StringTools.addSpace("word", demoLanguage));
    assertEquals("", StringTools.addSpace(",", demoLanguage));
    assertEquals("", StringTools.addSpace(",", demoLanguage));
    assertEquals("", StringTools.addSpace(",", demoLanguage));
    assertEquals("", StringTools.addSpace(".", new FakeLanguage("fr")));
    assertEquals("", StringTools.addSpace(".", new FakeLanguage("de")));
    assertEquals(" ", StringTools.addSpace("!", new FakeLanguage("fr")));
    assertEquals("", StringTools.addSpace("!", new FakeLanguage("de")));
}
Also used : FakeLanguage(org.languagetool.FakeLanguage) Language(org.languagetool.Language) FakeLanguage(org.languagetool.FakeLanguage) Test(org.junit.Test)

Example 4 with Language

use of org.languagetool.Language in project languagetool by languagetool-org.

the class PatternRuleTest method runGrammarRulesFromXmlTest.

/**
   * To be called from language modules. Languages.get() knows only the languages that's in the classpath.
   * @param ignoredLanguage ignore this language - useful to speed up tests from languages that 
   *                        have another language as a dependency
   */
protected void runGrammarRulesFromXmlTest(Language ignoredLanguage) throws IOException {
    int count = 0;
    for (Language lang : Languages.get()) {
        if (ignoredLanguage.getShortCodeWithCountryAndVariant().equals(lang.getShortCodeWithCountryAndVariant())) {
            continue;
        }
        runGrammarRuleForLanguage(lang);
        count++;
    }
    if (count == 0) {
        System.err.println("Warning: no languages found in classpath - cannot run any grammar rule tests");
    }
}
Also used : FakeLanguage(org.languagetool.FakeLanguage) Language(org.languagetool.Language)

Example 5 with Language

use of org.languagetool.Language in project languagetool by languagetool-org.

the class MorfologikAmericanSpellerRuleTest method testSuggestions.

@Test
public void testSuggestions() throws IOException {
    Language language = new AmericanEnglish();
    Rule rule = new MorfologikAmericanSpellerRule(TestTools.getMessages("en"), language);
    super.testNonVariantSpecificSuggestions(rule, language);
}
Also used : Language(org.languagetool.Language) AmericanEnglish(org.languagetool.language.AmericanEnglish) Rule(org.languagetool.rules.Rule) Test(org.junit.Test)

Aggregations

Language (org.languagetool.Language)84 Test (org.junit.Test)23 File (java.io.File)15 ArrayList (java.util.ArrayList)12 JLanguageTool (org.languagetool.JLanguageTool)11 Rule (org.languagetool.rules.Rule)11 RuleMatch (org.languagetool.rules.RuleMatch)10 IOException (java.io.IOException)7 Ignore (org.junit.Ignore)6 StringTools.readerToString (org.languagetool.tools.StringTools.readerToString)5 InputStream (java.io.InputStream)4 English (org.languagetool.language.English)4 BitextRule (org.languagetool.rules.bitext.BitextRule)4 URL (java.net.URL)3 HashSet (java.util.HashSet)3 MultiThreadedJLanguageTool (org.languagetool.MultiThreadedJLanguageTool)3 AmericanEnglish (org.languagetool.language.AmericanEnglish)3 LanguageModel (org.languagetool.languagemodel.LanguageModel)3 LuceneLanguageModel (org.languagetool.languagemodel.LuceneLanguageModel)3 BufferedReader (java.io.BufferedReader)2