public String getStringForRuleString()

in ruta-ep-textruler/src/main/java/org/apache/uima/ruta/textruler/learner/lp2/LP2RuleItem.java [176:262]


  public String getStringForRuleString(TextRulerRule rule, MLRuleItemType type,
          int numberInPattern, int patternSize, int numberInRule, int ruleSize, int slotIndex) {

    String result = "";
    LP2Rule lp2Rule = (LP2Rule) rule;
    boolean isMarkingItem = (rule != null)
            && (((rule.getTarget().type == MLTargetType.SINGLE_RIGHT_BOUNDARY)
                    && (type == MLRuleItemType.PREFILLER) && (numberInPattern == patternSize - 1)) || ((rule
                    .getTarget().type == MLTargetType.SINGLE_LEFT_BOUNDARY)
                    && (type == MLRuleItemType.POSTFILLER) && (numberInPattern == 0)));

    ArrayList<String> constraints = new ArrayList<String>();

    String anchor = null;

    if (wordConstraint == null)
      anchor = "ANY";
    else {
      if (wordConstraint.isRegExpConstraint()) {
        anchor = wordConstraint.typeShortName();
        constraints.add("REGEXP(\"" + wordConstraint + "\")");
      } else
        anchor = wordConstraint.toString();
    }

    if (isMarkingItem && lp2Rule.isContextualRule())
      constraints.add("-IS(" + ((TextRulerSingleSlotRule) rule).getMarkName() + ")");

    if (contextConstraint != null)
      constraints.add(contextConstraint.toString());

    MLLP2OtherConstraint anchorConstraint = null;
    if (wordConstraint == null) {

      // prefer the basic Ruta constraint as the anchor
      anchorConstraint = getTMBasicTypeTokenConstraint(); // returns null
      // if we don't
      // have one...

      if (anchorConstraint == null) {
        for (MLLP2OtherConstraint c : otherConstraints)
          if (c.canBeAnchorConstraint()) {
            anchorConstraint = c;
            break;
          }
      }
      for (MLLP2OtherConstraint oc : otherConstraints) {
        if (oc != anchorConstraint) {
          if (oc.canBeAnchorConstraint())
            constraints.add("IS(" + oc + ")");
          else
            constraints.add("PARTOF(" + oc + ")");
        }
      }
      if (anchorConstraint != null)
        anchor = anchorConstraint.toString();
    }

    if (constraints.size() > 0) {
      String cStr = "";
      for (String constraintStr : constraints) {
        if (cStr.length() > 0)
          cStr += ", ";
        cStr += constraintStr;
      }
      result += "{" + cStr;
    }

    if ((rule != null)
            && (((rule.getTarget().type == MLTargetType.SINGLE_RIGHT_BOUNDARY)
                    && (type == MLRuleItemType.PREFILLER) && (numberInPattern == patternSize - 1)) || ((rule
                    .getTarget().type == MLTargetType.SINGLE_LEFT_BOUNDARY)
                    && (type == MLRuleItemType.POSTFILLER) && (numberInPattern == 0)))) {
      // result +=
      // "(MARKONCE, "+((TextRulerSingleSlotRule)rule).getMarkName()+", "+(numberInRule+1);
      if (constraints.size() == 0)
        result += "{";
      result += "->MARKONCE(" + ((TextRulerSingleSlotRule) rule).getMarkName() + ")";
      if (lp2Rule.isContextualRule())
        result += ", ASSIGN(redoContextualRules, true)";
      result += "}";
    } else {
      if (constraints.size() != 0)
        result += "}";
    }
    return anchor + result;
  }