use of org.languagetool.rules.spelling.SpellingCheckRule in project languagetool by languagetool-org.
the class SpellingCheckRuleTest method testIgnorePhrases.
@Test
public void testIgnorePhrases() throws IOException {
JLanguageTool langTool = new JLanguageTool(new AmericanEnglish());
assertThat(langTool.check("A test with myfoo mybar").size(), is(2));
for (Rule rule : langTool.getAllActiveRules()) {
if (rule instanceof SpellingCheckRule) {
((SpellingCheckRule) rule).acceptPhrases(Arrays.asList("myfoo mybar", "Myy othertest"));
} else {
langTool.disableRule(rule.getId());
}
}
assertThat(langTool.check("A test with myfoo mybar").size(), is(0));
// the words on their own are not ignored
assertThat(langTool.check("A test with myfoo and mybar").size(), is(2));
assertThat(langTool.check("myfoo mybar here").size(), is(0));
assertThat(langTool.check("Myfoo mybar here").size(), is(0));
assertThat(langTool.check("MYfoo mybar here").size(), is(2));
assertThat(langTool.check("Myy othertest is okay").size(), is(0));
assertThat(langTool.check("And Myy othertest is okay").size(), is(0));
assertThat(langTool.check("But Myy Othertest is not okay").size(), is(2));
assertThat(langTool.check("But myy othertest is not okay").size(), is(2));
}
use of org.languagetool.rules.spelling.SpellingCheckRule in project languagetool by languagetool-org.
the class WordListValidatorTest method testWordListValidity.
@Test
public void testWordListValidity() throws IOException {
Set<String> checked = new HashSet<>();
for (Language lang : Languages.get()) {
if (lang.getShortCode().equals("ru")) {
// skipping, Cyrillic chars not part of the validation yet
continue;
}
JLanguageTool lt = new JLanguageTool(lang);
List<Rule> rules = lt.getAllActiveRules();
for (Rule rule : rules) {
if (rule instanceof SpellingCheckRule) {
SpellingCheckRule sRule = (SpellingCheckRule) rule;
String file = sRule.getSpellingFileName();
if (JLanguageTool.getDataBroker().resourceExists(file) && !checked.contains(file)) {
System.out.println("Checking " + file);
CachingWordListLoader loader = new CachingWordListLoader();
List<String> words = loader.loadWords(file);
validateWords(words, file);
checked.add(file);
}
}
}
}
}
use of org.languagetool.rules.spelling.SpellingCheckRule in project languagetool by languagetool-org.
the class SpellIgnoreTest method testIgnore.
// code also used in http://wiki.languagetool.org/java-api
@Test
public void testIgnore() throws IOException {
String text = "This is a text with specialword and myotherword";
JLanguageTool lt = new JLanguageTool(new AmericanEnglish());
assertThat(lt.check(text).size(), is(2));
for (Rule rule : lt.getAllActiveRules()) {
if (rule instanceof SpellingCheckRule) {
List<String> wordsToIgnore = Arrays.asList("specialword", "myotherword");
((SpellingCheckRule) rule).addIgnoreTokens(wordsToIgnore);
}
}
assertThat(lt.check(text).size(), is(0));
}
use of org.languagetool.rules.spelling.SpellingCheckRule 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.rules.spelling.SpellingCheckRule in project languagetool by languagetool-org.
the class JLanguageToolTest method spellCheckerDemoCodeForHomepageWithAddedWords.
@Ignore("not a test, but used on http://wiki.languagetool.org/java-spell-checker")
@Test
public void spellCheckerDemoCodeForHomepageWithAddedWords() throws IOException {
JLanguageTool langTool = new JLanguageTool(new BritishEnglish());
for (Rule rule : langTool.getAllRules()) {
if (rule instanceof SpellingCheckRule) {
((SpellingCheckRule) rule).addIgnoreTokens(Arrays.asList("myspecialword", "anotherspecialword"));
}
}
List<RuleMatch> matches = langTool.check("These are myspecialword and anotherspecialword");
// => "0 matches"
System.out.println(matches.size() + " matches");
}
Aggregations