Package org.apache.uima.ruta

Examples of org.apache.uima.ruta.RutaEnvironment


  }

  @Override
  public void execute(RuleMatch match, RuleElement element, RutaStream stream, InferenceCrowd crowd) {
    RutaBlock parent = element.getParent();
    RutaEnvironment environment = parent.getEnvironment();
    Class<?> clazz = environment.getVariableType(var);
    if (clazz.equals(Integer.class) && expression instanceof INumberExpression) {
      int v = ((INumberExpression) expression).getIntegerValue(parent, match, element, stream);
      environment.setVariableValue(var, v);
    } else if (clazz.equals(Double.class) && expression instanceof INumberExpression) {
      double v = ((INumberExpression) expression).getDoubleValue(parent, match, element, stream);
      environment.setVariableValue(var, v);
    } else if (clazz.equals(Type.class) && expression instanceof TypeExpression) {
      Type v = ((TypeExpression) expression).getType(parent);
      environment.setVariableValue(var, v);
    } else if (clazz.equals(Boolean.class) && expression instanceof IBooleanExpression) {
      boolean v = ((IBooleanExpression) expression).getBooleanValue(parent, match, element, stream);
      environment.setVariableValue(var, v);
    } else if (clazz.equals(String.class) && expression instanceof IStringExpression) {
      String v = ((IStringExpression) expression).getStringValue(parent, match, element, stream);
      environment.setVariableValue(var, v);
    }
  }
