Search in sources :

Example 66 with JLanguageTool

use of org.languagetool.JLanguageTool in project languagetool by languagetool-org.

the class MorfologikTagalogSpellerRuleTest method testMorfologikSpeller.

@Test
public void testMorfologikSpeller() throws IOException {
    Tagalog language = new Tagalog();
    MorfologikTagalogSpellerRule rule = new MorfologikTagalogSpellerRule(TestTools.getMessages("en"), language);
    JLanguageTool langTool = new JLanguageTool(language);
    assertEquals(0, rule.match(langTool.getAnalyzedSentence("Ang talatang ito ay nagpapakita ng ng kakayahan ng LanguageTool at halimbawa kung paano ito gamitin.")).length);
    RuleMatch[] matches = rule.match(langTool.getAnalyzedSentence("Ang talatang ito ay nagpapakita ng ng kakayahan ng LanguageTool at hinahalimbawa kung paano ito gamitin."));
    assertEquals(1, matches.length);
    assertEquals(67, matches[0].getFromPos());
    assertEquals(80, matches[0].getToPos());
    assertEquals("hina halimbawa", matches[0].getSuggestedReplacements().get(0));
}
Also used : RuleMatch(org.languagetool.rules.RuleMatch) JLanguageTool(org.languagetool.JLanguageTool) Tagalog(org.languagetool.language.Tagalog) Test(org.junit.Test)

Example 67 with JLanguageTool

use of org.languagetool.JLanguageTool in project languagetool by languagetool-org.

the class ConfigThread method run.

@Override
public void run() {
    try {
        JLanguageTool langTool = new JLanguageTool(docLanguage, config.getMotherTongue());
        cfgDialog.show(langTool.getAllRules());
        config.saveConfiguration(docLanguage);
        if (mainThread != null) {
            mainThread.resetDocument();
        }
    } catch (Throwable e) {
        Main.showError(e);
    }
}
Also used : JLanguageTool(org.languagetool.JLanguageTool)

Example 68 with JLanguageTool

use of org.languagetool.JLanguageTool in project languagetool by languagetool-org.

the class SimpleReplaceRuleTest method testRule.

@Test
public void testRule() throws IOException {
    SimpleReplaceRule rule = new SimpleReplaceRule(TestTools.getEnglishMessages());
    RuleMatch[] matches;
    JLanguageTool langTool = new JLanguageTool(new Ukrainian());
    // correct sentences:
    matches = rule.match(langTool.getAnalyzedSentence("Ці рядки повинні збігатися."));
    assertEquals(0, matches.length);
    // incorrect sentences:
    matches = rule.match(langTool.getAnalyzedSentence("Ці рядки повинні співпадати."));
    assertEquals(1, matches.length);
    assertEquals(2, matches[0].getSuggestedReplacements().size());
    assertEquals(Arrays.asList("збігатися", "сходитися"), matches[0].getSuggestedReplacements());
    matches = rule.match(langTool.getAnalyzedSentence("Нападаючий"));
    assertEquals(1, matches.length);
    assertEquals(Arrays.asList("Нападник", "Нападальний", "Нападний"), matches[0].getSuggestedReplacements());
    matches = rule.match(langTool.getAnalyzedSentence("Нападаючого"));
    assertEquals(1, matches.length);
    assertEquals(Arrays.asList("Нападник", "Нападальний", "Нападний"), matches[0].getSuggestedReplacements());
    // test ignoreTagged
    matches = rule.match(langTool.getAnalyzedSentence("щедрота"));
    assertEquals(1, matches.length);
    assertEquals(Arrays.asList("щедрість", "гойність", "щедриня"), matches[0].getSuggestedReplacements());
    matches = rule.match(langTool.getAnalyzedSentence("щедроти"));
    assertEquals(0, matches.length);
}
Also used : Ukrainian(org.languagetool.language.Ukrainian) RuleMatch(org.languagetool.rules.RuleMatch) JLanguageTool(org.languagetool.JLanguageTool) Test(org.junit.Test)

Example 69 with JLanguageTool

use of org.languagetool.JLanguageTool in project languagetool by languagetool-org.

the class SimpleReplaceSoftRuleTest method testRule.

@Test
public void testRule() throws IOException {
    SimpleReplaceSoftRule rule = new SimpleReplaceSoftRule(TestTools.getEnglishMessages());
    RuleMatch[] matches;
    JLanguageTool langTool = new JLanguageTool(new Ukrainian());
    // correct sentences:
    matches = rule.match(langTool.getAnalyzedSentence("Ці рядки повинні збігатися."));
    assertEquals(0, matches.length);
    matches = rule.match(langTool.getAnalyzedSentence("Цей брелок."));
    assertEquals(1, matches.length);
    assertEquals(Arrays.asList("дармовис"), matches[0].getSuggestedReplacements());
    matches = rule.match(langTool.getAnalyzedSentence("Не знайде спасіння."));
    assertEquals(1, matches.length);
    assertEquals(Arrays.asList("рятування", "рятунок", "порятунок", "визволення"), matches[0].getSuggestedReplacements());
    assertTrue(matches[0].getMessage().contains(": релігія"));
    //refl
    matches = rule.match(langTool.getAnalyzedSentence("відображаються"));
    assertEquals(1, matches.length);
    assertEquals(Arrays.asList("показуватися", "зображатися", "відбиватися"), matches[0].getSuggestedReplacements());
    assertTrue("No context: " + matches[0].getMessage(), matches[0].getMessage().contains(": математика"));
// test ignoreTagged
//    matches = rule.match(langTool.getAnalyzedSentence("щедрота"));
//    assertEquals(1, matches.length);
//    assertEquals(Arrays.asList("щедрість", "гойність", "щедриня"), matches[0].getSuggestedReplacements());
//
//    matches = rule.match(langTool.getAnalyzedSentence("щедроти"));
//    assertEquals(0, matches.length);
}
Also used : Ukrainian(org.languagetool.language.Ukrainian) RuleMatch(org.languagetool.rules.RuleMatch) JLanguageTool(org.languagetool.JLanguageTool) Test(org.junit.Test)

Example 70 with JLanguageTool

use of org.languagetool.JLanguageTool in project languagetool by languagetool-org.

the class TokenAgreementRuleTest method setUp.

@Before
public void setUp() throws IOException {
    rule = new TokenAgreementRule(TestTools.getMessages("uk"));
    langTool = new JLanguageTool(new Ukrainian());
}
Also used : Ukrainian(org.languagetool.language.Ukrainian) JLanguageTool(org.languagetool.JLanguageTool) Before(org.junit.Before)

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