Package org.languagetool.rules.patterns

Examples of org.languagetool.rules.patterns.Element


    assertEquals("RULE1", rule.getId());
  }

  public void testNegatedMatchAtSentenceStart() throws Exception {
    createIndex("How to move?");
    final Element negatedElement = new Element("Negated", false, false, false);
    negatedElement.setNegation(true);
    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());
View Full Code Here


    assertEquals("RULE1", rule.getId());
  }

  public void testWithOneElementWithException() throws Exception {
    createIndex("How to move back and fourth from linux to xmb?");
    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);
View Full Code Here

          List<Pattern> posPatterns = new ArrayList<>(andGroup.size());
          // get all the exceptions and attributes
          List<Element> allExceptions = new ArrayList<>();
          allExceptions.addAll(prevExceptions)// add all the exceptions from the next token with scope="previous"
          for (int a=0;a<andGroup.size();a++) {
            Element and = andGroup.get(a);
            List<Element> ex = and.getExceptionList();
            if (ex != null) {
              allExceptions.addAll(and.getExceptionList());
            }
            if (and.isReferenceElement()) {
              and = getReferenceElement(and,elements,examples)// gets the string for the element if it's a match token
            }
            String andPostag = and.getPOStag();
            String andToken = and.getString();
            tokenPatterns.add(Pattern.compile(andToken));
            if (andPostag != null) {
              if (and.isPOStagRegularExpression()) {
                posPatterns.add(Pattern.compile(andPostag));
              } else {
                posPatterns.add(Pattern.compile(Pattern.quote(andPostag)));
              }
             
View Full Code Here

    /**
     * Returns an element with the string set as the previously matched element
     */
    private Element getReferenceElement(Element e, List<Element> elements, ArrayList<String> examples) {
      int r = e.getMatch().getTokenRef();
      Element newElement = new Element(examples.get(r), elements.get(r).isCaseSensitive(), false, false);
      newElement.setNegation(e.getNegation());
      return newElement;
     
    }
View Full Code Here

      }
      List<Pattern> tokenPatterns = exceptionAttributes.get(0);
      List<Pattern> posPatterns = exceptionAttributes.get(1);
     
      for (int i=0;i<exceptions.size();i++) {
        Element curException = exceptions.get(i);
        if (isExampleOf(word,tokenPatterns.get(i),
            posPatterns.get(i),
            curException)) {
          return true;
        }
View Full Code Here

        if (!exceptionSet || tokenElement == null) {
          boolean tokenCase = caseSensitive;
          if (tokenLevelCaseSet) {
            tokenCase = tokenLevelCaseSensitive;
          }
          tokenElement = new Element(elements.toString(), tokenCase,
              regExpression, tokenInflected);
          tokenElement.setNegation(tokenNegated);
        } else {
          tokenElement.setStringElement(elements.toString());
        }
View Full Code Here

    }
  }

  public void testOverlapFilter() throws IOException {
    final Category category = new Category("test category");
    final List<Element> elements1 = Arrays.asList(new Element("one", true, false, false));
    final PatternRule rule1 = new PatternRule("id1", new English(), elements1, "desc1", "msg1", "shortMsg1");
    rule1.setSubId("1");
    rule1.setCategory(category);

    final List<Element> elements2 = Arrays.asList(new Element("one", true, false, false), new Element("two", true, false, false));
    final PatternRule rule2 = new PatternRule("id1", new English(), elements2, "desc2", "msg2", "shortMsg2");
    rule2.setSubId("2");
    rule2.setCategory(category);

    final JLanguageTool tool = new JLanguageTool(new English());
View Full Code Here

TOP

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

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.