Search in sources :

Example 16 with JLanguageTool

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

the class GoogleTokenTest method testTokenizationWithPosTag.

@Test
public void testTokenizationWithPosTag() throws IOException {
    JLanguageTool lt = new JLanguageTool(new PosTaggingDemo());
    AnalyzedSentence analyzedSentence = lt.getAnalyzedSentence("This, isn't a test.");
    List<GoogleToken> tokens = GoogleToken.getGoogleTokens(analyzedSentence, false, new MyWordTokenizer());
    assertThat(tokens.get(0).token, is("This"));
    assertThat(tokens.get(0).posTags.toString(), is("[This/DT]"));
    assertThat(tokens.get(1).token, is(","));
    assertThat(tokens.get(1).posTags.toString(), is("[,/null]"));
    assertThat(tokens.get(2).token, is("isn"));
    assertThat(tokens.get(3).token, is("'t"));
    assertThat(tokens.get(4).token, is("a"));
    assertThat(tokens.get(5).token, is("test"));
    assertThat(tokens.get(5).posTags.toString(), is("[test/NN]"));
    assertThat(tokens.get(6).token, is("."));
}
Also used : AnalyzedSentence(org.languagetool.AnalyzedSentence) JLanguageTool(org.languagetool.JLanguageTool) Test(org.junit.Test)

Example 17 with JLanguageTool

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

the class DemoPatternRuleTest method testRule.

@Test
public void testRule() throws IOException {
    PatternRule pr;
    RuleMatch[] matches;
    JLanguageTool langTool = new JLanguageTool(language);
    pr = makePatternRule("one");
    matches = pr.match(langTool.getAnalyzedSentence("A non-matching sentence."));
    assertEquals(0, matches.length);
    matches = pr.match(langTool.getAnalyzedSentence("A matching sentence with one match."));
    assertEquals(1, matches.length);
    assertEquals(25, matches[0].getFromPos());
    assertEquals(28, matches[0].getToPos());
    // these two are not set if the rule is called standalone (not via
    // JLanguageTool):
    assertEquals(-1, matches[0].getColumn());
    assertEquals(-1, matches[0].getLine());
    assertEquals("ID1", matches[0].getRule().getId());
    assertTrue(matches[0].getMessage().equals("user visible message"));
    assertTrue(matches[0].getShortMessage().equals("short comment"));
    matches = pr.match(langTool.getAnalyzedSentence("one one and one: three matches"));
    assertEquals(3, matches.length);
    pr = makePatternRule("one two");
    matches = pr.match(langTool.getAnalyzedSentence("this is one not two"));
    assertEquals(0, matches.length);
    matches = pr.match(langTool.getAnalyzedSentence("this is two one"));
    assertEquals(0, matches.length);
    matches = pr.match(langTool.getAnalyzedSentence("this is one two three"));
    assertEquals(1, matches.length);
    matches = pr.match(langTool.getAnalyzedSentence("one two"));
    assertEquals(1, matches.length);
    pr = makePatternRule("one|foo|xxxx two", false, true);
    matches = pr.match(langTool.getAnalyzedSentence("one foo three"));
    assertEquals(0, matches.length);
    matches = pr.match(langTool.getAnalyzedSentence("one two"));
    assertEquals(1, matches.length);
    matches = pr.match(langTool.getAnalyzedSentence("foo two"));
    assertEquals(1, matches.length);
    matches = pr.match(langTool.getAnalyzedSentence("one foo two"));
    assertEquals(1, matches.length);
    matches = pr.match(langTool.getAnalyzedSentence("y x z one two blah foo"));
    assertEquals(1, matches.length);
    pr = makePatternRule("one|foo|xxxx two|yyy", false, true);
    matches = pr.match(langTool.getAnalyzedSentence("one, yyy"));
    assertEquals(0, matches.length);
    matches = pr.match(langTool.getAnalyzedSentence("one yyy"));
    assertEquals(1, matches.length);
    matches = pr.match(langTool.getAnalyzedSentence("xxxx two"));
    assertEquals(1, matches.length);
    matches = pr.match(langTool.getAnalyzedSentence("xxxx yyy"));
    assertEquals(1, matches.length);
}
Also used : RuleMatch(org.languagetool.rules.RuleMatch) JLanguageTool(org.languagetool.JLanguageTool) Test(org.junit.Test)

Example 18 with JLanguageTool

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

the class MorfologikNewZealandSpellerRuleTest method testMorfologikSpeller.

