Search in sources :

Example 11 with JLanguageTool

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

the class DifferentLengthRuleTest method testRule.

@Test
public void testRule() throws IOException {
    DifferentLengthRule rule = new DifferentLengthRule();
    RuleMatch[] matches;
    JLanguageTool trgLangTool = new JLanguageTool(TestTools.getDemoLanguage());
    JLanguageTool srcLangTool = new JLanguageTool(new FakeLanguage());
    rule.setSourceLanguage(TestTools.getDemoLanguage());
    // correct sentences:
    matches = rule.match(srcLangTool.getAnalyzedSentence("This is a test sentence."), trgLangTool.getAnalyzedSentence("To zdanie testowe."));
    assertEquals(0, matches.length);
    matches = rule.match(srcLangTool.getAnalyzedSentence("Click this button."), trgLangTool.getAnalyzedSentence("Kliknij ten przycisk."));
    assertEquals(0, matches.length);
    // incorrect sentences:
    matches = rule.match(srcLangTool.getAnalyzedSentence("Open a file, and check if it is corrupt."), trgLangTool.getAnalyzedSentence("Otwórz plik."));
    assertEquals(1, matches.length);
}
Also used : RuleMatch(org.languagetool.rules.RuleMatch) FakeLanguage(org.languagetool.FakeLanguage) JLanguageTool(org.languagetool.JLanguageTool) Test(org.junit.Test)

Example 12 with JLanguageTool

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

the class ToolsTest method expectDemoRuleId.

private void expectDemoRuleId(Set<CategoryId> disabledCategories, Set<CategoryId> enabledCategories, Set<String> disabledRules, Set<String> enabledRules, boolean useEnabledOnly, Demo demo) {
    JLanguageTool lt = new JLanguageTool(demo);
    Tools.selectRules(lt, disabledCategories, enabledCategories, disabledRules, enabledRules, useEnabledOnly);
    assertTrue(getRuleIds(lt).contains("DEMO_RULE"));
}
Also used : JLanguageTool(org.languagetool.JLanguageTool)

Example 13 with JLanguageTool

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

the class RegexPatternRuleTest method testMatchWithMark.

@Test
public void testMatchWithMark() throws IOException {
    RegexPatternRule rule = new RegexPatternRule("ID", "desc", "msg: <suggestion>a suggestion \\1</suggestion>", "<suggestion>another suggestion \\2</suggestion>", TestTools.getDemoLanguage(), Pattern.compile("(fo.) (bar)"), 1);
    JLanguageTool lt = new JLanguageTool(TestTools.getDemoLanguage());
    RuleMatch[] matches2 = rule.match(lt.getAnalyzedSentence("This is foo bar"));
    assertThat(matches2.length, is(1));
    assertThat(matches2[0].getFromPos(), is(8));
    assertThat(matches2[0].getToPos(), is(11));
}
Also used : RuleMatch(org.languagetool.rules.RuleMatch) JLanguageTool(org.languagetool.JLanguageTool) Test(org.junit.Test)

Example 14 with JLanguageTool

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

the class RegexPatternRuleTest method testMatch.

@Test
public void testMatch() throws IOException {
    RegexPatternRule rule = new RegexPatternRule("ID", "desc", "msg: <suggestion>a suggestion \\1</suggestion>", "<suggestion>another suggestion \\2</suggestion>", TestTools.getDemoLanguage(), Pattern.compile("(fo.) (bar)"), 0);
    JLanguageTool lt = new JLanguageTool(TestTools.getDemoLanguage());
    RuleMatch[] matches1 = rule.match(lt.getAnalyzedSentence("This is a test"));
    assertThat(matches1.length, is(0));
    RuleMatch[] matches2 = rule.match(lt.getAnalyzedSentence("This is foo bar"));
    assertThat(matches2.length, is(1));
    assertThat(matches2[0].getFromPos(), is(8));
    assertThat(matches2[0].getToPos(), is(15));
    RuleMatch[] matches3 = rule.match(lt.getAnalyzedSentence("This is foo bar and fou bar"));
    assertThat(matches3.length, is(2));
    assertThat(matches3[0].getFromPos(), is(8));
    assertThat(matches3[0].getToPos(), is(15));
    assertThat(matches3[0].getMessage(), is("msg: <suggestion>a suggestion foo</suggestion>"));
    assertThat(matches3[0].getSuggestedReplacements().toString(), is("[a suggestion foo, another suggestion bar]"));
    assertThat(matches3[1].getFromPos(), is(20));
    assertThat(matches3[1].getToPos(), is(27));
    assertThat(matches3[1].getMessage(), is("msg: <suggestion>a suggestion fou</suggestion>"));
    assertThat(matches3[1].getSuggestedReplacements().toString(), is("[a suggestion fou, another suggestion bar]"));
}
Also used : RuleMatch(org.languagetool.rules.RuleMatch) JLanguageTool(org.languagetool.JLanguageTool) Test(org.junit.Test)

Example 15 with JLanguageTool

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

the class DifferentPunctuationRuleTest method testRule.

@Test
public void testRule() throws IOException {
    DifferentPunctuationRule rule = new DifferentPunctuationRule();
    RuleMatch[] matches;
    JLanguageTool srcLangTool = new JLanguageTool(TestTools.getDemoLanguage());
    JLanguageTool trgLangTool = new JLanguageTool(new FakeLanguage());
    rule.setSourceLanguage(TestTools.getDemoLanguage());
    // correct sentences:
    matches = rule.match(srcLangTool.getAnalyzedSentence("This is a test sentence!"), trgLangTool.getAnalyzedSentence("C'est la vie!"));
    assertEquals(0, matches.length);
    matches = rule.match(srcLangTool.getAnalyzedSentence("one sentence"), trgLangTool.getAnalyzedSentence("jedno zdanie"));
    assertEquals(0, matches.length);
    // incorrect sentences:
    matches = rule.match(srcLangTool.getAnalyzedSentence("This this is a test sentence."), trgLangTool.getAnalyzedSentence("This this is a test sentence!"));
    assertEquals(1, matches.length);
}
Also used : RuleMatch(org.languagetool.rules.RuleMatch) FakeLanguage(org.languagetool.FakeLanguage) JLanguageTool(org.languagetool.JLanguageTool) 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