Package org.languagetool.rules.patterns

Examples of org.languagetool.rules.patterns.PatternRule


  private List<String> getRuleMatchIds(List<RuleMatch> ruleMatches) {
    final List<String> ids = new ArrayList<>();
    for (RuleMatch ruleMatch : ruleMatches) {
      if (ruleMatch.getRule() instanceof PatternRule) {
        final PatternRule patternRule = (PatternRule) ruleMatch.getRule();
        ids.add(getFullId(patternRule));
      }
    }
    return ids;
  }
View Full Code Here


    int ruleCount = 0;
    try (Indexer indexer = new Indexer(directory, lt.getLanguage())) {
      final List<Rule> rules = lt.getAllActiveRules();
      for (Rule rule : rules) {
        if (rule instanceof PatternRule && !rule.isDefaultOff()) {
          final PatternRule patternRule = (PatternRule) rule;
          final List<IncorrectExample> incorrectExamples = rule.getIncorrectExamples();
          final Document doc = new Document();
          final FieldType idType = new FieldType();
          idType.setStored(true);
          idType.setTokenized(false);
View Full Code Here

  public void testForDebugging() throws Exception {
    // Note that the second sentence ends with "lid" instead of "lids" (the inflated one)
    //createIndex("I thin so");
    useRealIndex();
    German language = new German();
    PatternRule rule = getFirstRule("I_THIN", language);
    SearcherResult searcherResult = errorSearcher.findRuleMatchesOnIndex(rule, language);
    System.out.println("Matches: " + searcherResult.getMatchingSentences());
  }
View Full Code Here

    createIndex("How to move back and fourth from linux to xmb?");
    final List<Element> elements = Arrays.asList(
        new Element("move", false, false, false),
        new Element("back", false, false, false)
        );
    final PatternRule rule1 = new PatternRule("RULE1", new English(), elements, "desc", "msg", "shortMsg");
    final Searcher errorSearcher = new Searcher(directory);
    final SearcherResult searcherResult = errorSearcher.findRuleMatchesOnIndex(rule1, new English());
    assertEquals(1, searcherResult.getCheckedSentences());
    assertEquals(1, searcherResult.getMatchingSentences().size());
    final List<RuleMatch> ruleMatches = searcherResult.getMatchingSentences().get(0).getRuleMatches();
View Full Code Here

    createIndex("How to move back and fourth from linux to xmb?");
    final List<Element> elements = Arrays.asList(
        new Element("move", false, false, false),
        new Element("forth|back", false, true, false)
        );
    final PatternRule rule1 = new PatternRule("RULE1", new English(), elements, "desc", "msg", "shortMsg");
    final Searcher errorSearcher = new Searcher(directory);
    final SearcherResult searcherResult = errorSearcher.findRuleMatchesOnIndex(rule1, new English());
    assertEquals(1, searcherResult.getCheckedSentences());
    assertEquals(1, searcherResult.getMatchingSentences().size());
    final List<RuleMatch> ruleMatches = searcherResult.getMatchingSentences().get(0).getRuleMatches();
View Full Code Here

    final List<Element> elements1 = Arrays.asList(
        new Element("Bleed", false, false, false),
        new Element("'", false, false, false),
        new Element("s", false, false, false)
        );
    final PatternRule rule1 = new PatternRule("RULE1", new English(), elements1, "desc", "msg", "shortMsg");

    final List<Element> elements2 = Arrays.asList(
        new Element("Bleed", false, false, false),
        new Element("'", false, false, false),
        new Element("x", false, false, false)
        );
    final PatternRule rule2 = new PatternRule("RULE", new English(), elements2, "desc", "msg", "shortMsg");

    final SearcherResult searcherResult1 = errorSearcher.findRuleMatchesOnIndex(rule1, new English());
    assertEquals(1, searcherResult1.getMatchingSentences().size());
    final List<RuleMatch> ruleMatches = searcherResult1.getMatchingSentences().get(0).getRuleMatches();
    assertEquals(1, ruleMatches.size());
View Full Code Here

    exceptionElem.setStringPosException("exception", false, false, false, false, false, "POS", false, false);
    final List<Element> elements = Arrays.asList(
        new Element("move", false, false, false),
        exceptionElem
        );
    final PatternRule rule1 = new PatternRule("RULE1", new English(), elements, "desc", "msg", "shortMsg");
    final Searcher errorSearcher = new Searcher(directory);
    final SearcherResult searcherResult = errorSearcher.findRuleMatchesOnIndex(rule1, new English());
    assertEquals(1, searcherResult.getCheckedSentences());
    assertEquals(1, searcherResult.getMatchingSentences().size());
    final List<RuleMatch> ruleMatches = searcherResult.getMatchingSentences().get(0).getRuleMatches();
View Full Code Here

    final List<Element> elements = Arrays.asList(
        negatedElement,
        new Element("How", false, false, false)
        );
    final Searcher errorSearcher = new Searcher(directory);
    final PatternRule rule1 = new PatternRule("RULE1", new English(), elements, "desc", "msg", "shortMsg");
    final SearcherResult searcherResult = errorSearcher.findRuleMatchesOnIndex(rule1, new English());
    assertEquals(1, searcherResult.getCheckedSentences());
    assertEquals(1, searcherResult.getMatchingSentences().size());
    final List<RuleMatch> ruleMatches = searcherResult.getMatchingSentences().get(0).getRuleMatches();
    assertEquals(1, ruleMatches.size());
View Full Code Here

    final Element exceptionElem = new Element("", false, true, false);
    exceptionElem.setStringPosException("exception", false, false, false, false, false, "POS", false, false);
    final List<Element> elements = Arrays.asList(
        exceptionElem
        );
    final PatternRule rule1 = new PatternRule("RULE1", new English(), elements, "desc", "msg", "shortMsg");
    final Searcher errorSearcher = new Searcher(directory);
    try {
      errorSearcher.findRuleMatchesOnIndex(rule1, new English());
      fail();
    } catch (UnsupportedPatternRuleException expected) {
View Full Code Here

      + "<token skip='1'>thin</token>" // match "thin"
      + "<token postag_regexp='yes' postag='JJ|DT'>this</token>" // match "this/[DT]"
      + "<token regexp='yes' negate='yes'>bad|good</token>" // match "wonderful"
      + "<token regexp='yes'>idea|proposal</token>"; // match "idea"

    final PatternRule patternRule = makeRule(ruleXml);
    final PatternRuleQueryBuilder patternRuleQueryBuilder = new PatternRuleQueryBuilder(language);
    final 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());
View Full Code Here

TOP

Related Classes of org.languagetool.rules.patterns.PatternRule

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.