Search in sources :

Example 26 with Language

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

the class WordListValidatorTest method testWordListValidity.

@Test
public void testWordListValidity() throws IOException {
    Set<String> checked = new HashSet<>();
    for (Language lang : Languages.get()) {
        if (lang.getShortCode().equals("ru")) {
            // skipping, Cyrillic chars not part of the validation yet
            continue;
        }
        JLanguageTool lt = new JLanguageTool(lang);
        List<Rule> rules = lt.getAllActiveRules();
        for (Rule rule : rules) {
            if (rule instanceof SpellingCheckRule) {
                SpellingCheckRule sRule = (SpellingCheckRule) rule;
                String file = sRule.getSpellingFileName();
                if (JLanguageTool.getDataBroker().resourceExists(file) && !checked.contains(file)) {
                    System.out.println("Checking " + file);
                    CachingWordListLoader loader = new CachingWordListLoader();
                    List<String> words = loader.loadWords(file);
                    validateWords(words, file);
                    checked.add(file);
                }
            }
        }
    }
}
Also used : Language(org.languagetool.Language) SpellingCheckRule(org.languagetool.rules.spelling.SpellingCheckRule) JLanguageTool(org.languagetool.JLanguageTool) SpellingCheckRule(org.languagetool.rules.spelling.SpellingCheckRule) CachingWordListLoader(org.languagetool.rules.spelling.CachingWordListLoader) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 27 with Language

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

the class MultiThreadingTest1 method test.

@Test
@Ignore("for interactive use only")
public void test() throws Exception {
    List<Language> languages1 = new ArrayList<>(Languages.get());
    initExpectedResults(languages1);
    List<Language> languages2 = new ArrayList<>(Languages.get());
    ExecutorService executor = Executors.newFixedThreadPool(THREADS);
    for (int i = 0; i < RUNS; i++) {
        System.out.println("Run #" + i);
        Collections.shuffle(languages1, rnd);
        Collections.shuffle(languages2, rnd);
        List<Future> futures = new ArrayList<>();
        for (int j = 0; j < languages1.size(); j++) {
            Language lang1 = languages1.get(j);
            Language lang2 = languages2.get(j);
            //System.out.println("Checking " + lang1 + " and " + lang2);
            futures.add(executor.submit(new Handler(lang1)));
            futures.add(executor.submit(new Handler(lang2)));
        }
        for (Future future : futures) {
            // wait for all results or exception
            future.get();
        }
    }
}
Also used : Language(org.languagetool.Language) ExecutorService(java.util.concurrent.ExecutorService) Future(java.util.concurrent.Future) Ignore(org.junit.Ignore) Test(org.junit.Test)

Example 28 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 29 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 30 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)

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