Search in sources :

Example 81 with JLanguageTool

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

the class PortugueseWordRepeatBeginningRuleTest method testRule.

@Test
public void testRule() throws IOException {
    JLanguageTool langTool = new JLanguageTool(new Portuguese());
    // correct sentences:
    assertEquals(0, langTool.check("Este exemplo está correto. Este exemplo também.").size());
    assertEquals(0, langTool.check("Certo, isto está bem. Este exemplo está correto. Certo que este também.").size());
    assertEquals(0, langTool.check("2011: Setembro já passou. 2011: Outubro também. 2011: Novembro já se foi.").size());
    // errors:
    assertEquals(1, langTool.check("Este exemplo está correto. Este segundo também. Este terceiro exemplo não.").size());
    assertEquals(1, langTool.check("Então, este está correto. Então, este está errado, por causa da repetição.").size());
    // this used to cause false alarms because reset() was not implemented
    assertEquals(0, langTool.check("Então, este deve ser considerado uma nova frase.").size());
}
Also used : Portuguese(org.languagetool.language.Portuguese) JLanguageTool(org.languagetool.JLanguageTool) Test(org.junit.Test)

Example 82 with JLanguageTool

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

the class HunspellRuleTest method testImmunizedFrenchWord.

@Test
public void testImmunizedFrenchWord() throws Exception {
    final French french = new French();
    final HunspellRule rule = new HunspellRule(TestTools.getMessages("fr"), french);
    JLanguageTool langTool = new JLanguageTool(french);
    assertEquals(1, rule.match(langTool.getAnalyzedSentence("languageTool est génial.")).length);
    final French frenchWithDisambiguator = new French() {

        @Override
        public Disambiguator getDisambiguator() {
            return new TestFrenchDisambiguator();
        }
    };
    langTool = new JLanguageTool(frenchWithDisambiguator);
    assertEquals(0, rule.match(langTool.getAnalyzedSentence("languageTool est génial.")).length);
}
Also used : French(org.languagetool.language.French) JLanguageTool(org.languagetool.JLanguageTool) Test(org.junit.Test)

Example 83 with JLanguageTool

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

the class MorfologikMalayalamSpellerRuleTest method testMorfologikSpeller.

@Test
public void testMorfologikSpeller() throws IOException {
    final Malayalam language = new Malayalam();
    final MorfologikMalayalamSpellerRule rule = new MorfologikMalayalamSpellerRule(TestTools.getMessages("ml"), language);
    RuleMatch[] matches;
    final JLanguageTool langTool = new JLanguageTool(language);
    // correct sentences:
    assertEquals(0, rule.match(langTool.getAnalyzedSentence("എന്തുകൊണ്ട്‌ അംഗത്വം")).length);
    assertEquals(0, rule.match(langTool.getAnalyzedSentence("എങ്ങനെ അംഗമാകാം?")).length);
    //test for "LanguageTool":
    assertEquals(0, rule.match(langTool.getAnalyzedSentence("LanguageTool")).length);
    assertEquals(0, rule.match(langTool.getAnalyzedSentence(",")).length);
    assertEquals(0, rule.match(langTool.getAnalyzedSentence("123454")).length);
    //incorrect sentences:
    matches = rule.match(langTool.getAnalyzedSentence("Zolw"));
    // check match positions:
    assertEquals(1, matches.length);
    assertEquals(0, matches[0].getFromPos());
    assertEquals(4, matches[0].getToPos());
    assertEquals(matches[0].getSuggestedReplacements().isEmpty(), true);
    matches = rule.match(langTool.getAnalyzedSentence("എaങ്ങനെ"));
    assertEquals(1, matches.length);
    assertEquals(0, matches[0].getFromPos());
    assertEquals(7, matches[0].getToPos());
    assertEquals(matches[0].getSuggestedReplacements().get(0), "എങ്ങനെ");
    assertEquals(1, rule.match(langTool.getAnalyzedSentence("aõh")).length);
    assertEquals(1, rule.match(langTool.getAnalyzedSentence("a")).length);
}
Also used : Malayalam(org.languagetool.language.Malayalam) RuleMatch(org.languagetool.rules.RuleMatch) JLanguageTool(org.languagetool.JLanguageTool) Test(org.junit.Test)

Example 84 with JLanguageTool

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

the class GenericUnpairedBracketsRuleTest method testDutchRule.

@Test
public void testDutchRule() throws IOException {
    langTool = new JLanguageTool(new Dutch());
    rule = org.languagetool.rules.GenericUnpairedBracketsRuleTest.getBracketsRule(langTool);
    // correct sentences:
    assertMatches("Het centrale probleem van het werk is de ‘dichterlijke kuischheid’.", 0);
    //this was a bug as there are several pairs that start with the same char:
    assertMatches(" Eurlings: “De gegevens van de dienst zijn van cruciaal belang voor de veiligheid van de luchtvaart en de scheepvaart”.", 0);
    assertMatches(" Eurlings: „De gegevens van de dienst zijn van cruciaal belang voor de veiligheid van de luchtvaart en de scheepvaart”.", 0);
    // incorrect sentences:
    assertMatches("Het centrale probleem van het werk is de „dichterlijke kuischheid.", 1);
    assertMatches(" Eurlings: “De gegevens van de dienst zijn van cruciaal belang voor de veiligheid van de luchtvaart en de scheepvaart.", 1);
}
Also used : JLanguageTool(org.languagetool.JLanguageTool) Dutch(org.languagetool.language.Dutch) Test(org.junit.Test)

Example 85 with JLanguageTool

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

the class UppercaseSentenceStartRuleTest method testDutchSpecialCases.

@Test
public void testDutchSpecialCases() throws IOException {
    final JLanguageTool lt = new JLanguageTool(new Dutch() {

        @Override
        protected synchronized List<AbstractPatternRule> getPatternRules() {
            return Collections.emptyList();
        }
    });
    assertEquals(1, lt.check("A sentence.").size());
    assertEquals(0, lt.check("'s Morgens...").size());
    assertEquals(2, lt.check("a sentence.").size());
    assertEquals(1, lt.check("'s morgens...").size());
    assertEquals(2, lt.check("s sentence.").size());
}
Also used : JLanguageTool(org.languagetool.JLanguageTool) List(java.util.List) Dutch(org.languagetool.language.Dutch) 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