use of org.languagetool.rules.patterns.AbstractPatternRule in project languagetool by languagetool-org.
the class PatternRuleQueryBuilderTest method testQueryBuilder.
public void testQueryBuilder() throws Exception {
String ruleXml = // match "How"
"<token skip='-1'>How</token>" + // match"you/[PRP]"
"<token postag='PRP'></token>" + // match "thin"
"<token skip='1'>thin</token>" + // match "this/[DT]"
"<token postag_regexp='yes' postag='JJ|DT'>this</token>" + // match "wonderful"
"<token regexp='yes' negate='yes'>bad|good</token>" + // match "idea"
"<token regexp='yes'>idea|proposal</token>";
AbstractPatternRule patternRule = makeRule(ruleXml);
PatternRuleQueryBuilder patternRuleQueryBuilder = new PatternRuleQueryBuilder(language, searcher);
Query query = patternRuleQueryBuilder.buildRelaxedQuery(patternRule);
assertEquals("+fieldLowercase:how +fieldLowercase:_pos_prp +fieldLowercase:thin " + "+spanNear([fieldLowercase:this, SpanMultiTermQueryWrapper(fieldLowercase:/_pos_(jj|dt)/)], 0, false) " + "+fieldLowercase:/idea|proposal/", query.toString());
}
use of org.languagetool.rules.patterns.AbstractPatternRule in project languagetool by languagetool-org.
the class PatternRuleQueryBuilderTest method testSpecialRegexSyntax.
public void testSpecialRegexSyntax() throws Exception {
AbstractPatternRule patternRule = makeRule("<token regexp='yes'>\\p{Punct}</token>", false);
PatternRuleQueryBuilder queryBuilder = new PatternRuleQueryBuilder(language, searcher);
try {
queryBuilder.buildRelaxedQuery(patternRule);
fail();
} catch (UnsupportedPatternRuleException ignore) {
}
}
Aggregations