Search in sources :

Example 96 with JLanguageTool

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);
    }
}
Also used : PatternRule(org.languagetool.rules.patterns.PatternRule) JLanguageTool(org.languagetool.JLanguageTool) ArrayList(java.util.ArrayList) PatternRule(org.languagetool.rules.patterns.PatternRule) Rule(org.languagetool.rules.Rule)

Example 97 with JLanguageTool

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));
}
Also used : RuleMatch(org.languagetool.rules.RuleMatch) Language(org.languagetool.Language) JLanguageTool(org.languagetool.JLanguageTool) BitextRule(org.languagetool.rules.bitext.BitextRule)

Example 98 with JLanguageTool

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);
}
Also used : RuleMatch(org.languagetool.rules.RuleMatch) JLanguageTool(org.languagetool.JLanguageTool) Test(org.junit.Test)

Example 99 with JLanguageTool

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());
}
Also used : RuleMatch(org.languagetool.rules.RuleMatch) JLanguageTool(org.languagetool.JLanguageTool) Test(org.junit.Test)

Example 100 with JLanguageTool

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);
}
Also used : JLanguageTool(org.languagetool.JLanguageTool) List(java.util.List) Test(org.junit.Test)

Aggregations

JLanguageTool (org.languagetool.JLanguageTool)184 Test (org.junit.Test)109 RuleMatch (org.languagetool.rules.RuleMatch)57 Before (org.junit.Before)38 German (org.languagetool.language.German)16 Rule (org.languagetool.rules.Rule)16 Catalan (org.languagetool.language.Catalan)14 Ukrainian (org.languagetool.language.Ukrainian)14 English (org.languagetool.language.English)13 Polish (org.languagetool.language.Polish)12 Language (org.languagetool.Language)10 GermanyGerman (org.languagetool.language.GermanyGerman)9 PatternRule (org.languagetool.rules.patterns.PatternRule)9 AnalyzedSentence (org.languagetool.AnalyzedSentence)8 File (java.io.File)7 AnalyzedTokenReadings (org.languagetool.AnalyzedTokenReadings)6 Dutch (org.languagetool.language.Dutch)5 French (org.languagetool.language.French)5 ArrayList (java.util.ArrayList)4 FakeLanguage (org.languagetool.FakeLanguage)4