Search in sources :

Example 81 with Language

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

the class AbstractLanguageConcurrencyTest method testSpellCheckerFailure.

@Ignore("too slow to run every time")
@Test
public void testSpellCheckerFailure() throws Exception {
    String sampleText = createSampleText();
    Language language = createLanguage();
    int threadCount = Runtime.getRuntime().availableProcessors() * 10;
    int testRuns = 100;
    ReadWriteLock testWaitLock = new ReentrantReadWriteLock();
    Lock testWriteLock = testWaitLock.writeLock();
    testWriteLock.lock();
    failedTests = 0;
    List<Thread> threads = new ArrayList<>();
    for (int i = 0; i < threadCount; i++) {
        Thread t = new Thread(new TestRunner(testWaitLock, language, testRuns, sampleText));
        t.start();
        threads.add(t);
    }
    // Release the lock and allow all TestRunner threads to do their work.
    testWriteLock.unlock();
    for (Thread t : threads) {
        t.join();
    }
    Assert.assertEquals(0, failedTests);
}
Also used : Language(org.languagetool.Language) ReentrantReadWriteLock(java.util.concurrent.locks.ReentrantReadWriteLock) ReadWriteLock(java.util.concurrent.locks.ReadWriteLock) ArrayList(java.util.ArrayList) ReentrantReadWriteLock(java.util.concurrent.locks.ReentrantReadWriteLock) Lock(java.util.concurrent.locks.Lock) ReentrantReadWriteLock(java.util.concurrent.locks.ReentrantReadWriteLock) ReadWriteLock(java.util.concurrent.locks.ReadWriteLock) Ignore(org.junit.Ignore) Test(org.junit.Test)

Example 82 with Language

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

the class LanguageBuilderTest method testMakeAdditionalLanguage.

@Test
public void testMakeAdditionalLanguage() throws Exception {
    Language language = LanguageBuilder.makeAdditionalLanguage(new File("rules-xy-Fakelanguage.xml"));
    assertEquals("Fakelanguage", language.getName());
    assertEquals("xy", language.getShortCode());
    assertEquals(0, language.getRelevantRules(JLanguageTool.getMessageBundle()).size());
    assertTrue(language.isExternal());
}
Also used : Language(org.languagetool.Language) File(java.io.File) Test(org.junit.Test)

Example 83 with Language

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

the class MatchDatabaseTest method test.

@Test
public void test() throws SQLException, ClassNotFoundException {
    Language language = Languages.getLanguageForShortCode("de");
    MatchDatabase database = new MatchDatabase("jdbc:derby:atomFeedChecksDB;create=true", "user", "pass");
    database.dropTables();
    database.createTables();
    assertThat(database.getLatestDate(language), is(new Date(0)));
    assertThat(database.list().size(), is(0));
    assertThat(database.getCheckDates().size(), is(0));
    FakeRule rule1 = new FakeRule(1);
    rule1.setCategory(new Category(new CategoryId("TEST_ID"), "My Category"));
    RuleMatch ruleMatch = new RuleMatch(rule1, 5, 10, "my message");
    AtomFeedItem feedItem1 = new AtomFeedItem("//id1?diff=123", "title", "summary1", new Date(10000));
    WikipediaRuleMatch wikiRuleMatch1 = new WikipediaRuleMatch(language, ruleMatch, "my context", feedItem1);
    database.add(wikiRuleMatch1);
    assertThat(database.list().size(), is(1));
    assertThat(database.list().get(0).getRuleId(), is("ID_1"));
    assertThat(database.list().get(0).getRuleDescription(), is("A fake rule"));
    assertThat(database.list().get(0).getRuleMessage(), is("my message"));
    assertThat(database.list().get(0).getTitle(), is("title"));
    assertThat(database.list().get(0).getErrorContext(), is("my context"));
    assertThat(database.list().get(0).getDiffId(), is(123L));
    assertThat(database.list().get(0).getFixDiffId(), is(0L));
    assertThat(database.list().get(0).getEditDate(), is(new Date(10000)));
    assertThat(database.getLatestDate(language), is(new Date(0)));
    assertNull(database.list().get(0).getRuleSubId());
    assertNull(database.list().get(0).getFixDate());
    assertThat(database.getCheckDates().size(), is(0));
    // same ID, different character positions
    RuleMatch ruleMatch2 = new RuleMatch(new FakeRule(1), 9, 11, "my message");
    AtomFeedItem feedItem2 = new AtomFeedItem("//id2?diff=124", "title", "summary2", new Date(9000000000L));
    WikipediaRuleMatch wikiRuleMatch2 = new WikipediaRuleMatch(language, ruleMatch2, "my context", feedItem2);
    int affected = database.markedFixed(wikiRuleMatch2);
    assertThat(affected, is(1));
    assertThat(database.list().get(0).getFixDate(), is(new Date(9000000000L)));
    assertThat(database.list().get(0).getDiffId(), is(123L));
    assertThat(database.list().get(0).getFixDiffId(), is(124L));
    assertThat(database.getLatestDate(language), is(new Date(0)));
    assertThat(database.getCheckDates().size(), is(0));
}
Also used : CategoryId(org.languagetool.rules.CategoryId) Category(org.languagetool.rules.Category) RuleMatch(org.languagetool.rules.RuleMatch) Language(org.languagetool.Language) Date(java.util.Date) Test(org.junit.Test)

Example 84 with Language

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

the class HunspellRuleTest method testPerformance.

@Ignore("just for internal performance testing, thus ignored by default")
@Test
public void testPerformance() throws Exception {
    List<Language> allLanguages = Languages.get();
    for (Language language : allLanguages) {
        JLanguageTool langTool = new JLanguageTool(language);
        //HunspellRule rule = new HunspellRule(TestTools.getMessages("German"), language);
        // make sure everything is initialized when actually testing
        langTool.check("warmup");
        langTool.check("anotherwarmup");
        long startTime = System.currentTimeMillis();
        langTool.check("fdfds fdfdsa fdfdsb fdfdsc fdfdsd fdfdse fdfdsf fdfds fdfdsa fdfdsb fdfdsc fdfdsd fdfdse fdfdsf");
        //String[] w = {"foo", "warmup", "Rechtschreipreform", "Theatrekasse", "Zoobesuck", "Handselvertreter", "Mückenstick", "gewönlich", "Traprennen", "Autoverkehrr"};
        //AnalyzedSentence analyzedSentence = langTool.getAnalyzedSentence("fdfds fdfdsa fdfdsb fdfdsc fdfdsd fdfdse fdfdsf");
        //rule.match(analyzedSentence);
        long endTime = System.currentTimeMillis();
        System.out.println((endTime - startTime) + "ms for " + language);
    }
}
Also used : Language(org.languagetool.Language) JLanguageTool(org.languagetool.JLanguageTool) Ignore(org.junit.Ignore) 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