use of org.languagetool.language.BritishEnglish in project languagetool by languagetool-org.
the class MorfologikBritishSpellerRuleTest method testMorfologikSpeller.
@Test
public void testMorfologikSpeller() throws IOException {
BritishEnglish language = new BritishEnglish();
MorfologikBritishSpellerRule rule = new MorfologikBritishSpellerRule(TestTools.getMessages("en"), language);
JLanguageTool langTool = new JLanguageTool(language);
// correct sentences:
assertEquals(0, rule.match(langTool.getAnalyzedSentence("This is an example: we get behaviour as a dictionary word.")).length);
assertEquals(0, rule.match(langTool.getAnalyzedSentence("Why don't we speak today.")).length);
//with doesn't
assertEquals(0, rule.match(langTool.getAnalyzedSentence("He doesn't know what to do.")).length);
//with diacritics
assertEquals(0, rule.match(langTool.getAnalyzedSentence("The entrée at the café.")).length);
//with an abbreviation:
assertEquals(0, rule.match(langTool.getAnalyzedSentence("This is my Ph.D. thesis.")).length);
assertEquals(0, rule.match(langTool.getAnalyzedSentence(",")).length);
assertEquals(0, rule.match(langTool.getAnalyzedSentence("123454")).length);
//incorrect sentences:
RuleMatch[] matches1 = rule.match(langTool.getAnalyzedSentence("Behavior"));
// check match positions:
assertEquals(1, matches1.length);
assertEquals(0, matches1[0].getFromPos());
assertEquals(8, matches1[0].getToPos());
assertEquals("Behaviour", matches1[0].getSuggestedReplacements().get(0));
assertEquals(1, rule.match(langTool.getAnalyzedSentence("aõh")).length);
assertEquals(0, rule.match(langTool.getAnalyzedSentence("a")).length);
//based on replacement pairs:
RuleMatch[] matches2 = rule.match(langTool.getAnalyzedSentence("He teached us."));
// check match positions:
assertEquals(1, matches2.length);
assertEquals(3, matches2[0].getFromPos());
assertEquals(10, matches2[0].getToPos());
assertEquals("taught", matches2[0].getSuggestedReplacements().get(0));
}
use of org.languagetool.language.BritishEnglish in project languagetool by languagetool-org.
the class JLanguageToolTest method spellCheckerDemoCodeForHomepage.
@Ignore("not a test, but used on http://wiki.languagetool.org/java-spell-checker")
@Test
public void spellCheckerDemoCodeForHomepage() throws IOException {
JLanguageTool langTool = new JLanguageTool(new BritishEnglish());
for (Rule rule : langTool.getAllRules()) {
if (!rule.isDictionaryBasedSpellingRule()) {
langTool.disableRule(rule.getId());
}
}
List<RuleMatch> matches = langTool.check("A speling error");
for (RuleMatch match : matches) {
System.out.println("Potential typo at characters " + match.getFromPos() + "-" + match.getToPos() + ": " + match.getMessage());
System.out.println("Suggested correction(s): " + match.getSuggestedReplacements());
}
}
use of org.languagetool.language.BritishEnglish in project languagetool by languagetool-org.
the class JLanguageToolTest method demoCodeForHomepage.
@Ignore("not a test, but used on http://wiki.languagetool.org/java-api")
@Test
public void demoCodeForHomepage() throws IOException {
JLanguageTool langTool = new JLanguageTool(new BritishEnglish());
// comment in to use statistical ngram data:
//langTool.activateLanguageModelRules(new File("/data/google-ngram-data"));
List<RuleMatch> matches = langTool.check("A sentence with a error in the Hitchhiker's Guide tot he Galaxy");
for (RuleMatch match : matches) {
System.out.println("Potential error at characters " + match.getFromPos() + "-" + match.getToPos() + ": " + match.getMessage());
System.out.println("Suggested correction(s): " + match.getSuggestedReplacements());
}
}
use of org.languagetool.language.BritishEnglish in project languagetool by languagetool-org.
the class BritishReplaceRuleTest method setUp.
@Before
public void setUp() throws Exception {
rule = new BritishReplaceRule(TestTools.getMessages("en"));
langTool = new JLanguageTool(new BritishEnglish());
}
use of org.languagetool.language.BritishEnglish in project languagetool by languagetool-org.
the class MorfologikBritishSpellerRuleTest method testSuggestions.
@Test
public void testSuggestions() throws IOException {
Language language = new BritishEnglish();
Rule rule = new MorfologikBritishSpellerRule(TestTools.getMessages("en"), language);
super.testNonVariantSpecificSuggestions(rule, language);
}
Aggregations