Search in sources :

Example 1 with AmericanEnglish

use of org.languagetool.language.AmericanEnglish 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));
}
Also used : SpellingCheckRule(org.languagetool.rules.spelling.SpellingCheckRule) JLanguageTool(org.languagetool.JLanguageTool) AmericanEnglish(org.languagetool.language.AmericanEnglish) SpellingCheckRule(org.languagetool.rules.spelling.SpellingCheckRule) Rule(org.languagetool.rules.Rule) Test(org.junit.Test)

Example 2 with AmericanEnglish

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

the class MorfologikAmericanSpellerRuleTest method testSuggestions.

@Test
public void testSuggestions() throws IOException {
    Language language = new AmericanEnglish();
    Rule rule = new MorfologikAmericanSpellerRule(TestTools.getMessages("en"), language);
    super.testNonVariantSpecificSuggestions(rule, language);
}
Also used : Language(org.languagetool.Language) AmericanEnglish(org.languagetool.language.AmericanEnglish) Rule(org.languagetool.rules.Rule) Test(org.junit.Test)

Example 3 with AmericanEnglish

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

the class JLanguageToolTest method testPositionsWithEnglishTwoLineBreaks.

@Test
public void testPositionsWithEnglishTwoLineBreaks() throws IOException {
    JLanguageTool tool = new JLanguageTool(new AmericanEnglish());
    List<RuleMatch> matches = tool.check("This sentence.\n\n" + "A sentence. A typoh.");
    assertEquals(1, matches.size());
    RuleMatch match = matches.get(0);
    assertEquals(2, match.getLine());
    // TODO: should actually be 15, as in testPositionsWithEnglish()
    assertEquals(14, match.getColumn());
}
Also used : AmericanEnglish(org.languagetool.language.AmericanEnglish) Test(org.junit.Test)

Example 4 with AmericanEnglish

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

the class JLanguageToolTest method testPositionsWithEnglish.

@Test
public void testPositionsWithEnglish() throws IOException {
    JLanguageTool tool = new JLanguageTool(new AmericanEnglish());
    List<RuleMatch> matches = tool.check("A sentence with no period\n" + "A sentence. A typoh.");
    assertEquals(1, matches.size());
    RuleMatch match = matches.get(0);
    assertEquals(1, match.getLine());
    assertEquals(15, match.getColumn());
}
Also used : AmericanEnglish(org.languagetool.language.AmericanEnglish) Test(org.junit.Test)

Example 5 with AmericanEnglish

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

the class ConfigurationTest method testSaveAndLoadConfigurationForManyLanguages.

@Test
public void testSaveAndLoadConfigurationForManyLanguages() throws Exception {
    File tempFile = File.createTempFile(ConfigurationTest.class.getSimpleName(), ".cfg");
    createConfiguration(tempFile, new AmericanEnglish());
    try {
        Configuration conf = new Configuration(tempFile.getParentFile(), tempFile.getName(), new AmericanEnglish());
        Set<String> disabledRuleIds = conf.getDisabledRuleIds();
        assertTrue(disabledRuleIds.contains("FOO1"));
        assertTrue(disabledRuleIds.contains("Foo2"));
        assertEquals(2, disabledRuleIds.size());
        Set<String> enabledRuleIds = conf.getEnabledRuleIds();
        assertTrue(enabledRuleIds.contains("enabledRule"));
        assertEquals(1, enabledRuleIds.size());
        //now change language
        conf = new Configuration(tempFile.getParentFile(), tempFile.getName(), new Belarusian());
        disabledRuleIds = conf.getDisabledRuleIds();
        assertTrue(disabledRuleIds.isEmpty());
        enabledRuleIds = conf.getEnabledRuleIds();
        assertTrue(enabledRuleIds.isEmpty());
        conf.setEnabledRuleIds(new HashSet<>(Arrays.asList("enabledBYRule")));
        conf.saveConfiguration(new Belarusian());
        //and back...
        conf = new Configuration(tempFile.getParentFile(), tempFile.getName(), new AmericanEnglish());
        disabledRuleIds = conf.getDisabledRuleIds();
        assertTrue(disabledRuleIds.contains("FOO1"));
        assertTrue(disabledRuleIds.contains("Foo2"));
        assertEquals(2, disabledRuleIds.size());
        enabledRuleIds = conf.getEnabledRuleIds();
        assertTrue(enabledRuleIds.contains("enabledRule"));
        assertEquals(1, enabledRuleIds.size());
    } finally {
        tempFile.delete();
    }
}
Also used : AmericanEnglish(org.languagetool.language.AmericanEnglish) Belarusian(org.languagetool.language.Belarusian) File(java.io.File) Test(org.junit.Test)

Aggregations

AmericanEnglish (org.languagetool.language.AmericanEnglish)10 Test (org.junit.Test)7 Rule (org.languagetool.rules.Rule)4 JLanguageTool (org.languagetool.JLanguageTool)3 Language (org.languagetool.Language)3 SpellingCheckRule (org.languagetool.rules.spelling.SpellingCheckRule)2 StringTools.readerToString (org.languagetool.tools.StringTools.readerToString)2 BufferedReader (java.io.BufferedReader)1 File (java.io.File)1 InputStreamReader (java.io.InputStreamReader)1 Before (org.junit.Before)1 TabBitextReader (org.languagetool.bitext.TabBitextReader)1 Belarusian (org.languagetool.language.Belarusian)1 RuleMatch (org.languagetool.rules.RuleMatch)1 BitextRule (org.languagetool.rules.bitext.BitextRule)1 AbstractPatternRule (org.languagetool.rules.patterns.AbstractPatternRule)1