in ruta-core/src/main/java/org/apache/uima/ruta/RutaStream.java [1437:1506]
public void assignVariable(String var, IRutaExpression expression, MatchContext context) {
RutaBlock parent = context.getParent();
RutaEnvironment environment = parent.getEnvironment();
Class<?> clazz = environment.getVariableType(var);
if (clazz.equals(Double.class) && expression instanceof INumberExpression) {
double v = ((INumberExpression) expression).getDoubleValue(context, this);
environment.setVariableValue(var, v);
} else if (clazz.equals(Float.class) && expression instanceof INumberExpression) {
float v = (float) ((INumberExpression) expression).getDoubleValue(context, this);
environment.setVariableValue(var, v);
} else if (clazz.equals(Integer.class) && expression instanceof INumberExpression) {
int v = ((INumberExpression) expression).getIntegerValue(context, this);
environment.setVariableValue(var, v);
} else if (clazz.equals(Type.class) && expression instanceof ITypeExpression) {
Type v = ((ITypeExpression) expression).getType(context, this);
environment.setVariableValue(var, v);
} else if (clazz.equals(Boolean.class) && expression instanceof IBooleanExpression) {
boolean v = ((IBooleanExpression) expression).getBooleanValue(context, this);
environment.setVariableValue(var, v);
} else if (clazz.equals(String.class) && expression instanceof IStringExpression) {
String v = ((IStringExpression) expression).getStringValue(context, this);
environment.setVariableValue(var, v);
} else if (clazz.equals(AnnotationFS.class) && expression instanceof IAnnotationExpression) {
AnnotationFS v = ((IAnnotationExpression) expression).getAnnotation(context, this);
environment.setVariableValue(var, v);
} else if (clazz.equals(List.class)) {
Class<?> variableGenericType = environment.getVariableGenericType(var);
if (variableGenericType.equals(AnnotationFS.class)
&& expression instanceof IAnnotationListExpression) {
List<AnnotationFS> v = ((IAnnotationListExpression) expression).getAnnotationList(context,
this);
environment.setVariableValue(var, v);
} else if (variableGenericType.equals(Boolean.class)
&& expression instanceof IBooleanListExpression) {
List<Boolean> v = ((IBooleanListExpression) expression).getBooleanList(context, this);
environment.setVariableValue(var, v);
} else if (Number.class.isAssignableFrom(variableGenericType)
&& expression instanceof INumberListExpression) {
List<Number> v = ((INumberListExpression) expression).getNumberList(context, this);
environment.setVariableValue(var, v);
} else if (variableGenericType.equals(String.class)
&& expression instanceof IStringListExpression) {
List<String> v = ((IStringListExpression) expression).getStringList(context, this);
environment.setVariableValue(var, v);
} else if (variableGenericType.equals(Type.class)
&& expression instanceof ITypeListExpression) {
List<Type> v = ((ITypeListExpression) expression).getTypeList(context, this);
environment.setVariableValue(var, v);
}
} else if (clazz.equals(Boolean.class) && expression instanceof AnnotationTypeExpression) {
// special not yet supported use case: b = a1==a2
// TODO: this should be solved by having a boolean expression and an atomic feature
// expression?
AnnotationTypeExpression ate = (AnnotationTypeExpression) expression;
AnnotationFS annotation = ate.getAnnotation(context, this);
FeatureExpression featureExpression = ate.getFeatureExpression();
if (featureExpression instanceof FeatureMatchExpression) {
FeatureMatchExpression fme = (FeatureMatchExpression) featureExpression;
IRutaExpression arg = fme.getArg();
if (arg instanceof IAnnotationExpression) {
AnnotationFS argAnnotation = ((IAnnotationExpression) arg).getAnnotation(context, this);
if (StringUtils.equals(fme.getOp(), "==")) {
environment.setVariableValue(var, annotation == argAnnotation);
} else if (StringUtils.equals(fme.getOp(), "!=")) {
environment.setVariableValue(var, annotation != argAnnotation);
}
}
}
}
}