Search in sources :

Example 6 with GermanyGerman

use of org.languagetool.language.GermanyGerman in project languagetool by languagetool-org.

the class SuggestionReplacerTest method testCompleteText.

@Test
public void testCompleteText() throws Exception {
    InputStream stream = SuggestionReplacerTest.class.getResourceAsStream("/org/languagetool/dev/wikipedia/wikipedia.txt");
    String origMarkup = IOUtils.toString(stream, "utf-8");
    JLanguageTool langTool = new JLanguageTool(new GermanyGerman() {

        @Override
        protected synchronized List<AbstractPatternRule> getPatternRules() {
            return Collections.emptyList();
        }
    });
    langTool.disableRule(GermanSpellerRule.RULE_ID);
    langTool.disableRule("DE_AGREEMENT");
    langTool.disableRule("GERMAN_WORD_REPEAT_BEGINNING_RULE");
    langTool.disableRule("COMMA_PARENTHESIS_WHITESPACE");
    langTool.disableRule("DE_CASE");
    langTool.disableRule("ABKUERZUNG_LEERZEICHEN");
    langTool.disableRule("TYPOGRAFISCHE_ANFUEHRUNGSZEICHEN");
    PlainTextMapping mapping = filter.filter(origMarkup);
    List<RuleMatch> matches = langTool.check(mapping.getPlainText());
    assertThat("Expected 3 matches, got: " + matches, matches.size(), is(3));
    int oldPos = 0;
    for (RuleMatch match : matches) {
        SuggestionReplacer replacer = new SuggestionReplacer(mapping, origMarkup, new ErrorMarker("<s>", "</s>"));
        List<RuleMatchApplication> ruleMatchApplications = replacer.applySuggestionsToOriginalText(match);
        assertThat(ruleMatchApplications.size(), is(1));
        RuleMatchApplication ruleMatchApplication = ruleMatchApplications.get(0);
        assertThat(StringUtils.countMatches(ruleMatchApplication.getTextWithCorrection(), "absichtlicher absichtlicher"), is(2));
        int pos = ruleMatchApplication.getTextWithCorrection().indexOf("<s>absichtlicher</s> Fehler");
        if (pos == -1) {
            // markup area varies because our mapping is sometimes a bit off:
            pos = ruleMatchApplication.getTextWithCorrection().indexOf("<s>absichtlicher Fehler</s>");
        }
        assertTrue("Found correction at: " + pos, pos > oldPos);
        oldPos = pos;
    }
}
Also used : InputStream(java.io.InputStream) JLanguageTool(org.languagetool.JLanguageTool) GermanyGerman(org.languagetool.language.GermanyGerman) RuleMatch(org.languagetool.rules.RuleMatch) List(java.util.List) Test(org.junit.Test)

Example 7 with GermanyGerman

use of org.languagetool.language.GermanyGerman in project languagetool by languagetool-org.

the class HunspellRuleTest method testCompoundAwareRulePerformance.

@Ignore("just for internal performance testing, thus ignored by default")
@Test
public void testCompoundAwareRulePerformance() throws IOException {
    ResourceBundle messages = ResourceBundle.getBundle("org.languagetool.MessagesBundle", new Locale("de"));
    //slow:
    //HunspellRule rule = new HunspellRule(messages, Language.GERMANY_GERMAN);
    //fast:
    CompoundAwareHunspellRule rule = new GermanSpellerRule(messages, new GermanyGerman());
    rule.init();
    String[] words = { "foo", "warmup", "Rechtschreipreform", "Theatrekasse", "Zoobesuck", "Handselvertreter", "Mückenstick", "gewönlich", "Traprennen", "Autoverkehrr" };
    for (String word : words) {
        long startTime = System.currentTimeMillis();
        List<String> suggest = rule.getSuggestions(word);
        System.out.println((System.currentTimeMillis() - startTime) + "ms for " + word + ": " + suggest);
    }
}
Also used : Locale(java.util.Locale) ResourceBundle(java.util.ResourceBundle) GermanSpellerRule(org.languagetool.rules.de.GermanSpellerRule) GermanyGerman(org.languagetool.language.GermanyGerman) Ignore(org.junit.Ignore) Test(org.junit.Test)

