Examples of EvaluatedCondition


Examples of org.apache.uima.ruta.rule.EvaluatedCondition

  public EvaluatedCondition eval(AnnotationFS annotation, RuleElement element,
          RutaStream stream, InferenceCrowd crowd) {
    if (!isWorkingOnList()) {
      Type givenType = type.getType(element.getParent());
      boolean result = check(stream, annotation, givenType);
      return new EvaluatedCondition(this, result);
    } else {
      boolean result = false;
      List<Type> types = getList().getList(element.getParent());
      for (Type t : types) {
        result |= check(stream, annotation, t);
        if (result) {
          break;
        }
      }
      return new EvaluatedCondition(this, result);
    }
  }
View Full Code Here

Examples of org.apache.uima.ruta.rule.EvaluatedCondition

    if (var != null) {
      element.getParent().getEnvironment().setVariableValue(var, score);
    }
    boolean value = score >= min.getDoubleValue(element.getParent())
            && score <= max.getDoubleValue(element.getParent());
    return new EvaluatedCondition(this, value);
  }
View Full Code Here

Examples of org.apache.uima.ruta.rule.EvaluatedCondition

  @Override
  public EvaluatedCondition eval(AnnotationFS annotation, RuleElement element,
          RutaStream stream, InferenceCrowd crowd) {
    AbstractRutaCondition cond = conditions.get(0);
    crowd.beginVisit(cond, null);
    EvaluatedCondition eval = cond.eval(annotation, element, stream, crowd);
    crowd.endVisit(cond, null);
    return new EvaluatedCondition(this, !eval.isValue(), eval);
  }
View Full Code Here

Examples of org.apache.uima.ruta.rule.EvaluatedCondition

    RutaBasic beginAnchor = stream.getBeginAnchor(annotation.getBegin());
    RutaBasic endAnchor = stream.getEndAnchor(annotation.getEnd());
    if (beginAnchor == null || endAnchor == null || !beginAnchor.isPartOf(t)
            || !endAnchor.isPartOf(t)) {
      return new EvaluatedCondition(this, false);
    }

    boolean relatively = relative == null ? true : relative.getBooleanValue(element.getParent());

    FSIterator<AnnotationFS> iterator = stream.getCas().getAnnotationIndex(t).iterator(beginAnchor);
    if (!iterator.isValid()) {
      iterator.moveToNext();
    }
    if (!iterator.isValid()) {
      iterator.moveToLast();
    }
    AnnotationFS window = null;
    while (iterator.isValid()) {
      AnnotationFS annotationFS = iterator.get();
      if (annotationFS.getBegin() <= annotation.getBegin()
              && annotationFS.getEnd() >= annotation.getEnd()) {
        window = annotationFS;
        break;
      }
      iterator.moveToPrevious();
    }

    List<Type> targetTypes = new ArrayList<Type>();
    if (element instanceof RutaRuleElement) {
      RutaRuleElement re = (RutaRuleElement) element;
      targetTypes.addAll(re.getMatcher().getTypes(element.getParent(), stream));
    } else {
      targetTypes.add(annotation.getType());
    }

    if (window == null) {
      return new EvaluatedCondition(this, false);
    }
    int integerValue = position.getIntegerValue(element.getParent());
    if (relatively) {
      int counter = 0;
      List<RutaBasic> inWindow = stream.getBasicsInWindow(window);
      for (RutaBasic each : inWindow) {
        if (beginsWith(each, targetTypes)) {
          counter++;
          if (counter == integerValue) {
            if (each.getBegin() == beginAnchor.getBegin()) {
              return new EvaluatedCondition(this, true);
            } else {
              return new EvaluatedCondition(this, false);
            }
          } else if (counter > integerValue) {
            return new EvaluatedCondition(this, false);
          }
        }
      }
      return new EvaluatedCondition(this, false);
    } else {
      int counter = 0;
      List<RutaBasic> inWindow = stream.getBasicsInWindow(window);
      for (RutaBasic each : inWindow) {
        counter++;
        boolean beginsWith = beginsWith(each, targetTypes);
        if (each.getBegin() == beginAnchor.getBegin() && beginsWith && counter == integerValue) {
          return new EvaluatedCondition(this, true);
        } else if (counter > integerValue) {
          return new EvaluatedCondition(this, false);
        }
      }
      return new EvaluatedCondition(this, false);
    }
  }
View Full Code Here

Examples of org.apache.uima.ruta.rule.EvaluatedCondition

  public EvaluatedCondition eval(AnnotationFS annotation, RuleElement element,
          RutaStream stream, InferenceCrowd crowd) {
    if (!isWorkingOnList()) {
      Type t = type.getType(element.getParent());
      boolean result = check(annotation, stream, t);
      return new EvaluatedCondition(this, result);
    } else {
      boolean result = false;
      List<Type> types = getList().getList(element.getParent());
      for (Type t : types) {
        result |= check(annotation, stream, t);
        if (result == true) {
          break;
        }
      }
      return new EvaluatedCondition(this, result);
    }
  }
