Search in sources :

Example 86 with JLanguageTool

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

the class KhmerSpaceBeforeRuleTest method testSpaceBeforeRule.

@Test
public void testSpaceBeforeRule() throws IOException {
    final Khmer language = new Khmer();
    KhmerSpaceBeforeRule rule = new KhmerSpaceBeforeRule(TestTools.getEnglishMessages(), language);
    JLanguageTool langTool = new JLanguageTool(language);
    // correct sentences:
    assertEquals(0, rule.match(langTool.getAnalyzedSentence("គាត់​បាន​ទៅ ដើម្បី​ទិញ​ម្ហូប។")).length);
    assertEquals(0, rule.match(langTool.getAnalyzedSentence("ខ្ញុំ និង​គាត់។")).length);
    assertEquals(0, rule.match(langTool.getAnalyzedSentence("គាត់​ចង់​បាន ពីព្រោះ​គាត់​អត់​មាន។")).length);
    // incorrect sentences:
    assertEquals(1, rule.match(langTool.getAnalyzedSentence("គាត់​បាន​ទៅ​ដើម្បី​ទិញ​ម្ហូប។")).length);
    assertEquals(1, rule.match(langTool.getAnalyzedSentence("ខ្ញុំ​និង​គាត់។")).length);
    assertEquals(1, rule.match(langTool.getAnalyzedSentence("គាត់​ចង់​បាន​ពីព្រោះ​គាត់​អត់​មាន។")).length);
}
Also used : JLanguageTool(org.languagetool.JLanguageTool) Khmer(org.languagetool.language.Khmer) Test(org.junit.Test)

Example 87 with JLanguageTool

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

the class MorfologikPolishSpellerRuleTest method testMorfologikSpeller.

@Test
public void testMorfologikSpeller() throws IOException {
    final MorfologikPolishSpellerRule rule = new MorfologikPolishSpellerRule(TestTools.getMessages("pl"), new Polish());
    final JLanguageTool langTool = new JLanguageTool(new Polish());
    // correct sentences:
    assertEquals(0, rule.match(langTool.getAnalyzedSentence("To jest test bez jakiegokolwiek błędu.")).length);
    assertEquals(0, rule.match(langTool.getAnalyzedSentence("Żółw na starość wydziela dziwną woń.")).length);
    assertEquals(0, rule.match(langTool.getAnalyzedSentence("Żółw na starość wydziela dziwną woń numer 1234.")).length);
    assertEquals(0, rule.match(langTool.getAnalyzedSentence("W MI-6 pracuje 15-letni agent.")).length);
    //test for "LanguageTool":
    assertEquals(0, rule.match(langTool.getAnalyzedSentence("LanguageTool jest świetny!")).length);
    //test for the ignored uppercase word "Gdym":
    assertEquals(0, rule.match(langTool.getAnalyzedSentence("Gdym to zobaczył, zdębiałem.")).length);
    assertEquals(0, rule.match(langTool.getAnalyzedSentence(",")).length);
    assertEquals(0, rule.match(langTool.getAnalyzedSentence("123454")).length);
    //compound word with ignored part "techniczno"
    assertEquals(0, rule.match(langTool.getAnalyzedSentence("Bogactwo nie rośnie proporcjonalnie do jej rozwoju techniczno-terytorialnego.")).length);
    //compound word with one of the compound prefixes:
    assertEquals(0, rule.match(langTool.getAnalyzedSentence("Antypostmodernistyczna batalia hiperfilozofów")).length);
    //compound words: "trzynastobitowy", "zgniłożółty"
    assertEquals(0, rule.match(langTool.getAnalyzedSentence("Trzynastobitowe przystawki w kolorze zgniłożółtym")).length);
    //incorrect sentences:
    final RuleMatch[] matches = rule.match(langTool.getAnalyzedSentence("Zolw"));
    // check match positions:
    assertEquals(1, matches.length);
    assertEquals(0, matches[0].getFromPos());
    assertEquals(4, matches[0].getToPos());
    assertEquals("Żółw", matches[0].getSuggestedReplacements().get(0));
    assertEquals(1, rule.match(langTool.getAnalyzedSentence("aõh")).length);
    //tokenizing on prefixes niby- and quasi-
    assertEquals(0, rule.match(langTool.getAnalyzedSentence("Niby-artysta spotkał się z quasi-opiekunem i niby-Francuzem.")).length);
    final RuleMatch[] prunedMatches = rule.match(langTool.getAnalyzedSentence("Clarkem"));
    assertEquals(1, prunedMatches.length);
    assertEquals(5, prunedMatches[0].getSuggestedReplacements().size());
    assertEquals("Clarke", prunedMatches[0].getSuggestedReplacements().get(0));
    assertEquals("Clarkiem", prunedMatches[0].getSuggestedReplacements().get(1));
    assertEquals("Ciarkę", prunedMatches[0].getSuggestedReplacements().get(2));
    assertEquals("Clarkom", prunedMatches[0].getSuggestedReplacements().get(3));
    assertEquals("Czarkę", prunedMatches[0].getSuggestedReplacements().get(4));
    // There should be a match, this is not a prefix!
    assertEquals(1, rule.match(langTool.getAnalyzedSentence("premoc")).length);
    // "0" instead "o"...
    assertEquals(1, rule.match(langTool.getAnalyzedSentence("dziwneg0")).length);
}
Also used : Polish(org.languagetool.language.Polish) RuleMatch(org.languagetool.rules.RuleMatch) JLanguageTool(org.languagetool.JLanguageTool) Test(org.junit.Test)

