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);
}
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());
}
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));
}
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);
}
}
Aggregations