Example 8 with GermanyGerman

use of org.languagetool.language.GermanyGerman in project languagetool by languagetool-org.

the class SpellingCheckRuleTest method testIgnorePhrases.

@Test
public void testIgnorePhrases() throws IOException {
    JLanguageTool lt = new JLanguageTool(new GermanyGerman());
    assertThat(lt.check("Ein Test mit Auriensis Fantasiewortus").size(), is(2));
    for (Rule rule : lt.getAllActiveRules()) {
        if (rule instanceof SpellingCheckRule) {
            ((SpellingCheckRule) rule).acceptPhrases(Arrays.asList("Auriensis Fantasiewortus", "fudeldu laberwort"));
        } else {
            lt.disableRule(rule.getId());
        }
    }
    assertThat(lt.check("Ein Test mit Auriensis Fantasiewortus").size(), is(0));
    // the words on their own are not ignored
    assertThat(lt.check("Ein Test mit Auriensis und Fantasiewortus").size(), is(2));
    assertThat(lt.check("fudeldu laberwort").size(), is(0));
    // Uppercase at sentence start is okay
    assertThat(lt.check("Fudeldu laberwort").size(), is(0));
    // Different case somewhere other than at sentence start is not okay
    assertThat(lt.check("Fudeldu Laberwort").size(), is(2));
}
Also used : SpellingCheckRule(org.languagetool.rules.spelling.SpellingCheckRule) JLanguageTool(org.languagetool.JLanguageTool) GermanSpellerRule(org.languagetool.rules.de.GermanSpellerRule) SpellingCheckRule(org.languagetool.rules.spelling.SpellingCheckRule) Rule(org.languagetool.rules.Rule) GermanyGerman(org.languagetool.language.GermanyGerman) Test(org.junit.Test)

Example 9 with GermanyGerman

use of org.languagetool.language.GermanyGerman in project languagetool by languagetool-org.

the class JLanguageToolTest method testGermanyGerman.

@Test
public void testGermanyGerman() throws IOException {
    JLanguageTool tool = new JLanguageTool(new GermanyGerman());
    assertEquals(0, tool.check("Ein Test, der keine Fehler geben sollte.").size());
    assertEquals(1, tool.check("Ein Test Test, der Fehler geben sollte.").size());
    tool.setListUnknownWords(true);
    // German rule has no effect with English error, but they are spelling mistakes:
    assertEquals(6, tool.check("I can give you more a detailed description").size());
    //test unknown words listing
    assertEquals("[I, can, description, detailed, give, more, you]", tool.getUnknownWords().toString());
}
Also used : GermanyGerman(org.languagetool.language.GermanyGerman) Test(org.junit.Test)

Example 10 with GermanyGerman

use of org.languagetool.language.GermanyGerman in project languagetool by languagetool-org.

the class CaseRuleTest method setUp.

@Before
public void setUp() throws IOException {
    rule = new CaseRule(TestTools.getMessages("de"), new GermanyGerman());
    lt = new JLanguageTool(new GermanyGerman());
}
Also used : JLanguageTool(org.languagetool.JLanguageTool) GermanyGerman(org.languagetool.language.GermanyGerman) Before(org.junit.Before)

Aggregations

GermanyGerman (org.languagetool.language.GermanyGerman)10 Test (org.junit.Test)8 JLanguageTool (org.languagetool.JLanguageTool)7 RuleMatch (org.languagetool.rules.RuleMatch)4 Before (org.junit.Before)2 GermanSpellerRule (org.languagetool.rules.de.GermanSpellerRule)2 InputStream (java.io.InputStream)1 List (java.util.List)1 Locale (java.util.Locale)1 ResourceBundle (java.util.ResourceBundle)1 Ignore (org.junit.Ignore)1 AustrianGerman (org.languagetool.language.AustrianGerman)1 German (org.languagetool.language.German)1 SwissGerman (org.languagetool.language.SwissGerman)1 Rule (org.languagetool.rules.Rule)1 SpellingCheckRule (org.languagetool.rules.spelling.SpellingCheckRule)1