Search in sources :

Example 31 with English

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

the class AtomFeedCheckerTest method testCheckManually.

@Ignore("Interactive use only - for testing the 'recent changes' XML we get from the API")
@Test
public void testCheckManually() throws IOException {
    AtomFeedChecker atomFeedChecker = new AtomFeedChecker(new English());
    CheckResult checkResult = atomFeedChecker.checkChanges(new FileInputStream("/home/dnaber/wiki.xml"));
    List<ChangeAnalysis> changeAnalysisList = checkResult.getCheckResults();
    for (ChangeAnalysis changeAnalysis : changeAnalysisList) {
        System.out.println(changeAnalysis.getTitle());
        for (WikipediaRuleMatch match : changeAnalysis.getRemovedMatches()) {
            System.out.println(" [-] " + match);
        }
        for (WikipediaRuleMatch match : changeAnalysis.getAddedMatches()) {
            System.out.println(" [+] " + match);
        }
        System.out.println("----------------------");
    }
}
Also used : English(org.languagetool.language.English) FileInputStream(java.io.FileInputStream) Ignore(org.junit.Ignore) Test(org.junit.Test)

Example 32 with English

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

the class JLanguageToolTest method testEnglish.

@Test
public void testEnglish() throws IOException {
    //more error-free sentences to deal with possible regressions
    if (System.getProperty("disableHardcodedTests") == null) {
        JLanguageTool lt = new JLanguageTool(new English());
        assertNoError("A test that should not give errors.", lt);
        assertNoError("As long as you have hope, a chance remains.", lt);
        assertNoError("A rolling stone gathers no moss.", lt);
        assertNoError("Hard work causes fitness.", lt);
        assertNoError("Gershwin overlays the slow blues theme from section B in the final “Grandioso.”", lt);
        assertNoError("Making ingroup membership more noticeable increases cooperativeness.", lt);
        assertNoError("Dog mushing is more of a sport than a true means of transportation.", lt);
        assertNoError("No one trusts him any more.", lt);
        assertNoError("A member of the United Nations since 1992, Azerbaijan was elected to membership in the newly established Human Rights Council by the United Nations General Assembly on May 9, 2006 (the term of office began on June 19, 2006).", lt);
        assertNoError("Anatomy and geometry are fused in one, and each does something to the other.", lt);
        assertNoError("Certain frogs that lay eggs underground have unpigmented eggs.", lt);
        assertNoError("It's a kind of agreement in which each party gives something to the other, Jack said.", lt);
        assertNoError("Later, you shall know it better.", lt);
        assertNoError("And the few must win what the many lose, for the opposite arrangement would not support markets as we know them at all, and is, in fact, unimaginable.", lt);
        assertNoError("He explained his errand, but without bothering much to make it plausible, for he felt something well up in him which was the reason why he had fled the army.", lt);
        assertNoError("I think it's better, and it's not a big deal.", lt);
        assertOneError("A test test that should give errors.", lt);
        assertOneError("I can give you more a detailed description.", lt);
        assertTrue(lt.getAllRules().size() > 1000);
        assertNoError("The sea ice is highly variable - frozen solid during cold, calm weather and broke...", lt);
        assertTrue(lt.getAllRules().size() > 3);
        assertOneError("I can give you more a detailed description.", lt);
        lt.disableRule("MORE_A_JJ");
        assertNoError("I can give you more a detailed description.", lt);
        assertOneError("I've go to go.", lt);
        lt.disableCategory(Categories.TYPOS.getId());
        assertNoError("I've go to go.", lt);
    }
}
Also used : AmericanEnglish(org.languagetool.language.AmericanEnglish) English(org.languagetool.language.English) BritishEnglish(org.languagetool.language.BritishEnglish) Test(org.junit.Test)

Example 33 with English

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

the class JLanguageToolTest method testWhitespace.