View Full Code Here


  @SuppressWarnings({ "unchecked", "rawtypes" })
  @Override
  public void execute(RuleMatch match, RuleElement element, RutaStream stream, InferenceCrowd crowd) {
    RutaBlock parent = element.getParent();
    RutaEnvironment environment = parent.getEnvironment();
    List list = environment.getVariableValue(var, List.class);
    // Class<?> vtype = environment.getVariableType(var);
    Class<?> vgtype = environment.getVariableGenericType(var);
    for (IRutaExpression each : elements) {
      if (each instanceof ListExpression) {
        ListExpression l = (ListExpression) each;
        list.addAll(l.getList(parent, stream));
      } else if (vgtype.equals(Boolean.class) && each instanceof IBooleanExpression) {
View Full Code Here

  private void resolve(RutaBlock parent, RutaStream stream) {
    if (typeExpression != null) {
      return;
    }
    RutaEnvironment e = parent.getEnvironment();
    typeExpression = buildTypeExpression(match, e);
    if (typeExpression == null) {
      String[] elements = match.split("[.]");
      StringBuilder sb = new StringBuilder();
      List<String> tail = null;
View Full Code Here

      return;

    for (Type type : types) {
      String stringValue = featureStringExpression.getStringValue(parent, match, element, stream);
      Feature featureByBaseName = type.getFeatureByBaseName(stringValue);
      RutaEnvironment environment = parent.getEnvironment();
      List<AnnotationFS> matchedAnnotations = match.getMatchedAnnotationsOf(element);
      for (AnnotationFS annotationFS : matchedAnnotations) {
        if (annotationFS.getType().getFeatureByBaseName(stringValue) == null) {
          System.out.println("Can't access feature " + stringValue
                  + ", because it's not defined in the matched type: " + annotationFS.getType());
          return;
        }

        String featName = featureByBaseName.getRange().getName();
        if (environment.getVariableType(variable).equals(String.class)
                && featName.equals(UIMAConstants.TYPE_STRING)) {
          Object value = annotationFS.getStringValue(featureByBaseName);
          environment.setVariableValue(variable, value);
        } else if (Number.class.isAssignableFrom(environment.getVariableType(variable))) {
          Number value = 0;
          if (featName.equals(UIMAConstants.TYPE_INTEGER)) {
            value = annotationFS.getIntValue(featureByBaseName);
          } else if (featName.equals(UIMAConstants.TYPE_DOUBLE)) {
            value = annotationFS.getDoubleValue(featureByBaseName);
          } else if (featName.equals(UIMAConstants.TYPE_FLOAT)) {
            value = annotationFS.getFloatValue(featureByBaseName);
          } else if (featName.equals(UIMAConstants.TYPE_BYTE)) {
            value = annotationFS.getByteValue(featureByBaseName);
          } else if (featName.equals(UIMAConstants.TYPE_SHORT)) {
            value = annotationFS.getShortValue(featureByBaseName);
          } else if (featName.equals(UIMAConstants.TYPE_LONG)) {
            value = annotationFS.getLongValue(featureByBaseName);
          }
          environment.setVariableValue(variable, value);
        } else if (environment.getVariableType(variable).equals(Boolean.class)
                && featName.equals(UIMAConstants.TYPE_BOOLEAN)) {
          Object value = annotationFS.getBooleanValue(featureByBaseName);
          environment.setVariableValue(variable, value);
        } else if (environment.getVariableType(variable).equals(Type.class)
                && featName.equals(UIMAConstants.TYPE_STRING)) {
          Object value = annotationFS.getStringValue(featureByBaseName);
          Type t = stream.getCas().getTypeSystem().getType((String) value);
          if (t != null) {
            environment.setVariableValue(variable, t);
          }
        }
      }
    }
View Full Code Here

  @Override
  public EvaluatedCondition eval(AnnotationFS annotation, RuleElement element, RutaStream stream,
          InferenceCrowd crowd) {
    String text = annotation.getCoveredText();
    RutaEnvironment env = element.getParent().getEnvironment();
    Class<?> type = env.getVariableType(var);
    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) {
View Full Code Here

      return;

    for (Type type : types) {
      String stringValue = featureStringExpression.getStringValue(element.getParent());
      Feature featureByBaseName = type.getFeatureByBaseName(stringValue);
      RutaEnvironment environment = element.getParent().getEnvironment();
      List<AnnotationFS> matchedAnnotations = match.getMatchedAnnotationsOf(element, stream);
      for (AnnotationFS annotationFS : matchedAnnotations) {
        if (annotationFS.getType().getFeatureByBaseName(stringValue) == null) {
          System.out.println("Can't access feature " + stringValue
                  + ", because it's not defined in the matched type: " + annotationFS.getType());
          return;
        }

        String featName = featureByBaseName.getRange().getName();
        if (environment.getVariableType(variable).equals(String.class)
                && featName.equals(UIMAConstants.TYPE_STRING)) {
          Object value = annotationFS.getStringValue(featureByBaseName);
          environment.setVariableValue(variable, value);
        } else if (Number.class.isAssignableFrom(environment.getVariableType(variable))) {
          Number value = 0;    
          if(featName.equals(UIMAConstants.TYPE_INTEGER)) {
            value = annotationFS.getIntValue(featureByBaseName);
          } else if (featName.equals(UIMAConstants.TYPE_DOUBLE)) {
            value = annotationFS.getDoubleValue(featureByBaseName);
          } else if (featName.equals(UIMAConstants.TYPE_FLOAT)) {
            value = annotationFS.getFloatValue(featureByBaseName);
          } else if (featName.equals(UIMAConstants.TYPE_BYTE)) {
            value = annotationFS.getByteValue(featureByBaseName);
          } else if (featName.equals(UIMAConstants.TYPE_SHORT)) {
            value = annotationFS.getShortValue(featureByBaseName);
          } else if (featName.equals(UIMAConstants.TYPE_LONG)) {
            value = annotationFS.getLongValue(featureByBaseName);
          }
          environment.setVariableValue(variable, value);
        } else if (environment.getVariableType(variable).equals(Boolean.class)
                && featName.equals(UIMAConstants.TYPE_BOOLEAN)) {
          Object value = annotationFS.getBooleanValue(featureByBaseName);
          environment.setVariableValue(variable, value);
        } else if (environment.getVariableType(variable).equals(Type.class)
                && featName.equals(UIMAConstants.TYPE_STRING)) {
          Object value = annotationFS.getStringValue(featureByBaseName);
          Type t = stream.getCas().getTypeSystem().getType((String) value);
          if (t != null) {
            environment.setVariableValue(variable, t);
          }
        }
      }
    }
View Full Code Here

      } else {
        regularExpPattern = Pattern.compile(stringValue);
      }
      matcher = regularExpPattern.matcher(coveredText);
    } else {
      RutaEnvironment environment = element.getParent().getEnvironment();
      String variableValue = environment.getVariableValue(variable, String.class);
      Pattern regularExpPattern = null;
      if (ignore) {
        regularExpPattern = Pattern.compile(stringValue, Pattern.CASE_INSENSITIVE);
      } else {
        regularExpPattern = Pattern.compile(stringValue);
View Full Code Here

  @Override
  public void execute(RuleMatch match, RuleElement element, RutaStream stream,
          InferenceCrowd crowd) {
    RutaBlock parent = element.getParent();
    RutaEnvironment environment = parent.getEnvironment();
    Class<?> clazz = environment.getVariableType(var);
    if (clazz.equals(Integer.class) && expression instanceof NumberExpression) {
      int v = ((NumberExpression) expression).getIntegerValue(parent);
      environment.setVariableValue(var, v);
    } else if (clazz.equals(Double.class) && expression instanceof NumberExpression) {
      double v = ((NumberExpression) expression).getDoubleValue(parent);
      environment.setVariableValue(var, v);
    } else if (clazz.equals(Type.class) && expression instanceof TypeExpression) {
      Type v = ((TypeExpression) expression).getType(parent);
      environment.setVariableValue(var, v);
    } else if (clazz.equals(Boolean.class) && expression instanceof BooleanExpression) {
      boolean v = ((BooleanExpression) expression).getBooleanValue(parent);
      environment.setVariableValue(var, v);
    } else if (clazz.equals(String.class) && expression instanceof StringExpression) {
      String v = ((StringExpression) expression).getStringValue(parent);
      environment.setVariableValue(var, v);
    }
  }
View Full Code Here

  @Override
  public EvaluatedCondition eval(AnnotationFS annotation, RuleElement element,
          RutaStream stream, InferenceCrowd crowd) {
    String text = annotation.getCoveredText();
    RutaEnvironment env = element.getParent().getEnvironment();
    Class<?> type = env.getVariableType(var);
    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) {
View Full Code Here

  @SuppressWarnings({ "unchecked", "rawtypes" })
  @Override
  public void execute(RuleMatch match, RuleElement element, RutaStream stream,
          InferenceCrowd crowd) {
    RutaBlock parent = element.getParent();
    RutaEnvironment environment = parent.getEnvironment();
    List list = environment.getVariableValue(var, List.class);
    // Class<?> vtype = environment.getVariableType(var);
    Class<?> vgtype = environment.getVariableGenericType(var);
    for (RutaExpression each : elements) {
      if (each instanceof ListExpression) {
        ListExpression l = (ListExpression) each;
        list.addAll(l.getList(parent));
      } else if (vgtype.equals(Boolean.class) && each instanceof BooleanExpression) {
View Full Code Here

TOP

Related Classes of org.apache.uima.ruta.RutaEnvironment

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.