Search in sources :

Example 21 with Language

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

the class HTTPServerMultiLangLoadTest2 method testHTTPServer.

@Test
@Override
public void testHTTPServer() throws Exception {
    File dir = new File(DATA_PATH);
    List<Language> languages = new ArrayList<>();
    //languages.add(new German());
    languages.addAll(Languages.get());
    for (Language language : languages) {
        File file = new File(dir, "tatoeba-" + language.getShortCode() + ".txt");
        if (!file.exists()) {
            System.err.println("No data found for " + language + ", language will not be tested");
        } else {
            String content = StringTools.readerToString(new FileReader(file));
            int fromPos = random.nextInt(content.length());
            int toPos = fromPos + random.nextInt(MAX_TEXT_LENGTH) + MIN_TEXT_LENGTH;
            String textSubstring = content.substring(fromPos, Math.min(toPos, content.length()));
            langCodeToText.put(language, textSubstring);
            String response = checkByPOST(language, textSubstring);
            textToResult.put(language, response);
            System.err.println("Using " + content.length() + " bytes of data for " + language);
        }
    }
    if (langCodeToText.size() == 0) {
        throw new RuntimeException("No input data found in " + dir);
    }
    System.out.println("Testing " + langCodeToText.keySet().size() + " languages and variants");
    //super.testHTTPServer();  // start server in this JVM
    // assume server has been started manually in its own JVM
    super.doTest();
}
Also used : Language(org.languagetool.Language) FileReader(java.io.FileReader) File(java.io.File) Test(org.junit.Test)

Example 22 with Language

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

the class SRXSentenceTokenizerTest method testOfficeFootnoteTokenize.

@Test
public void testOfficeFootnoteTokenize() {
    int count = 0;
    for (Language language : Languages.get()) {
        if (language.getSentenceTokenizer().getClass() != SRXSentenceTokenizer.class) {
            continue;
        }
        if (language.getShortCode().equals("km") || language.getShortCode().equals("ml")) {
            // TODO: I don't know about these...
            continue;
        }
        String input = "A sentence. And another one.";
        SentenceTokenizer tokenizer = new SRXSentenceTokenizer(language);
        assertEquals("Sentence not split correctly for " + language + ": '" + input + "'", "[A sentence. , And another one.]", tokenizer.tokenize(input).toString());
        count++;
    }
    if (count == 0) {
        fail("No languages found for testing");
    }
}
Also used : Language(org.languagetool.Language) Test(org.junit.Test)

Example 23 with Language

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

the class PerformanceTest2 method run.

private void run(String languageCode, File textFile) throws IOException {
    String text = StringTools.readStream(new FileInputStream(textFile), "utf-8");
    System.out.println("Text length: " + text.length());
    Random rnd = new Random(42);
    Language language = Languages.getLanguageForShortCode(languageCode);
    long totalTime = 0;
    for (int i = 0; i < RUNS; i++) {
        int beginIndex = rnd.nextInt(text.length());
        int endIndex = Math.min(beginIndex + MAX_TEXT_LENGTH, text.length() - 1);
        String subText = text.substring(beginIndex, endIndex);
        long startTime = System.currentTimeMillis();
        MultiThreadedJLanguageTool langTool = new MultiThreadedJLanguageTool(language);
        List<RuleMatch> matches = langTool.check(subText);
        long runTime = System.currentTimeMillis() - startTime;
        langTool.shutdown();
        if (i >= SKIP) {
            totalTime += runTime;
            System.out.println("Time: " + runTime + "ms (" + matches.size() + " matches)");
        } else {
            System.out.println("Time: " + runTime + "ms (" + matches.size() + " matches) - skipped because of warm-up");
        }
    }
    System.out.println("Avg. Time: " + (float) totalTime / RUNS);
}
Also used : RuleMatch(org.languagetool.rules.RuleMatch) Random(java.util.Random) Language(org.languagetool.Language) MultiThreadedJLanguageTool(org.languagetool.MultiThreadedJLanguageTool) FileInputStream(java.io.FileInputStream)

Example 24 with Language

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

the class RuleLinkTest method testBuildReactivationLink.

@Test
public void testBuildReactivationLink() {
    Language language = new English();
    RuleLink ruleLink = RuleLink.buildReactivationLink(new WordRepeatRule(TestTools.getMessages(language.getShortCode()), language));
    assertEquals("WORD_REPEAT_RULE", ruleLink.getId());
    assertEquals("http://languagetool.org/reactivate/WORD_REPEAT_RULE", ruleLink.toString());
}
Also used : English(org.languagetool.language.English) Language(org.languagetool.Language) WordRepeatRule(org.languagetool.rules.WordRepeatRule) Test(org.junit.Test)

Example 25 with Language

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

the class RuleTest method testJavaRules.

@Test
public void testJavaRules() throws IOException {
    Set<String> ids = new HashSet<>();
    Set<Class> ruleClasses = new HashSet<>();
    if (Languages.getWithDemoLanguage().size() <= 1) {
        System.err.println("***************************************************************************");
        System.err.println("WARNING: found only these languages - the tests might not be complete:");
        System.err.println(Languages.getWithDemoLanguage());
        System.err.println("***************************************************************************");
    }
    for (Language language : Languages.getWithDemoLanguage()) {
        JLanguageTool lt = new JLanguageTool(language);
        List<Rule> allRules = lt.getAllRules();
        for (Rule rule : allRules) {
            if (!(rule instanceof AbstractPatternRule)) {
                assertIdUniqueness(ids, ruleClasses, language, rule);
                assertIdValidity(language, rule);
                assertTrue(rule.supportsLanguage(language));
                testExamples(rule, lt);
            }
        }
    }
}
Also used : Language(org.languagetool.Language) JLanguageTool(org.languagetool.JLanguageTool) AbstractPatternRule(org.languagetool.rules.patterns.AbstractPatternRule) HashSet(java.util.HashSet) AbstractPatternRule(org.languagetool.rules.patterns.AbstractPatternRule) 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