Package org.apache.uima.ruta.textruler.core

Examples of org.apache.uima.ruta.textruler.core.TextRulerRulePattern


      return "<no results yet>";
    String result = getFileHeaderString(true) + "DECLARE wien_tail;\n" + "DECLARE wien_rulemark;\n"
            + "DECLARE wien_content;\n" + "BOOLEAN wien_redo;\n\n"
            + "// tail/head/content area stuff:\n";

    TextRulerRulePattern hCopy = hPattern.copy();

    ((WienRuleItem) hCopy.get(0)).addCondition("-PARTOF(wien_content)");
    result += hCopy + " ALL*?{->MARK(wien_content)};\n";

    TextRulerRulePattern tCopy = tPattern.copy();
    ((WienRuleItem) tCopy.get(0)).addCondition("PARTOF(wien_content)");

    result += tCopy + "{->MARK(wien_tail";
    if (tPattern.size() > 1)
      result += ", 1, " + tPattern.size();
    result += ")};\n\n";
View Full Code Here


    int foundSlotNumber = -1; // debug info
    String foundSlotPattern = "";
    int termNumber = term.getTermNumberInExample();
    // determine, where this term is located relatively to the slots we
    // have...
    TextRulerRulePattern targetPattern = null;
    TextRulerRulePattern previousSlotPostFillerPattern = null;
    for (int i = 0; i < newRule.getPatterns().size(); i++) {
      TextRulerSlotPattern slotPattern = newRule.getPatterns().get(i);
      WhiskRuleItem it = (WhiskRuleItem) slotPattern.preFillerPattern.lastItem(); // look at the
      // prefiller
      // pattern
View Full Code Here

    for (int leftI = leftStart; leftI <= leftCount; leftI++)
      for (int rightI = rightStart; rightI <= rightCount; rightI++) {
        RapierRule newRule = strippedRule.copy();
        if (leftI > 0) {
          TextRulerRulePattern thePattern = null;
          if (leftType == 1)
            thePattern = newRule.getPreFillerPattern();
          else if (leftType == 2)
            thePattern = newRule.getFillerPattern();
          else if (leftType == 3)
            thePattern = newRule.getPostFillerPattern();
          for (int i = 0; i < leftI; i++) {
            RapierRuleItem theItem = left.copy();
            theItem.setListLen(0); // remove List-Character but add
            // listI copies instead!!
            thePattern.add(0, theItem);
          }
        }
        if (rightI > 0) {
          TextRulerRulePattern thePattern = null;
          if (rightType == 1)
            thePattern = newRule.getPostFillerPattern();
          else if (rightType == 2)
            thePattern = newRule.getFillerPattern();
          else if (rightType == 3)
            thePattern = newRule.getPreFillerPattern();
          for (int i = 0; i < rightI; i++) {
            RapierRuleItem theItem = right.copy();
            theItem.setListLen(0); // remove List-Character but add
            // listI copies instead!!
            thePattern.add(theItem);
          }
        }
        newRule.setNeedsCompile(true);
        if (newRule.totalItemCount() > 0) {
          // TextRulerToolkit.log(newRule.getRuleString());
View Full Code Here

    }
    if (slotIndex < 0) // we didn't even find the item in our rule ?! how
      // can this happen ?
      return null;

    TextRulerRulePattern currentPattern = getPattern(slotIndex, patternIndex);
    while (currentPattern != null) {
      int startIndex = currentPattern.indexOf(item); // this is only >= 0
      // for the first
      // pattern...
      if (!goToLeft) // walk forward...
      {
        int startSearchFromIndex = startIndex + 1;
        if (startSearchFromIndex < currentPattern.size())
          return (KEPRuleItem) currentPattern.get(startSearchFromIndex);
        else // skip to next pattern
        {
          patternIndex++;
          if (patternIndex > 2) {
            patternIndex = 0;
            slotIndex++;
            if (slotIndex >= slotPatterns.size())
              return null; // not found!
          }
          currentPattern = getPattern(slotIndex, patternIndex);
        }
      } else {
        int startSearchFromIndex = startIndex >= 0 ? startIndex - 1 : currentPattern.size() - 1;
        if (startSearchFromIndex >= 0 && currentPattern.size() > 0)
          return (KEPRuleItem) currentPattern.get(startSearchFromIndex);
        else // skip to previous pattern
        {
          patternIndex--;
          if (patternIndex < 0) {
            patternIndex = 2;
View Full Code Here

    }
  }

  protected List<LP2Rule> generalizeRule(LP2Rule baseRule) {
    List<LP2Rule> result = new ArrayList<LP2Rule>();
    TextRulerRulePattern rulePattern = new TextRulerRulePattern();
    TextRulerRulePattern prePattern = baseRule.getPreFillerPattern();

    for (int i = prePattern.size() - 1; i >= 0; i--) // we have to reverse
    // the order again!
    {
      rulePattern.add(prePattern.get(i));
    }
    rulePattern.addAll(baseRule.getPostFillerPattern());

    recursiveGeneralizeRule(baseRule, rulePattern, new TextRulerRulePattern(), result);
    TextRulerToolkit.log("GENERALIZATIONS: " + result.size());

    for (LP2Rule r : result)
      removeOutermostWildCardItemsFromRule(r);
View Full Code Here

    }
    if (slotIndex < 0) // we didn't even find the item in our rule ?! how
      // can this happen ?
      return null;

    TextRulerRulePattern currentPattern = getPattern(slotIndex, patternIndex);
    while (currentPattern != null) {
      int startIndex = currentPattern.indexOf(item); // this is only >= 0
      // for the first
      // pattern...
      if (!goToLeft) // walk forward...
      {
        int startSearchFromIndex = startIndex + 1;
        if (startSearchFromIndex < currentPattern.size())
          return (WhiskRuleItem) currentPattern.get(startSearchFromIndex);
        else // skip to next pattern
        {
          patternIndex++;
          if (patternIndex > 2) {
            patternIndex = 0;
            slotIndex++;
            if (slotIndex >= slotPatterns.size())
              return null; // not found!
          }
          currentPattern = getPattern(slotIndex, patternIndex);
        }
      } else {
        int startSearchFromIndex = startIndex >= 0 ? startIndex - 1 : currentPattern.size() - 1;
        if (startSearchFromIndex >= 0 && currentPattern.size() > 0)
          return (WhiskRuleItem) currentPattern.get(startSearchFromIndex);
        else // skip to previous pattern
        {
          patternIndex--;
          if (patternIndex < 0) {
            patternIndex = 2;
View Full Code Here

    // now we have patternSize lists of possible generalizations, one list
    // per original pattern item pair of
    // pattern1 and pattern2. we now have to build all possible
    // combinations. Each combination is a
    // new pattern
    recursiveBuildAllRuleItemCombinations(generalizationTable, 0, new TextRulerRulePattern(),
            resultList);
    return resultList;
  }
View Full Code Here

  private static void recursiveBuildAllRuleItemCombinations(
          ArrayList<ArrayList<TextRulerRuleItem>> table, int curIndex,
          TextRulerRulePattern currentPattern, ArrayList<TextRulerRulePattern> resultPatterns) {
    if (curIndex >= table.size()) {
      // make a deep copy of the current pattern:
      TextRulerRulePattern copy = new TextRulerRulePattern();
      for (TextRulerRuleItem item : currentPattern)
        copy.add(item.copy());
      resultPatterns.add(copy);
    } else {
      for (TextRulerRuleItem item : table.get(curIndex)) {
        currentPattern.add(item);
        recursiveBuildAllRuleItemCombinations(table, curIndex + 1, currentPattern, resultPatterns);
View Full Code Here

      TextRulerToolkit.log("ERROR! CALL getGeneralizationsForRuleItemPatternsOfEqualSize instead!");
      if (TextRulerToolkit.DEBUG)
        return null;
    }

    TextRulerRulePattern longerPattern = pattern1;
    TextRulerRulePattern shorterPattern = pattern2;
    if (pattern2.size() > pattern1.size()) {
      longerPattern = pattern2;
      shorterPattern = pattern1;
    }

    if (longerPattern.size() <= 1 || shorterPattern.size() <= 1) {
      // Special case 1: one of the pattern terms list is empty AND
      // special case 2: one has only ONE element
      if (longerPattern.size() + shorterPattern.size() == 0) {
        TextRulerToolkit.log("ERROR !! BOTH PATTERNS ARE EMPTY!");
        if (TextRulerToolkit.DEBUG)
          return null;
      }

      // get all possible generalizations of the two patterns. result of
      // each generalization is ONE rule item, so we
      // don't use TextRulerRulePattern here since this IS NOT a rule
      // pattern! it's a list of possible generalizations:
      ArrayList<TextRulerRuleItem> generalizations = getGeneralizationsForRuleItemLists(
              longerPattern, shorterPattern);
      // create a one element result pattern for each:
      for (TextRulerRuleItem item : generalizations) {
        TextRulerRulePattern p = new TextRulerRulePattern();
        p.add(item);
        resultList.add(p);
      }
    }
    // else SPECIAL CASE 3 // TODO make those values configurable ?
    else if (((longerPattern.size() - shorterPattern.size()) > 6) || (longerPattern.size() > 10)) {
      int resultListLen1 = 0;
      for (TextRulerRuleItem rt : shorterPattern)
        resultListLen1 += ((RapierRuleItem) rt).isListItem() ? ((RapierRuleItem) rt).listLen() : 1;
      int resultListLen2 = 0;
      for (TextRulerRuleItem rt : longerPattern)
        resultListLen2 += ((RapierRuleItem) rt).isListItem() ? ((RapierRuleItem) rt).listLen() : 1;

      RapierRuleItem singleItem = new RapierRuleItem();
      singleItem.setListLen(resultListLen1 > resultListLen2 ? resultListLen1 : resultListLen2);
      TextRulerRulePattern singleItemPattern = new TextRulerRulePattern();
      singleItemPattern.add(singleItem);
      resultList.add(singleItemPattern);
    } else { // sizes are different and both > 1
      // create all possible generalization combinations, that is: how can
      // we map elements of the shorter pattern
      // to the ones of the longer pattern and then generalize each
View Full Code Here

        expandedRules.add(rule);
      }
    } else {
      expanding = false;
      for (KEPRule eachRule : rules) {
        TextRulerRulePattern inFiller = eachRule.getInFiller();
        KEPRuleItem lastItem = (KEPRuleItem) inFiller.get(inFiller.size() - 1);
        int end = lastItem.getEnd();
        if (end >= e.getAnnotation().getEnd()) {
          if (!expandedRules.contains(eachRule)) {
            expandedRules.add(eachRule);
          }
View Full Code Here

TOP

Related Classes of org.apache.uima.ruta.textruler.core.TextRulerRulePattern

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.