Example 88 with JLanguageTool

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

the class PolishUnpairedBracketsRuleTest method testRulePolish.

@Test
public void testRulePolish() throws IOException {
    Polish language = new Polish();
    PolishUnpairedBracketsRule rule = new PolishUnpairedBracketsRule(TestTools.getEnglishMessages(), language);
    JLanguageTool lt = new JLanguageTool(language);
    assertEquals(0, getMatches("(To jest zdanie do testowania).", rule, lt));
    assertEquals(0, getMatches("Piosenka ta trafiła na wiele list \"Best of...\", włączając w to te, które zostały utworzone przez magazyn Rolling Stone.", rule, lt));
    assertEquals(0, getMatches("A \"B\" C.", rule, lt));
    assertEquals(0, getMatches("\"A\" B \"C\".", rule, lt));
    assertEquals(1, getMatches("W tym zdaniu jest niesparowany „cudzysłów.", rule, lt));
}
Also used : Polish(org.languagetool.language.Polish) JLanguageTool(org.languagetool.JLanguageTool) Test(org.junit.Test)

Example 89 with JLanguageTool

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

the class PolishWordRepeatRuleTest method testRule.

@Test
public void testRule() throws IOException {
    final PolishWordRepeatRule rule = new PolishWordRepeatRule(TestTools.getEnglishMessages());
    RuleMatch[] matches;
    JLanguageTool langTool = new JLanguageTool(new Polish());
    //correct
    matches = rule.match(langTool.getAnalyzedSentence("To jest zdanie próbne."));
    assertEquals(0, matches.length);
    matches = rule.match(langTool.getAnalyzedSentence("On tak się bardzo nie martwił, bo przecież musiał się umyć."));
    assertEquals(0, matches.length);
    //repeated prepositions, don't count'em
    matches = rule.match(langTool.getAnalyzedSentence("Na dyskotece tańczył jeszcze, choć był na bani."));
    assertEquals(0, matches.length);
    // sf bug report:
    matches = rule.match(langTool.getAnalyzedSentence("Żadnych „ale”."));
    assertEquals(0, matches.length);
    //incorrect
    matches = rule.match(langTool.getAnalyzedSentence("Był on bowiem pięknym strzelcem bowiem."));
    assertEquals(1, matches.length);
    matches = rule.match(langTool.getAnalyzedSentence("Mówiła długo, żeby tylko mówić długo."));
    assertEquals(2, matches.length);
}
Also used : RuleMatch(org.languagetool.rules.RuleMatch) Polish(org.languagetool.language.Polish) JLanguageTool(org.languagetool.JLanguageTool) Test(org.junit.Test)

Example 90 with JLanguageTool

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

the class SimpleReplaceRuleTest method setUp.

@Before
public void setUp() throws Exception {
    rule = new SimpleReplaceRule(TestTools.getMessages("pl"));
    langTool = new JLanguageTool(new Polish());
}
Also used : Polish(org.languagetool.language.Polish) 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