Package org.languagetool

Examples of org.languagetool.JLanguageTool


  @Test
  public void testRuleWithFrench() throws Exception {
    final French french = new French();
    final HunspellRule rule = new HunspellRule(TestTools.getMessages("French"), french);
    final JLanguageTool langTool = new JLanguageTool(french);

    assertEquals(0, rule.match(langTool.getAnalyzedSentence("Un test simple.")).length);
    assertEquals(1, rule.match(langTool.getAnalyzedSentence("Un test simpple.")).length);
    assertEquals(0, rule.match(langTool.getAnalyzedSentence("Le cœur, la sœur.")).length);

    assertEquals(0, rule.match(langTool.getAnalyzedSentence("LanguageTool")).length);

    // Tests with dash and apostrophes.
    assertEquals(0, rule.match(langTool.getAnalyzedSentence("Il arrive après-demain.")).length);
    assertEquals(0, rule.match(langTool.getAnalyzedSentence("L'Haÿ-les-Roses")).length);
    assertEquals(1, rule.match(langTool.getAnalyzedSentence("L'Haÿ les Roses")).length);

    assertEquals(0, rule.match(langTool.getAnalyzedSentence("Aujourd'hui et jusqu'à demain.")).length);
    assertEquals(0, rule.match(langTool.getAnalyzedSentence("Aujourd’hui et jusqu’à demain.")).length);
    assertEquals(0, rule.match(langTool.getAnalyzedSentence("L'Allemagne et l'Italie.")).length);
    assertEquals(0, rule.match(langTool.getAnalyzedSentence("L’Allemagne et l’Italie.")).length);
    assertEquals(2, rule.match(langTool.getAnalyzedSentence("L’allemagne et l’italie.")).length);
  }
