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