@Test
public void testWhitespace() throws IOException {
    JLanguageTool tool = new JLanguageTool(new English());
    AnalyzedSentence raw = tool.getRawAnalyzedSentence("Let's do a \"test\", do you understand?");
    AnalyzedSentence cooked = tool.getAnalyzedSentence("Let's do a \"test\", do you understand?");
    //test if there was a change
    assertFalse(raw.equals(cooked));
    //see if nothing has been deleted
    assertEquals(raw.getTokens().length, cooked.getTokens().length);
    int i = 0;
    for (AnalyzedTokenReadings atr : raw.getTokens()) {
        assertEquals(atr.isWhitespaceBefore(), cooked.getTokens()[i].isWhitespaceBefore());
        i++;
    }
}
Also used : AmericanEnglish(org.languagetool.language.AmericanEnglish) English(org.languagetool.language.English) BritishEnglish(org.languagetool.language.BritishEnglish) Test(org.junit.Test)

Example 34 with English

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

the class JLanguageToolTest method testAnalyzedSentence.

@Test
public void testAnalyzedSentence() throws IOException {
    JLanguageTool tool = new JLanguageTool(new English());
    //test soft-hyphen ignoring:
    assertEquals("<S> This[this/DT,B-NP-singular|E-NP-singular] " + "is[be/VBZ,B-VP] a[a/DT,B-NP-singular] " + "test­ed[tested/JJ,test/VBD,test/VBN,test­ed/null,I-NP-singular] " + "sentence[sentence/NN,E-NP-singular].[./.,</S>,O]", tool.getAnalyzedSentence("This is a test­ed sentence.").toString());
    //test paragraph ends adding
    assertEquals("<S> </S><P/> ", tool.getAnalyzedSentence("\n").toString());
}
Also used : AmericanEnglish(org.languagetool.language.AmericanEnglish) English(org.languagetool.language.English) BritishEnglish(org.languagetool.language.BritishEnglish) Test(org.junit.Test)

Example 35 with English

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

the class JLanguageToolTest method testParagraphRules.

@Test
public void testParagraphRules() throws IOException {
    JLanguageTool tool = new JLanguageTool(new English());
    //run normally
    List<RuleMatch> matches1 = tool.check("(This is an quote.\n It ends in the second sentence.");
    assertEquals(2, matches1.size());
    //run in a sentence-only mode
    List<RuleMatch> matches2 = tool.check("(This is an quote.\n It ends in the second sentence.", false, ParagraphHandling.ONLYNONPARA);
    assertEquals(1, matches2.size());
    assertEquals("EN_A_VS_AN", matches2.get(0).getRule().getId());
    //run in a paragraph mode - single sentence
    List<RuleMatch> matches3 = tool.check("(This is an quote.\n It ends in the second sentence.", false, ParagraphHandling.ONLYPARA);
    assertEquals(1, matches3.size());
    assertEquals("EN_UNPAIRED_BRACKETS", matches3.get(0).getRule().getId());
    //run in a paragraph mode - many sentences
    List<RuleMatch> matches4 = tool.check("(This is an quote.\n It ends in the second sentence.", true, ParagraphHandling.ONLYPARA);
    assertEquals(1, matches4.size());
    assertEquals("EN_UNPAIRED_BRACKETS", matches4.get(0).getRule().getId());
}
Also used : AmericanEnglish(org.languagetool.language.AmericanEnglish) English(org.languagetool.language.English) BritishEnglish(org.languagetool.language.BritishEnglish) Test(org.junit.Test)

Aggregations

English (org.languagetool.language.English)35 Test (org.junit.Test)19 JLanguageTool (org.languagetool.JLanguageTool)14 PatternRule (org.languagetool.rules.patterns.PatternRule)8 Rule (org.languagetool.rules.Rule)7 RuleMatch (org.languagetool.rules.RuleMatch)7 PatternToken (org.languagetool.rules.patterns.PatternToken)7 AmericanEnglish (org.languagetool.language.AmericanEnglish)6 BritishEnglish (org.languagetool.language.BritishEnglish)5 Before (org.junit.Before)4 Language (org.languagetool.Language)4 InputStream (java.io.InputStream)3 AnalyzedSentence (org.languagetool.AnalyzedSentence)3 AnalyzedTokenReadings (org.languagetool.AnalyzedTokenReadings)3 ByteArrayInputStream (java.io.ByteArrayInputStream)2 FileInputStream (java.io.FileInputStream)2 IOException (java.io.IOException)2 ArrayList (java.util.ArrayList)2 RAMDirectory (org.apache.lucene.store.RAMDirectory)2 Ignore (org.junit.Ignore)2