Package org.languagetool.rules.patterns

Examples of org.languagetool.rules.patterns.Element


    }
  }

  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


          ArrayList<Pattern> posPatterns = new ArrayList<Pattern>(andGroup.size());
          // get all the exceptions and attributes
          ArrayList<Element> allExceptions = new ArrayList<Element>();
          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

     * @param examples
     * @return
     */
    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).getCaseSensitive(), false, false);
      newElement.setNegation(e.getNegation());
      return newElement;
     
    }
View Full Code Here

      }
      ArrayList<Pattern> tokenPatterns = exceptionAttributes.get(0);
      ArrayList<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

    final AnalyzedTokenReadings[] tokens = text.getTokensWithoutWhitespace();
    AnalyzedTokenReadings[] whTokens = text.getTokens();
    final int[] tokenPositions = new int[tokens.length + 1];
    final int patternSize = patternElements.size();
    final int limit = Math.max(0, tokens.length - patternSize + 1);
    Element elem = null;
    boolean changed = false;
    for (int i = 0; i < limit && !(sentStart && i > 0); i++) {
      boolean allElementsMatch = false;
      unifiedTokens = null;
      int matchingTokens = 0;
      int skipShiftTotal = 0;
      int firstMatchToken = -1;
      int prevSkipNext = 0;
      if (testUnification) {
        unifier.reset();
      }
      for (int k = 0; k < patternSize; k++) {
        final Element prevElement = elem;
        elem = patternElements.get(k);
        setupRef(firstMatchToken, elem, tokens);       
        final int nextPos = i + k + skipShiftTotal;
        prevMatched = false;
        if (prevSkipNext + nextPos >= tokens.length || prevSkipNext < 0) { // SENT_END?
View Full Code Here

      case FILTERALL:
        for (int i = 0; i < matchingTokens - startPositionCorrection
                + endPositionCorrection; i++) {
          final int position = text.getOriginalPosition(firstMatchToken
                  + correctedStPos + i);
          final Element myEl = patternElements.get(i+startPositionCorrection);
          final Match tmpMatchToken = new Match(myEl.getPOStag(), null,
                  true, myEl.getPOStag(), //myEl.isPOStagRegularExpression()
                  null, Match.CaseConversion.NONE, false, false,
                  Match.IncludeRange.NONE);
          tmpMatchToken.setToken(whTokens[position]);
          final String prevValue = whTokens[position].toString();
          final String prevAnot = whTokens[position]
View Full Code Here

      inAndGroup = false;
      andGroupCounter = 0;
      tokenCounter++;           
    } else if (qName.equals(TOKEN)) {
      if (!exceptionSet || tokenElement == null) {
        tokenElement = new Element(elements.toString(), caseSensitive,
            regExpression, tokenInflected);
        tokenElement.setNegation(tokenNegated);
      } else {
        tokenElement.setStringElement(elements.toString());
      }
View Full Code Here

    assertEquals("foo!", "foo!");
  }
 
  private class FakeRule extends PatternRule {
    public FakeRule() {
      super("FAKE_ID", Language.DEMO, Collections.singletonList(new Element("foo", true, false, false)),
              "My fake description", "Fake message", "Fake short message");
    }
View Full Code Here

  }

  public void testWithNewRule() throws Exception {
    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());
View Full Code Here

  }

  public void testWithRegexRule() throws Exception {
    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());
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.