Search in sources :

Example 21 with AbstractPatternRule

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());
}
Also used : Query(org.apache.lucene.search.Query) AbstractPatternRule(org.languagetool.rules.patterns.AbstractPatternRule)

Example 22 with AbstractPatternRule

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) {
    }
}
Also used : AbstractPatternRule(org.languagetool.rules.patterns.AbstractPatternRule)

Aggregations

AbstractPatternRule (org.languagetool.rules.patterns.AbstractPatternRule)22 RuleMatch (org.languagetool.rules.RuleMatch)7 Rule (org.languagetool.rules.Rule)5 ArrayList (java.util.ArrayList)4 InputStream (java.io.InputStream)3 JLanguageTool (org.languagetool.JLanguageTool)3 PatternRuleLoader (org.languagetool.rules.patterns.PatternRuleLoader)3 ByteArrayInputStream (java.io.ByteArrayInputStream)2 IOException (java.io.IOException)2 HashSet (java.util.HashSet)2 Matcher (java.util.regex.Matcher)2 Pattern (java.util.regex.Pattern)2 Query (org.apache.lucene.search.Query)2 Test (org.junit.Test)2 Language (org.languagetool.Language)2 BitextRule (org.languagetool.rules.bitext.BitextRule)2 BufferedInputStream (java.io.BufferedInputStream)1 BufferedReader (java.io.BufferedReader)1 File (java.io.File)1 FileInputStream (java.io.FileInputStream)1