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