View Full Code Here

Examples of org.apache.uima.ruta.rule.EvaluatedCondition

    if (stringExpr != null) {
      String value = annotation.getStringValue(featureByBaseName);
      String string = stringExpr.getStringValue(element.getParent());
      boolean result = string != null && string.equals(value);
      return new EvaluatedCondition(this, result);
    } else if (numberExpr != null) {
      String range = featureByBaseName.getRange().getName();
      boolean result = false;
      if (range.equals(UIMAConstants.TYPE_INTEGER)) {
        int value = annotation.getIntValue(featureByBaseName);
        int v = numberExpr.getIntegerValue(element.getParent());
        result = value == v;
      } else if (range.equals(UIMAConstants.TYPE_DOUBLE)) {
        double value = annotation.getDoubleValue(featureByBaseName);
        double v = numberExpr.getDoubleValue(element.getParent());
        result = value == v;
      } else if (range.equals(UIMAConstants.TYPE_FLOAT)) {
        float value = annotation.getFloatValue(featureByBaseName);
        float v = numberExpr.getFloatValue(element.getParent());
        result = value == v;
      } else if (range.equals(UIMAConstants.TYPE_BYTE)) {
        byte value = annotation.getByteValue(featureByBaseName);
        byte v = (byte) numberExpr.getIntegerValue(element.getParent());
        result = value == v;
      } else if (range.equals(UIMAConstants.TYPE_SHORT)) {
        short value = annotation.getShortValue(featureByBaseName);
        short v = (short) numberExpr.getIntegerValue(element.getParent());
        result = value == v;
      } else if (range.equals(UIMAConstants.TYPE_LONG)) {
        long value = annotation.getLongValue(featureByBaseName);
        long v = numberExpr.getIntegerValue(element.getParent());
        result = value == v;
      }
      return new EvaluatedCondition(this, result);
    } else if (booleanExpr != null) {
      boolean value = annotation.getBooleanValue(featureByBaseName);
      boolean v = booleanExpr.getBooleanValue(element.getParent());
      boolean result = value == v;
      return new EvaluatedCondition(this, result);
    } else if (typeExpr != null) {
      // String value = expandAnchor.getStringValue(featureByBaseName);
      // String string = stringExpr.getStringValue(element.getParent());
      // boolean result = string != null && string.equals(value);
      // return new EvaluatedCondition(this, result);
    }
    return new EvaluatedCondition(this, false);
  }
View Full Code Here

Examples of org.apache.uima.ruta.rule.EvaluatedCondition

        regularExpPattern = Pattern.compile(stringValue);
      }
      matcher = regularExpPattern.matcher(variableValue);
    }
    boolean matches = matcher.matches();
    return new EvaluatedCondition(this, matches);
  }
View Full Code Here

Examples of org.apache.uima.ruta.rule.EvaluatedCondition

      if (result) {
        break;
      }
    }

    return new EvaluatedCondition(this, result);
  }
View Full Code Here

Examples of org.apache.uima.ruta.rule.EvaluatedCondition

    try {
      if (Integer.class.equals(type)) {
        text = normalizeNumber(text);
        int value = Integer.valueOf(text);
        env.setVariableValue(var, value);
        return new EvaluatedCondition(this, true);
      } else if (Double.class.equals(type)) {
        text = normalizeNumber(text);
        double value = Double.valueOf(text);
        env.setVariableValue(var, value);
        return new EvaluatedCondition(this, true);
      } else if (String.class.equals(type)) {
        env.setVariableValue(var, text);
        return new EvaluatedCondition(this, true);
      } else if (Boolean.class.equals(type)) {
        env.setVariableValue(var, Boolean.valueOf(text));
        return new EvaluatedCondition(this, true);
      } else if (Type.class.equals(type)) {
        Type value = stream.getCas().getTypeSystem().getType(text);
        env.setVariableValue(var, value);
        return new EvaluatedCondition(this, true);
      } else {
        return new EvaluatedCondition(this, false);
      }
    } catch (Exception e) {
      return new EvaluatedCondition(this, false);
    }
  }
View Full Code Here

Examples of org.apache.uima.ruta.rule.EvaluatedCondition

  public EvaluatedCondition eval(AnnotationFS annotation, RuleElement element,
          RutaStream stream, InferenceCrowd crowd) {
    RutaBasic endAnchor = stream.getEndAnchor(annotation.getEnd());
    Type t = type.getType(element.getParent());
    boolean result = endAnchor.beginsWith(t) && endAnchor.endsWith(t);
    return new EvaluatedCondition(this, result);
  }
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. 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.