Search in sources :

Example 36 with JLanguageTool

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

the class SentenceWhitespaceRuleTest method testMatch.

@Test
public void testMatch() throws Exception {
    JLanguageTool lt = new JLanguageTool(new German());
    TestTools.disableAllRulesExcept(lt, "DE_SENTENCE_WHITESPACE");
    assertGood("Das ist ein Satz. Und hier der nächste.", lt);
    assertGood("Das ist ein Satz! Und hier der nächste.", lt);
    assertGood("Ist das ein Satz? Hier der nächste.", lt);
    assertBad("Das ist ein Satz.Und hier der nächste.", lt);
    assertBad("Das ist ein Satz!Und hier der nächste.", lt);
    assertBad("Ist das ein Satz?Hier der nächste.", lt);
    assertGood("Am 28. September.", lt);
    assertBad("Am 28.September.", lt);
    assertTrue(lt.check("Am 7.September 2014.").get(0).getMessage().contains("nach Ordnungszahlen"));
    assertTrue(lt.check("Im September.Dann der nächste Satz.").get(0).getMessage().contains("zwischen Sätzen"));
}
Also used : JLanguageTool(org.languagetool.JLanguageTool) German(org.languagetool.language.German) Test(org.junit.Test)

Example 37 with JLanguageTool

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

the class WordRepeatRuleTest method testRuleGerman.

@Test
public void testRuleGerman() throws IOException {
    JLanguageTool lt = new JLanguageTool(german);
    assertGood("Das sind die Sätze, die die testen sollen.", lt);
    assertGood("Sätze, die die testen.", lt);
    assertGood("Das Haus, auf das das Mädchen zeigt.", lt);
    assertGood("Warum fragen Sie sie nicht selbst?", lt);
    assertBad("Die die Sätze zum testen.", lt);
    assertBad("Und die die Sätze zum testen.", lt);
    assertBad("Auf der der Fensterbank steht eine Blume.", lt);
    assertBad("Das Buch, in in dem es steht.", lt);
    assertBad("Das Haus, auf auf das Mädchen zurennen.", lt);
    assertBad("Sie sie gehen nach Hause.", lt);
}
Also used : JLanguageTool(org.languagetool.JLanguageTool) Test(org.junit.Test)

Example 38 with JLanguageTool

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

the class HunspellRuleTest method testRuleWithSwissGerman.

@Test
public void testRuleWithSwissGerman() throws Exception {
    HunspellRule rule = new HunspellRule(TestTools.getMessages("de"), new SwissGerman());
    JLanguageTool langTool = new JLanguageTool(new German());
    commonGermanAsserts(rule, langTool);
    // ß not allowed in Swiss
    assertEquals(1, rule.match(langTool.getAnalyzedSentence("Der äußere Übeltäter.")).length);
    // ss is used instead of ß
    assertEquals(0, rule.match(langTool.getAnalyzedSentence("Der äussere Übeltäter.")).length);
}
Also used : SwissGerman(org.languagetool.language.SwissGerman) JLanguageTool(org.languagetool.JLanguageTool) SwissGerman(org.languagetool.language.SwissGerman) AustrianGerman(org.languagetool.language.AustrianGerman) German(org.languagetool.language.German) GermanyGerman(org.languagetool.language.GermanyGerman) Test(org.junit.Test)

Example 39 with JLanguageTool

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

the class Searcher method getLanguageToolWithOneRule.

private JLanguageTool getLanguageToolWithOneRule(Language lang, PatternRule patternRule) {
    JLanguageTool langTool = new JLanguageTool(lang);
    for (Rule rule : langTool.getAllActiveRules()) {
        if (!rule.getId().equals(patternRule.getId())) {
            langTool.disableRule(rule.getId());
        }
    }
    langTool.addRule(patternRule);
    // rule might be off by default
    langTool.enableRule(patternRule.getId());
    return langTool;
}
Also used : JLanguageTool(org.languagetool.JLanguageTool) PatternRule(org.languagetool.rules.patterns.PatternRule) Rule(org.languagetool.rules.Rule)

Example 40 with JLanguageTool

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

the class LanguageToolFilterTest method testFilter.

public void testFilter() throws Exception {
    String input = "How to?";
    Tokenizer stream = new AnyCharTokenizer();
    stream.setReader(new StringReader(input));
    LanguageToolFilter filter = new LanguageToolFilter(stream, new JLanguageTool(new English()), false);
    //displayTokensWithFullDetails(filter);
    String start = "_POS_SENT_START";
    assertTokenStreamContents(filter, new String[] { start, "How", "_LEMMA_how", "_POS_WRB", "to", "_LEMMA_to", "_POS_TO", "_LEMMA_to", "_POS_IN", "?", "_POS_SENT_END" }, new int[] { 0, 0, 0, 0, 4, 4, 4, 4, 4, 6, 6 }, new int[] { 0, 3, 3, 3, 6, 6, 6, 6, 6, 7, 7 }, new String[] { "pos", "word", "pos", "pos", "word", "pos", "pos", "pos", "pos", "word", "pos" }, new int[] { 1, 1, 0, 0, 1, 0, 0, 0, 0, 1, 0 }, 7);
}
Also used : English(org.languagetool.language.English) JLanguageTool(org.languagetool.JLanguageTool) StringReader(java.io.StringReader) Tokenizer(org.apache.lucene.analysis.Tokenizer)

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