You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@uima.apache.org by pk...@apache.org on 2015/03/31 21:57:36 UTC
svn commit: r1670457 - in
/uima/ruta/trunk/ruta-core/src/main/java/org/apache/uima/ruta:
action/AbstractStructureAction.java
expression/feature/SimpleFeatureExpression.java
Author: pkluegl
Date: Tue Mar 31 19:57:35 2015
New Revision: 1670457
URL: http://svn.apache.org/r1670457
Log:
UIMA-4319
- avoid NPE for aliased type expression interpreted as generic feature expression
Modified:
uima/ruta/trunk/ruta-core/src/main/java/org/apache/uima/ruta/action/AbstractStructureAction.java
uima/ruta/trunk/ruta-core/src/main/java/org/apache/uima/ruta/expression/feature/SimpleFeatureExpression.java
Modified: uima/ruta/trunk/ruta-core/src/main/java/org/apache/uima/ruta/action/AbstractStructureAction.java
URL: http://svn.apache.org/viewvc/uima/ruta/trunk/ruta-core/src/main/java/org/apache/uima/ruta/action/AbstractStructureAction.java?rev=1670457&r1=1670456&r2=1670457&view=diff
==============================================================================
--- uima/ruta/trunk/ruta-core/src/main/java/org/apache/uima/ruta/action/AbstractStructureAction.java (original)
+++ uima/ruta/trunk/ruta-core/src/main/java/org/apache/uima/ruta/action/AbstractStructureAction.java Tue Mar 31 19:57:35 2015
@@ -85,10 +85,13 @@ public abstract class AbstractStructureA
TypeExpression type = fe.getTypeExpr(parent);
List<AnnotationFS> annotationsInWindow = stream.getAnnotationsInWindow(matchedAnnotation,
type.getType(parent));
- List<AnnotationFS> featureAnnotations = new ArrayList<AnnotationFS>(fe.getFeatureAnnotations(annotationsInWindow, stream, parent, false));
+ List<AnnotationFS> featureAnnotations = annotationsInWindow;
+ if (fe.getFeatures(parent) != null) {
+ featureAnnotations = new ArrayList<AnnotationFS>(fe.getFeatureAnnotations(
+ annotationsInWindow, stream, parent, false));
+ }
if (typeSystem.subsumes(jcas.getCasType(FSArray.type), range)) {
- structure
- .setFeatureValue(targetFeature, UIMAUtils.toFSArray(jcas, featureAnnotations));
+ structure.setFeatureValue(targetFeature, UIMAUtils.toFSArray(jcas, featureAnnotations));
} else if (typeSystem.subsumes(range, type.getType(parent))
&& !featureAnnotations.isEmpty()) {
AnnotationFS annotation = featureAnnotations.get(0);
Modified: uima/ruta/trunk/ruta-core/src/main/java/org/apache/uima/ruta/expression/feature/SimpleFeatureExpression.java
URL: http://svn.apache.org/viewvc/uima/ruta/trunk/ruta-core/src/main/java/org/apache/uima/ruta/expression/feature/SimpleFeatureExpression.java?rev=1670457&r1=1670456&r2=1670457&view=diff
==============================================================================
--- uima/ruta/trunk/ruta-core/src/main/java/org/apache/uima/ruta/expression/feature/SimpleFeatureExpression.java (original)
+++ uima/ruta/trunk/ruta-core/src/main/java/org/apache/uima/ruta/expression/feature/SimpleFeatureExpression.java Tue Mar 31 19:57:35 2015
@@ -41,7 +41,7 @@ import org.apache.uima.ruta.rule.Annotat
public class SimpleFeatureExpression extends FeatureExpression {
private MatchReference mr;
-
+
private TypeExpression typeExpr;
private List<String> features;
@@ -71,9 +71,12 @@ public class SimpleFeatureExpression ext
@Override
public List<Feature> getFeatures(RutaBlock parent) {
- if(mr != null) {
+ if (mr != null) {
typeExpr = mr.getTypeExpression(parent);
FeatureExpression featureExpression = mr.getFeatureExpression(parent);
+ if (featureExpression == null) {
+ return null;
+ }
features = featureExpression.getFeatureStringList(parent);
}
List<Feature> result = new ArrayList<Feature>();
@@ -86,13 +89,13 @@ public class SimpleFeatureExpression ext
} else {
feature = type.getFeatureByBaseName(each);
if (feature == null) {
- if(!StringUtils.equals(each, UIMAConstants.FEATURE_COVERED_TEXT_SHORT))
- throw new IllegalArgumentException("Not able to access feature " + each + " of type "
- + type.getName());
+ if (!StringUtils.equals(each, UIMAConstants.FEATURE_COVERED_TEXT_SHORT))
+ throw new IllegalArgumentException("Not able to access feature " + each + " of type "
+ + type.getName());
}
}
result.add(feature);
- if(feature != null) {
+ if (feature != null) {
type = feature.getRange();
}
}
@@ -100,7 +103,7 @@ public class SimpleFeatureExpression ext
}
public TypeExpression getTypeExpr(RutaBlock parent) {
- if(mr != null) {
+ if (mr != null) {
return mr.getTypeExpression(parent);
}
return typeExpr;
@@ -111,7 +114,7 @@ public class SimpleFeatureExpression ext
}
public List<String> getFeatureStringList(RutaBlock parent) {
- if(mr != null) {
+ if (mr != null) {
features = mr.getFeatureExpression(parent).getFeatureStringList(parent);
}
return features;
@@ -128,7 +131,7 @@ public class SimpleFeatureExpression ext
for (AnnotationFS eachBase : annotations) {
AnnotationFS afs = eachBase;
for (Feature feature : features) {
- if(feature == null || feature.getRange().isPrimitive()) {
+ if (feature == null || feature.getRange().isPrimitive()) {
// feature == null -> this is the coveredText "feature"
if (this instanceof FeatureMatchExpression) {
FeatureMatchExpression fme = (FeatureMatchExpression) this;
@@ -154,19 +157,17 @@ public class SimpleFeatureExpression ext
}
} else {
// exploit expression for null assignments
- IRutaExpression arg = ((FeatureMatchExpression)this).getArg();
- if(arg instanceof NullExpression) {
+ IRutaExpression arg = ((FeatureMatchExpression) this).getArg();
+ if (arg instanceof NullExpression) {
result.addAll(annotations);
}
}
}
return result;
}
+
public MatchReference getMatchReference() {
return mr;
}
-
-
-
}