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);
}
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());
}
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"));
}
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) {
}
}
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;
}
});
}
Aggregations