Search in sources :

Example 1 with BritishEnglish

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));
}
Also used : BritishEnglish(org.languagetool.language.BritishEnglish) RuleMatch(org.languagetool.rules.RuleMatch) JLanguageTool(org.languagetool.JLanguageTool) Test(org.junit.Test)

Example 2 with BritishEnglish

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());
    }
}
Also used : BritishEnglish(org.languagetool.language.BritishEnglish) SpellingCheckRule(org.languagetool.rules.spelling.SpellingCheckRule) PatternRule(org.languagetool.rules.patterns.PatternRule) Ignore(org.junit.Ignore) Test(org.junit.Test)

Example 3 with BritishEnglish

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());
    }
}
Also used : BritishEnglish(org.languagetool.language.BritishEnglish) Ignore(org.junit.Ignore) Test(org.junit.Test)

Example 4 with BritishEnglish

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());
}
Also used : BritishEnglish(org.languagetool.language.BritishEnglish) JLanguageTool(org.languagetool.JLanguageTool) Before(org.junit.Before)

Example 5 with 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);
}
Also used : BritishEnglish(org.languagetool.language.BritishEnglish) Language(org.languagetool.Language) Rule(org.languagetool.rules.Rule) Test(org.junit.Test)

Aggregations

BritishEnglish (org.languagetool.language.BritishEnglish)6 Test (org.junit.Test)5 Ignore (org.junit.Ignore)3 JLanguageTool (org.languagetool.JLanguageTool)2 PatternRule (org.languagetool.rules.patterns.PatternRule)2 SpellingCheckRule (org.languagetool.rules.spelling.SpellingCheckRule)2 Before (org.junit.Before)1 Language (org.languagetool.Language)1 Rule (org.languagetool.rules.Rule)1 RuleMatch (org.languagetool.rules.RuleMatch)1