@Test
public void testMorfologikSpeller() throws IOException {
    NewZealandEnglish language = new NewZealandEnglish();
    MorfologikNewZealandSpellerRule rule = new MorfologikNewZealandSpellerRule(TestTools.getMessages("en"), language);
    JLanguageTool langTool = new JLanguageTool(language);
    // correct sentences:
    assertEquals(0, rule.match(langTool.getAnalyzedSentence("This is an example: we get behaviour as a dictionary word.")).length);
    assertEquals(0, rule.match(langTool.getAnalyzedSentence("Why don't we speak today.")).length);
    //with doesn't
    assertEquals(0, rule.match(langTool.getAnalyzedSentence("He doesn't know what to do.")).length);
    assertEquals(0, rule.match(langTool.getAnalyzedSentence(",")).length);
    assertEquals(0, rule.match(langTool.getAnalyzedSentence("123454")).length);
    //special New Zealand content:
    assertEquals(0, rule.match(langTool.getAnalyzedSentence("Abercrombie")).length);
    //incorrect sentences:
    RuleMatch[] matches1 = rule.match(langTool.getAnalyzedSentence("behavior"));
    // check match positions:
    assertEquals(1, matches1.length);
    assertEquals(0, matches1[0].getFromPos());
    assertEquals(8, matches1[0].getToPos());
    assertEquals("behaviour", matches1[0].getSuggestedReplacements().get(0));
    assertEquals(1, rule.match(langTool.getAnalyzedSentence("aõh")).length);
    assertEquals(0, rule.match(langTool.getAnalyzedSentence("a")).length);
    //based on replacement pairs:
    RuleMatch[] matches2 = rule.match(langTool.getAnalyzedSentence("He teached us."));
    // check match positions:
    assertEquals(1, matches2.length);
    assertEquals(3, matches2[0].getFromPos());
    assertEquals(10, matches2[0].getToPos());
    assertEquals("taught", matches2[0].getSuggestedReplacements().get(0));
}
Also used : RuleMatch(org.languagetool.rules.RuleMatch) JLanguageTool(org.languagetool.JLanguageTool) NewZealandEnglish(org.languagetool.language.NewZealandEnglish) Test(org.junit.Test)

Example 19 with JLanguageTool

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

the class MorfologikSouthAfricanSpellerRuleTest method testMorfologikSpeller.

@Test
public void testMorfologikSpeller() throws IOException {
    SouthAfricanEnglish language = new SouthAfricanEnglish();
    MorfologikSouthAfricanSpellerRule rule = new MorfologikSouthAfricanSpellerRule(TestTools.getMessages("en"), language);
    JLanguageTool langTool = new JLanguageTool(language);
    // correct sentences:
    assertEquals(0, rule.match(langTool.getAnalyzedSentence("This is an example: we get behaviour as a dictionary word.")).length);
    assertEquals(0, rule.match(langTool.getAnalyzedSentence("Why don't we speak today.")).length);
    //with doesn't
    assertEquals(0, rule.match(langTool.getAnalyzedSentence("He doesn't know what to do.")).length);
    assertEquals(0, rule.match(langTool.getAnalyzedSentence(",")).length);
    assertEquals(0, rule.match(langTool.getAnalyzedSentence("123454")).length);
    //South African dict:
    assertEquals(0, rule.match(langTool.getAnalyzedSentence("Amanzimnyama")).length);
    //incorrect sentences:
    RuleMatch[] matches1 = rule.match(langTool.getAnalyzedSentence("behavior"));
    // check match positions:
    assertEquals(1, matches1.length);
    assertEquals(0, matches1[0].getFromPos());
    assertEquals(8, matches1[0].getToPos());
    assertEquals("behaviour", matches1[0].getSuggestedReplacements().get(0));
    assertEquals(1, rule.match(langTool.getAnalyzedSentence("aõh")).length);
    assertEquals(0, rule.match(langTool.getAnalyzedSentence("a")).length);
    //based on replacement pairs:
    RuleMatch[] matches2 = rule.match(langTool.getAnalyzedSentence("He teached us."));
    // check match positions:
    assertEquals(1, matches2.length);
    assertEquals(3, matches2[0].getFromPos());
    assertEquals(10, matches2[0].getToPos());
    assertEquals("taught", matches2[0].getSuggestedReplacements().get(0));
}
Also used : RuleMatch(org.languagetool.rules.RuleMatch) JLanguageTool(org.languagetool.JLanguageTool) SouthAfricanEnglish(org.languagetool.language.SouthAfricanEnglish) Test(org.junit.Test)

Example 20 with JLanguageTool

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

the class NewZealandReplaceRuleTest method setUp.

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