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;
}
}
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);
}
}
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));
}
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());
}
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());
}
Aggregations