use of org.languagetool.rules.patterns.PatternRuleLoader in project languagetool by languagetool-org.
the class PatternRuleQueryBuilderTest method testCaseSensitive.
public void testCaseSensitive() throws Exception {
InputStream input = new ByteArrayInputStream(("<?xml version='1.0' encoding='UTF-8'?> <rules lang='en'> <category name='Test'>" + "<rule id='TEST_RULE_1' name='test_1'> <pattern case_sensitive='yes'><token>How</token></pattern> </rule>" + "<rule id='TEST_RULE_2' name='test_2'> <pattern case_sensitive='yes'><token>how</token>" + "</pattern> </rule>" + "<rule id='TEST_RULE_3' name='test_3'> <pattern><token>How</token></pattern> </rule>" + "<rule id='TEST_RULE_4' name='test_4'> <pattern><token>how</token></pattern> </rule>" + "</category> </rules>").getBytes());
PatternRuleLoader ruleLoader = new PatternRuleLoader();
List<AbstractPatternRule> rules = ruleLoader.getRules(input, "test.xml");
PatternRuleQueryBuilder patternRuleQueryBuilder = new PatternRuleQueryBuilder(language, searcher);
Query query1 = patternRuleQueryBuilder.buildRelaxedQuery(rules.get(0));
assertEquals(1, searcher.search(query1, 1000).totalHits);
Query query2 = patternRuleQueryBuilder.buildRelaxedQuery(rules.get(1));
assertEquals(0, searcher.search(query2, 1000).totalHits);
Query query3 = patternRuleQueryBuilder.buildRelaxedQuery(rules.get(2));
assertEquals(1, searcher.search(query3, 1000).totalHits);
Query query4 = patternRuleQueryBuilder.buildRelaxedQuery(rules.get(3));
assertEquals(1, searcher.search(query4, 1000).totalHits);
}
use of org.languagetool.rules.patterns.PatternRuleLoader in project languagetool by languagetool-org.
the class PatternRuleQueryBuilderTest method makeRule.
private AbstractPatternRule makeRule(String ruleXml, boolean caseSensitive) throws IOException {
StringBuilder sb = new StringBuilder();
sb.append("<?xml version='1.0' encoding='UTF-8'?>");
sb.append("<rules lang='en'> <category name='Test'> <rule id='TEST_RULE' name='test'>");
if (caseSensitive) {
sb.append("<pattern case_sensitive='yes'>");
} else {
sb.append("<pattern>");
}
sb.append(ruleXml);
sb.append("</pattern> </rule> </category> </rules>");
InputStream input = new ByteArrayInputStream(sb.toString().getBytes());
PatternRuleLoader ruleLoader = new PatternRuleLoader();
List<AbstractPatternRule> rules = ruleLoader.getRules(input, "test.xml");
assertEquals(1, rules.size());
return rules.get(0);
}
Aggregations