Search in sources :

Example 1 with Demo

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

the class ToolsTest method testSelectRules.

@Test
public void testSelectRules() {
    Demo demo = new Demo();
    expectDemoRuleId(Collections.emptySet(), Collections.emptySet(), Collections.emptySet(), Collections.emptySet(), false, demo);
    expectNotDemoRuleId(Collections.emptySet(), Collections.emptySet(), Collections.singleton("DEMO_RULE"), Collections.emptySet(), false, demo);
    expectNotDemoRuleId(Collections.singleton(CategoryIds.MISC), Collections.emptySet(), Collections.emptySet(), Collections.emptySet(), false, demo);
    // disable category, but enable rule:
    expectDemoRuleId(Collections.singleton(CategoryIds.MISC), Collections.emptySet(), Collections.emptySet(), Collections.singleton("DEMO_RULE"), false, demo);
    // now with enablesOnly=true:
    expectDemoRuleId(Collections.emptySet(), Collections.emptySet(), Collections.emptySet(), Collections.emptySet(), true, demo);
    expectNotDemoRuleId(Collections.emptySet(), Collections.emptySet(), Collections.singleton("DEMO_RULE"), Collections.emptySet(), true, demo);
    expectNotDemoRuleId(Collections.singleton(CategoryIds.MISC), Collections.emptySet(), Collections.emptySet(), Collections.emptySet(), true, demo);
    expectDemoRuleId(Collections.emptySet(), Collections.singleton(CategoryIds.MISC), Collections.emptySet(), Collections.emptySet(), true, demo);
    expectNotDemoRuleId(Collections.emptySet(), Collections.singleton(CategoryIds.CASING), Collections.emptySet(), Collections.emptySet(), true, demo);
}
Also used : Demo(org.languagetool.language.Demo) Test(org.junit.Test)

Example 2 with Demo

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

the class PatternRuleMatcherTest method testZeroMinOccurrencesWithSuggestion.

@Test
public void testZeroMinOccurrencesWithSuggestion() throws Exception {
    PatternToken patternTokenB = makeElement("b");
    patternTokenB.setMinOccurrence(0);
    // regex: a b? c
    List<PatternToken> patternTokens = Arrays.asList(makeElement("a"), patternTokenB, makeElement("c"));
    PatternRule rule = new PatternRule("", new Demo(), patternTokens, "my description", "<suggestion>\\1 \\2 \\3</suggestion>", "short message");
    PatternRuleMatcher matcher = new PatternRuleMatcher(rule, false);
    // we need to add this line to trigger proper replacement but I am not sure why :(
    rule.addSuggestionMatch(new Match(null, null, false, null, null, CaseConversion.NONE, false, false, IncludeRange.NONE));
    RuleMatch[] matches = getMatches("a b c", matcher);
    assertEquals(Arrays.asList("a b c"), matches[0].getSuggestedReplacements());
    RuleMatch[] matches2 = getMatches("a c", matcher);
    assertEquals(Arrays.asList("a c"), matches2[0].getSuggestedReplacements());
}
Also used : Demo(org.languagetool.language.Demo) RuleMatch(org.languagetool.rules.RuleMatch) RuleMatch(org.languagetool.rules.RuleMatch) Test(org.junit.Test)

Example 3 with Demo

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

the class PatternRuleXmlCreatorTest method testToXMLWithAntiPattern.

@Test
public void testToXMLWithAntiPattern() {
    PatternRuleId ruleId = new PatternRuleId("DEMO_RULE_ANTIPATTERN");
    PatternRuleXmlCreator creator = new PatternRuleXmlCreator();
    String xml = creator.toXML(ruleId, new Demo());
    assertTrue(xml.contains("  <antipattern>\n" + "    <token>bar</token>\n" + "    <token>,</token>\n" + "  </antipattern>\n"));
}
Also used : Demo(org.languagetool.language.Demo) Test(org.junit.Test)

Example 4 with Demo

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

the class MultiThreadedJLanguageToolTest method testShutdownException.

@Test
public void testShutdownException() throws IOException {
    MultiThreadedJLanguageTool tool = new MultiThreadedJLanguageTool(new Demo());
    getRuleMatchIds(tool);
    tool.shutdown();
    try {
        getRuleMatchIds(tool);
        fail("should have been rejected as the thread pool has been shut down");
    } catch (RejectedExecutionException ignore) {
    }
}
Also used : Demo(org.languagetool.language.Demo) RejectedExecutionException(java.util.concurrent.RejectedExecutionException) Test(org.junit.Test)

Example 5 with Demo

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

the class MatchTest method setUp.

//-- setup
@Before
public void setUp() throws Exception {
    tagger = new ManualTaggerAdapter(new ManualTagger(new ByteArrayInputStream(TEST_DATA.getBytes("UTF-8"))));
    synthesizer = new ManualSynthesizerAdapter(new ManualSynthesizer(new ByteArrayInputStream(TEST_DATA.getBytes("UTF-8"))));
    languageTool = new JLanguageTool(new Demo() {

        @Override
        public String getName() {
            return "TEST";
        }

        @Override
        public Synthesizer getSynthesizer() {
            return MatchTest.this.synthesizer;
        }

        @Override
        public Tagger getTagger() {
            return MatchTest.this.tagger;
        }
    });
}
Also used : Demo(org.languagetool.language.Demo) ManualTaggerAdapter(org.languagetool.tokenizers.ManualTaggerAdapter) ByteArrayInputStream(java.io.ByteArrayInputStream) JLanguageTool(org.languagetool.JLanguageTool) ManualSynthesizerAdapter(org.languagetool.synthesis.ManualSynthesizerAdapter) ManualTagger(org.languagetool.tagging.ManualTagger) ManualSynthesizer(org.languagetool.synthesis.ManualSynthesizer) Before(org.junit.Before)

Aggregations

Demo (org.languagetool.language.Demo)15 Test (org.junit.Test)14 ByteArrayInputStream (java.io.ByteArrayInputStream)1 RejectedExecutionException (java.util.concurrent.RejectedExecutionException)1 Before (org.junit.Before)1 JLanguageTool (org.languagetool.JLanguageTool)1 ChunkTag (org.languagetool.chunking.ChunkTag)1 RuleMatch (org.languagetool.rules.RuleMatch)1 ManualSynthesizer (org.languagetool.synthesis.ManualSynthesizer)1 ManualSynthesizerAdapter (org.languagetool.synthesis.ManualSynthesizerAdapter)1 ManualTagger (org.languagetool.tagging.ManualTagger)1 ManualTaggerAdapter (org.languagetool.tokenizers.ManualTaggerAdapter)1