View Full Code Here


    final CheckBNC prg = new CheckBNC();
    prg.run(new File(args[0]));
  }
 
  private CheckBNC() throws IOException {
    langTool = new JLanguageTool(new English());
    langTool.activateDefaultPatternRules();
    final String[] disRules = new String[] {"UPPERCASE_SENTENCE_START", "COMMA_PARENTHESIS_WHITESPACE",
        "WORD_REPEAT_RULE", "DOUBLE_PUNCTUATION"};
    System.err.println("Note: disabling the following rules:");
    for (String disRule : disRules) {
View Full Code Here

*/
public class WordCoherencyRuleTest extends TestCase {

  public void testRule() throws IOException {
    final WordCoherencyRule rule = new WordCoherencyRule(null);
    final JLanguageTool langTool = new JLanguageTool(new German());
    // correct sentences:
    assertEquals(0, rule.match(langTool.getAnalyzedSentence("Das ist aufwendig, aber nicht zu aufwendig.")).length);
    // as WordCoherencyRule keeps its state to check more than one sentence
    // we need to create a new object each time:
    rule.reset();
    assertEquals(0, rule.match(langTool.getAnalyzedSentence("Das ist aufwändig, aber nicht zu aufwändig.")).length);
    // errors:
    assertError("Das ist aufwendig, aber nicht zu aufwändig.", langTool);
    assertError("Das ist aufwendiger, aber nicht zu aufwändig.", langTool);
    assertError("Das ist aufwändig, aber nicht zu aufwendig.", langTool);
    assertError("Das ist aufwändiger, aber nicht zu aufwendig.", langTool);
View Full Code Here

    tokenizer = new WordTokenizer();
    sentenceTokenizer = new SentenceTokenizer();
    disambiguator = new FrenchRuleDisambiguator();
    disamb2 = new DemoDisambiguator();   
    try {
      lt = new JLanguageTool(new French());
    } catch (IOException e) {
      fail(e.getMessage());
    }
  }
View Full Code Here

    final WordCoherencyRule rule = new WordCoherencyRule(null);
    assertEquals(1, rule.match(langTool.getAnalyzedSentence(s)).length);
  }

  public void testRuleCompleteTexts() throws IOException {
    final JLanguageTool langTool;
    // complete texts:
    List<RuleMatch> matches;
    langTool = new JLanguageTool(new German());
    matches = langTool.check("Das ist aufwändig. Aber hallo. Es ist wirklich aufwändig.");
    assertEquals(0, matches.size());
   
    matches = langTool.check("Das ist aufwendig. Aber hallo. Es ist wirklich aufwändig.");
    assertEquals(1, matches.size());
   
    matches = langTool.check("Das ist aufwändig. Aber hallo. Es ist wirklich aufwendig.");
    assertEquals(1, matches.size());
   
    // also find full forms:
    matches = langTool.check("Das ist aufwendig. Aber hallo. Es ist wirklich aufwendiger als...");
    assertEquals(0, matches.size());
   
    matches = langTool.check("Das ist aufwendig. Aber hallo. Es ist wirklich aufwändiger als...");
    assertEquals(1, matches.size());
   
    matches = langTool.check("Das ist aufwändig. Aber hallo. Es ist wirklich aufwendiger als...");
    assertEquals(1, matches.size());
   
    matches = langTool.check("Das ist das aufwändigste. Aber hallo. Es ist wirklich aufwendiger als...");
    assertEquals(1, matches.size());
   
    matches = langTool.check("Das ist das aufwändigste. Aber hallo. Es ist wirklich aufwendig.");
    assertEquals(1, matches.size());

    // cross-paragraph checks
    matches = langTool.check("Das ist das aufwändigste.\n\nAber hallo. Es ist wirklich aufwendig.");
    assertEquals(1, matches.size());
  }
View Full Code Here

  public void testMorfologikSpeller() throws IOException {
    final MorfologikBretonSpellerRule rule =
            new MorfologikBretonSpellerRule (TestTools.getMessages("Breton"), new Breton());

    RuleMatch[] matches;
    final JLanguageTool langTool = new JLanguageTool(new Breton());

    // correct sentences:
    assertEquals(0, rule.match(langTool.getAnalyzedSentence("Penaos emañ kont ganit?")).length);

    assertEquals(0, rule.match(langTool.getAnalyzedSentence("C'hwerc'h merc'h gwerc'h war c'hwerc'h marc'h kalloc'h")).length);
    assertEquals(0, rule.match(langTool.getAnalyzedSentence("C’hwerc’h merc’h gwerc‘h war c‘hwerc‘h marc'h kalloc‘h")).length);

    //words with hyphens are tokenized internally...
    assertEquals(0, rule.match(langTool.getAnalyzedSentence("Evel-just")).length);
    assertEquals(0, rule.match(langTool.getAnalyzedSentence("Barrek-tre eo LanguageTool")).length);

    assertEquals(0, rule.match(langTool.getAnalyzedSentence("C'hwerc'h merc'h gwerc'h war c'hwerc'h marc'h kalloc'h")).length);
    assertEquals(0, rule.match(langTool.getAnalyzedSentence("C’hwerc’h merc’h gwerc‘h war c‘hwerc‘h marc'h kalloc‘h")).length);
    assertEquals(0, rule.match(langTool.getAnalyzedSentence("Evel-just")).length);
    assertEquals(1, rule.match(langTool.getAnalyzedSentence("Evel-juste")).length);
    assertEquals(0, rule.match(langTool.getAnalyzedSentence("Barrek-tre eo LanguageTool")).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:

    assertEquals(1, rule.match(langTool.getAnalyzedSentence("Evel-juste")).length);

    matches = rule.match(langTool.getAnalyzedSentence("Evel-juste"));

    // check match positions:
    assertEquals(1, matches.length);
    assertEquals(5, matches[0].getFromPos());
    assertEquals(10, matches[0].getToPos());

    matches = rule.match(langTool.getAnalyzedSentence("C’hreizhig-don"));

    assertEquals(1, matches.length);

    // check match positions:
    assertEquals(1, matches.length);
    assertEquals(0, matches[0].getFromPos());
    assertEquals(10, matches[0].getToPos());

    assertEquals(1, rule.match(langTool.getAnalyzedSentence("aõh")).length);
    assertEquals(0, rule.match(langTool.getAnalyzedSentence("a")).length);
  }
View Full Code Here

        }
        prg.run(args[0]);
    }

    private void run(final String lang) throws IOException {
        JLanguageTool langTool = new JLanguageTool(
                Language.getLanguageForShortName(lang));
        BufferedReader in = null;
        BufferedWriter out = null;
        try {
            in = new BufferedReader(new InputStreamReader(System.in));
            out = new BufferedWriter(new OutputStreamWriter(System.out));
            String line;
            while ((line = in.readLine()) != null) {
                AnalyzedTokenReadings[] atr = langTool.getRawAnalyzedSentence(line).
                        getTokensWithoutWhitespace();
                for (AnalyzedTokenReadings a : atr) {
                    out.write(a.getToken());
                    out.write("\n");
                }
View Full Code Here

  public void testRuleGerman() throws IOException {
    final German german = new German();
    final WordRepeatRule rule = new GermanWordRepeatRule(TestTools.getEnglishMessages(), german);
    RuleMatch[] matches;
    final JLanguageTool langTool = new JLanguageTool(german);
    // correct sentences:
    matches = rule.match(langTool.getAnalyzedSentence("Das sind die Sätze, die die testen sollen."));
    assertEquals(0, matches.length);
    matches = rule.match(langTool.getAnalyzedSentence("Sätze, die die testen."));
    assertEquals(0, matches.length);
    matches = rule.match(langTool.getAnalyzedSentence("Das Haus, auf das das Mädchen zeigt."));
    assertEquals(0, matches.length);
    matches = rule.match(langTool.getAnalyzedSentence("Warum fragen Sie sie nicht selbst?"));
    assertEquals(0, matches.length);
    // incorrect sentences:
    matches = rule.match(langTool.getAnalyzedSentence("Die die Sätze zum testen."));
    assertEquals(1, matches.length);
    matches = rule.match(langTool.getAnalyzedSentence("Und die die Sätze zum testen."));
    assertEquals(1, matches.length);
    matches = rule.match(langTool.getAnalyzedSentence("Auf der der Fensterbank steht eine Blume."));
    assertEquals(1, matches.length);
    matches = rule.match(langTool.getAnalyzedSentence("Das Buch, in in dem es steht."));
    assertEquals(1, matches.length);
    matches = rule.match(langTool.getAnalyzedSentence("Das Haus, auf auf das Mädchen zurennen."));
    assertEquals(1, matches.length);
    matches = rule.match(langTool.getAnalyzedSentence("Sie sie gehen nach Hause."));
    assertEquals(1, matches.length);
  }
View Full Code Here

  @Test
  public void testMorfologikSpeller() throws IOException {
    final MorfologikPolishSpellerRule rule =
            new MorfologikPolishSpellerRule (TestTools.getMessages("Polish"), 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);
    //test for "LanguageTool":
    assertEquals(0, rule.match(langTool.getAnalyzedSentence("LanguageTool jest świetny!")).length);
    assertEquals(0, rule.match(langTool.getAnalyzedSentence(",")).length);
    assertEquals(0, rule.match(langTool.getAnalyzedSentence("123454")).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);
    assertEquals(0, rule.match(langTool.getAnalyzedSentence("a")).length);
  }
View Full Code Here

public class WhitespaceRuleTest extends TestCase {

    public void testRule() throws IOException {
      final WhitespaceRule rule = new WhitespaceRule(TestTools.getEnglishMessages(), new Polish());
      final JLanguageTool langTool = new JLanguageTool(new Polish());
      assertEquals(0, rule.match(langTool.getAnalyzedSentence("To jest test.")).length);
      assertEquals(1, rule.match(langTool.getAnalyzedSentence("To jest   test.")).length);
    }
View Full Code Here

TOP

Related Classes of org.languagetool.JLanguageTool

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.