use of org.languagetool.JLanguageTool in project languagetool by languagetool-org.
the class Searcher method getRuleById.
List<PatternRule> getRuleById(String ruleId, Language language) throws IOException {
List<PatternRule> rules = new ArrayList<>();
JLanguageTool langTool = new JLanguageTool(language);
for (Rule rule : langTool.getAllRules()) {
if (rule.getId().equals(ruleId) && rule instanceof PatternRule) {
rules.add((PatternRule) rule);
}
}
if (rules.size() > 0) {
return rules;
} else {
throw new PatternRuleNotFoundException(ruleId, language);
}
}
use of org.languagetool.JLanguageTool in project languagetool by languagetool-org.
the class ToolsTest method testBitextCheck.
private void testBitextCheck(ResultCache cache) throws IOException, ParserConfigurationException, SAXException {
Language english = Languages.getLanguageForShortCode("en");
JLanguageTool srcTool = new JLanguageTool(english, null, cache);
Language polish = Languages.getLanguageForShortCode("pl");
JLanguageTool trgTool = new JLanguageTool(polish, null, cache);
List<BitextRule> rules = Tools.getBitextRules(english, polish);
int matchCount = Tools.checkBitext("This is a perfectly good sentence.", "To jest całkowicie prawidłowe zdanie.", srcTool, trgTool, rules).size();
assertEquals(0, matchCount);
List<RuleMatch> matches1 = Tools.checkBitext("This is not actual.", "To nie jest aktualne.", srcTool, trgTool, rules);
assertEquals(1, matches1.size());
assertThat(matches1.get(0).getRule().getId(), is("ACTUAL"));
assertThat(matches1.get(0).getFromPos(), is(12));
assertThat(matches1.get(0).getToPos(), is(20));
List<RuleMatch> matches2 = Tools.checkBitext("A sentence. This is not actual.", "Zdanie. To nie jest aktualne.", srcTool, trgTool, rules);
assertEquals(1, matches2.size());
assertThat(matches2.get(0).getRule().getId(), is("ACTUAL"));
assertThat(matches2.get(0).getFromPos(), is(20));
assertThat(matches2.get(0).getToPos(), is(28));
List<RuleMatch> matches3 = Tools.checkBitext("A new sentence. This is not actual.", "Nowa zdanie. To nie jest aktualne.", srcTool, trgTool, rules);
assertEquals(1, matches3.size());
assertThat(matches3.get(0).getRule().getId(), is("ACTUAL"));
assertThat(matches3.get(0).getFromPos(), is(25));
assertThat(matches3.get(0).getToPos(), is(33));
}
use of org.languagetool.JLanguageTool in project languagetool by languagetool-org.
the class FalseFriendRuleTest method testHintsForDemoLanguage.
@Test
public void testHintsForDemoLanguage() throws IOException, ParserConfigurationException, SAXException {
JLanguageTool langTool1 = new JLanguageTool(new BritishEnglish(), new German());
langTool1.disableRule(MorfologikBritishSpellerRule.RULE_ID);
List<RuleMatch> matches1 = assertErrors(1, "And forDemoOnly.", langTool1);
assertEquals("DEMO_ENTRY", matches1.get(0).getRule().getId());
JLanguageTool langTool2 = new JLanguageTool(new English(), new German());
langTool2.disableRule(MorfologikBritishSpellerRule.RULE_ID);
List<RuleMatch> matches2 = assertErrors(1, "And forDemoOnly.", langTool2);
assertEquals("DEMO_ENTRY", matches2.get(0).getRule().getId());
JLanguageTool langTool3 = new JLanguageTool(new AmericanEnglish(), new German());
langTool3.disableRule(MorfologikAmericanSpellerRule.RULE_ID);
assertErrors(0, "And forDemoOnly.", langTool3);
}
use of org.languagetool.JLanguageTool in project languagetool by languagetool-org.
the class FalseFriendRuleTest method testHintsForGermanSpeakersWithVariant.
@Test
public void testHintsForGermanSpeakersWithVariant() throws IOException, ParserConfigurationException, SAXException {
JLanguageTool langTool = new JLanguageTool(new BritishEnglish(), new SwissGerman());
List<RuleMatch> matches = assertErrors(1, "We will berate you.", langTool);
assertEquals(matches.get(0).getSuggestedReplacements().toString(), "[provide advice, give advice]");
assertErrors(0, "We will give you advice.", langTool);
assertErrors(1, "I go to high school in Berlin.", langTool);
List<RuleMatch> matches2 = assertErrors(1, "The chef", langTool);
assertEquals("[boss, chief]", matches2.get(0).getSuggestedReplacements().toString());
}
use of org.languagetool.JLanguageTool in project languagetool by languagetool-org.
the class FalseFriendRuleTest method testHintsForPolishSpeakers.
@Test
public void testHintsForPolishSpeakers() throws IOException, ParserConfigurationException, SAXException {
JLanguageTool langTool = new JLanguageTool(new English() {
@Override
protected synchronized List<AbstractPatternRule> getPatternRules() {
return Collections.emptyList();
}
}, new Polish());
assertErrors(1, "This is an absurd.", langTool);
assertErrors(0, "This is absurdity.", langTool);
assertSuggestions(0, "This is absurdity.", langTool);
assertErrors(1, "I have to speak to my advocate.", langTool);
assertSuggestions(3, "My brother is politic.", langTool);
}
Aggregations