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")));
}
use of org.languagetool.Language in project languagetool by languagetool-org.
the class PatternRuleTest method runGrammarRulesFromXmlTest.
/**
* To be called from language modules. Languages.get() knows only the languages that's in the classpath.
* @param ignoredLanguage ignore this language - useful to speed up tests from languages that
* have another language as a dependency
*/
protected void runGrammarRulesFromXmlTest(Language ignoredLanguage) throws IOException {
int count = 0;
for (Language lang : Languages.get()) {
if (ignoredLanguage.getShortCodeWithCountryAndVariant().equals(lang.getShortCodeWithCountryAndVariant())) {
continue;
}
runGrammarRuleForLanguage(lang);
count++;
}
if (count == 0) {
System.err.println("Warning: no languages found in classpath - cannot run any grammar rule tests");
}
}
use of org.languagetool.Language in project languagetool by languagetool-org.
the class MorfologikAmericanSpellerRuleTest method testSuggestions.
@Test
public void testSuggestions() throws IOException {
Language language = new AmericanEnglish();
Rule rule = new MorfologikAmericanSpellerRule(TestTools.getMessages("en"), language);
super.testNonVariantSpecificSuggestions(rule, language);
}
Aggregations