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 2016/03/16 16:04:01 UTC
svn commit: r1735237 - in /uima/ruta/trunk/ruta-core/src:
main/java/org/apache/uima/ruta/ main/java/org/apache/uima/ruta/action/
main/java/org/apache/uima/ruta/condition/
main/java/org/apache/uima/ruta/expression/
main/java/org/apache/uima/ruta/express...
Author: pkluegl
Date: Wed Mar 16 15:04:01 2016
New Revision: 1735237
URL: http://svn.apache.org/viewvc?rev=1735237&view=rev
Log:
UIMA-4822
- allow feature expressions on annotations expressions
- activated and extended tests
Modified:
uima/ruta/trunk/ruta-core/src/main/java/org/apache/uima/ruta/RutaStream.java
uima/ruta/trunk/ruta-core/src/main/java/org/apache/uima/ruta/action/ImplicitFeatureAction.java
uima/ruta/trunk/ruta-core/src/main/java/org/apache/uima/ruta/condition/ImplicitCondition.java
uima/ruta/trunk/ruta-core/src/main/java/org/apache/uima/ruta/expression/MatchReference.java
uima/ruta/trunk/ruta-core/src/main/java/org/apache/uima/ruta/expression/NullExpression.java
uima/ruta/trunk/ruta-core/src/main/java/org/apache/uima/ruta/expression/RutaExpression.java
uima/ruta/trunk/ruta-core/src/main/java/org/apache/uima/ruta/expression/annotation/AnnotationFeatureExpression.java
uima/ruta/trunk/ruta-core/src/main/java/org/apache/uima/ruta/expression/annotation/AnnotationListFeatureExpression.java
uima/ruta/trunk/ruta-core/src/main/java/org/apache/uima/ruta/expression/bool/BooleanFeatureExpression.java
uima/ruta/trunk/ruta-core/src/main/java/org/apache/uima/ruta/expression/bool/BooleanListFeatureExpression.java
uima/ruta/trunk/ruta-core/src/main/java/org/apache/uima/ruta/expression/feature/FeatureExpression.java
uima/ruta/trunk/ruta-core/src/main/java/org/apache/uima/ruta/expression/feature/GenericFeatureExpression.java
uima/ruta/trunk/ruta-core/src/main/java/org/apache/uima/ruta/expression/feature/SimpleFeatureExpression.java
uima/ruta/trunk/ruta-core/src/main/java/org/apache/uima/ruta/expression/number/NumberFeatureExpression.java
uima/ruta/trunk/ruta-core/src/main/java/org/apache/uima/ruta/expression/number/NumberListFeatureExpression.java
uima/ruta/trunk/ruta-core/src/main/java/org/apache/uima/ruta/expression/string/StringFeatureExpression.java
uima/ruta/trunk/ruta-core/src/main/java/org/apache/uima/ruta/expression/string/StringListFeatureExpression.java
uima/ruta/trunk/ruta-core/src/main/java/org/apache/uima/ruta/rule/RuleElementMatch.java
uima/ruta/trunk/ruta-core/src/main/java/org/apache/uima/ruta/rule/RutaRuleElement.java
uima/ruta/trunk/ruta-core/src/main/java/org/apache/uima/ruta/rule/RutaTypeMatcher.java
uima/ruta/trunk/ruta-core/src/main/java/org/apache/uima/ruta/rule/WildCardRuleElement.java
uima/ruta/trunk/ruta-core/src/main/java/org/apache/uima/ruta/verbalize/ExpressionVerbalizer.java
uima/ruta/trunk/ruta-core/src/test/java/org/apache/uima/ruta/condition/ContextCountTest.java
uima/ruta/trunk/ruta-core/src/test/java/org/apache/uima/ruta/expression/annotation/AnnotationLabelExpressionTest.java
Modified: uima/ruta/trunk/ruta-core/src/main/java/org/apache/uima/ruta/RutaStream.java
URL: http://svn.apache.org/viewvc/uima/ruta/trunk/ruta-core/src/main/java/org/apache/uima/ruta/RutaStream.java?rev=1735237&r1=1735236&r2=1735237&view=diff
==============================================================================
--- uima/ruta/trunk/ruta-core/src/main/java/org/apache/uima/ruta/RutaStream.java (original)
+++ uima/ruta/trunk/ruta-core/src/main/java/org/apache/uima/ruta/RutaStream.java Wed Mar 16 15:04:01 2016
@@ -1089,8 +1089,7 @@ public class RutaStream extends FSIterat
assignAnnotationByTypeInWindow(annotation, feature, context, t);
} else if (value instanceof GenericFeatureExpression && !feature.getRange().isPrimitive()) {
FeatureExpression fe = ((GenericFeatureExpression) value).getFeatureExpression();
- ITypeExpression typeExpr = fe.getTypeExpr(context, this);
- Type t = typeExpr.getType(context, this);
+ Type t = fe.getInitialType(context, this);
List<AnnotationFS> inWindow = this.getAnnotationsInWindow(context.getAnnotation(), t);
if (fe instanceof SimpleFeatureExpression) {
SimpleFeatureExpression sfe = (SimpleFeatureExpression) fe;
Modified: uima/ruta/trunk/ruta-core/src/main/java/org/apache/uima/ruta/action/ImplicitFeatureAction.java
URL: http://svn.apache.org/viewvc/uima/ruta/trunk/ruta-core/src/main/java/org/apache/uima/ruta/action/ImplicitFeatureAction.java?rev=1735237&r1=1735236&r2=1735237&view=diff
==============================================================================
--- uima/ruta/trunk/ruta-core/src/main/java/org/apache/uima/ruta/action/ImplicitFeatureAction.java (original)
+++ uima/ruta/trunk/ruta-core/src/main/java/org/apache/uima/ruta/action/ImplicitFeatureAction.java Wed Mar 16 15:04:01 2016
@@ -32,6 +32,9 @@ import org.apache.uima.cas.TypeSystem;
import org.apache.uima.cas.text.AnnotationFS;
import org.apache.uima.ruta.RutaStream;
import org.apache.uima.ruta.expression.IRutaExpression;
+import org.apache.uima.ruta.expression.MatchReference;
+import org.apache.uima.ruta.expression.annotation.IAnnotationExpression;
+import org.apache.uima.ruta.expression.annotation.IAnnotationListExpression;
import org.apache.uima.ruta.expression.feature.FeatureMatchExpression;
import org.apache.uima.ruta.expression.type.ITypeExpression;
import org.apache.uima.ruta.rule.AnnotationComparator;
@@ -55,12 +58,22 @@ public class ImplicitFeatureAction exten
public void execute(MatchContext context, RutaStream stream, InferenceCrowd crowd) {
RuleMatch match = context.getRuleMatch();
RuleElement element = context.getElement();
- ITypeExpression typeExpr = expr.getTypeExpr(context, stream);
- Type type = typeExpr.getType(context, stream);
List<AnnotationFS> matchedAnnotations = match.getMatchedAnnotationsOfElement(element);
Collection<AnnotationFS> annotations = new TreeSet<AnnotationFS>(comp);
+ MatchReference matchReference = expr.getMatchReference();
+ ITypeExpression typeExpr = matchReference.getTypeExpression(context, stream);
+ IAnnotationListExpression annotationListExpr = matchReference.getAnnotationListExpression(context, stream);
+ IAnnotationExpression annotationExpr = matchReference.getAnnotationExpression(context, stream);
+ // TODO refactor and do we really need multiple annotations for each matched ones?
for (AnnotationFS annotation : matchedAnnotations) {
- annotations.addAll(getAnnotations(annotation, type, expr, stream));
+ if (typeExpr != null) {
+ Type type = typeExpr.getType(context, stream);
+ annotations = getAnnotations(annotation, type, expr, stream);
+ } else if(annotationListExpr!=null) {
+ annotations.addAll(annotationListExpr.getAnnotationList(context, stream));
+ } else if(annotationExpr!=null) {
+ annotations.add(annotationExpr.getAnnotation(context, stream));
+ }
}
for (AnnotationFS each : annotations) {
stream.getCas().removeFsFromIndexes(each);
@@ -80,7 +93,7 @@ public class ImplicitFeatureAction exten
stream.getCas().addFsToIndexes(each);
}
}
-
+
private List<AnnotationFS> getAnnotations(AnnotationFS annotation, Type type,
FeatureMatchExpression fme, RutaStream stream) {
Modified: uima/ruta/trunk/ruta-core/src/main/java/org/apache/uima/ruta/condition/ImplicitCondition.java
URL: http://svn.apache.org/viewvc/uima/ruta/trunk/ruta-core/src/main/java/org/apache/uima/ruta/condition/ImplicitCondition.java?rev=1735237&r1=1735236&r2=1735237&view=diff
==============================================================================
--- uima/ruta/trunk/ruta-core/src/main/java/org/apache/uima/ruta/condition/ImplicitCondition.java (original)
+++ uima/ruta/trunk/ruta-core/src/main/java/org/apache/uima/ruta/condition/ImplicitCondition.java Wed Mar 16 15:04:01 2016
@@ -29,6 +29,9 @@ import org.apache.uima.cas.TypeSystem;
import org.apache.uima.cas.text.AnnotationFS;
import org.apache.uima.ruta.RutaStream;
import org.apache.uima.ruta.expression.IRutaExpression;
+import org.apache.uima.ruta.expression.MatchReference;
+import org.apache.uima.ruta.expression.annotation.IAnnotationExpression;
+import org.apache.uima.ruta.expression.annotation.IAnnotationListExpression;
import org.apache.uima.ruta.expression.bool.IBooleanExpression;
import org.apache.uima.ruta.expression.feature.FeatureMatchExpression;
import org.apache.uima.ruta.expression.type.ITypeExpression;
@@ -53,9 +56,20 @@ public class ImplicitCondition extends A
return new EvaluatedCondition(this, be.getBooleanValue(context, stream));
} else if (expr instanceof FeatureMatchExpression) {
FeatureMatchExpression fme = (FeatureMatchExpression) expr;
- ITypeExpression typeExpr = fme.getTypeExpr(context, stream);
- Type type = typeExpr.getType(context, stream);
- List<AnnotationFS> annotations = getAnnotationsToCheck(annotation, type, fme, stream);
+ List<AnnotationFS> annotations =new ArrayList<>();
+ MatchReference matchReference = fme.getMatchReference();
+ // TODO refactor
+ ITypeExpression typeExpr = matchReference.getTypeExpression(context, stream);
+ IAnnotationListExpression annotationListExpr = matchReference.getAnnotationListExpression(context, stream);
+ IAnnotationExpression annotationExpr = matchReference.getAnnotationExpression(context, stream);
+ if (typeExpr != null) {
+ Type type = typeExpr.getType(context, stream);
+ annotations = getAnnotationsToCheck(annotation, type, fme, stream);
+ } else if(annotationListExpr!=null) {
+ annotations.addAll(annotationListExpr.getAnnotationList(context, stream));
+ } else if(annotationExpr!=null) {
+ annotations.add(annotationExpr.getAnnotation(context, stream));
+ }
Collection<AnnotationFS> featureAnnotations = fme.getFeatureAnnotations(annotations, stream,
context, true);
return new EvaluatedCondition(this, !featureAnnotations.isEmpty());
@@ -72,11 +86,11 @@ public class ImplicitCondition extends A
} else {
Collection<AnnotationFS> beginAnchors = stream.getBeginAnchor(annotation.getBegin())
.getBeginAnchors(type);
- Collection<AnnotationFS> endAnchors = stream.getEndAnchor(annotation.getEnd()).getEndAnchors(
- type);
+ Collection<AnnotationFS> endAnchors = stream.getEndAnchor(annotation.getEnd())
+ .getEndAnchors(type);
@SuppressWarnings("unchecked")
- Collection<AnnotationFS> intersection = CollectionUtils
- .intersection(beginAnchors, endAnchors);
+ Collection<AnnotationFS> intersection = CollectionUtils.intersection(beginAnchors,
+ endAnchors);
result.addAll(intersection);
}
return result;
Modified: uima/ruta/trunk/ruta-core/src/main/java/org/apache/uima/ruta/expression/MatchReference.java
URL: http://svn.apache.org/viewvc/uima/ruta/trunk/ruta-core/src/main/java/org/apache/uima/ruta/expression/MatchReference.java?rev=1735237&r1=1735236&r2=1735237&view=diff
==============================================================================
--- uima/ruta/trunk/ruta-core/src/main/java/org/apache/uima/ruta/expression/MatchReference.java (original)
+++ uima/ruta/trunk/ruta-core/src/main/java/org/apache/uima/ruta/expression/MatchReference.java Wed Mar 16 15:04:01 2016
@@ -20,6 +20,7 @@
package org.apache.uima.ruta.expression;
import java.util.Arrays;
+import java.util.Collections;
import java.util.List;
import org.apache.uima.ruta.RutaBlock;
@@ -55,6 +56,8 @@ public class MatchReference extends Ruta
private FeatureExpression featureExpression;
+ private List<String> features = Collections.emptyList();
+
private boolean initialized = false;
public MatchReference(String reference) {
@@ -89,7 +92,8 @@ public class MatchReference extends Ruta
counter++;
}
if (tail != null) {
- featureExpression = new SimpleFeatureExpression(typeExpression, tail);
+ featureExpression = new SimpleFeatureExpression(this);
+ features = tail;
}
}
initialized = true;
@@ -165,4 +169,8 @@ public class MatchReference extends Ruta
return reference;
}
+ public List<String> getFeatureList() {
+ return features;
+ }
+
}
Modified: uima/ruta/trunk/ruta-core/src/main/java/org/apache/uima/ruta/expression/NullExpression.java
URL: http://svn.apache.org/viewvc/uima/ruta/trunk/ruta-core/src/main/java/org/apache/uima/ruta/expression/NullExpression.java?rev=1735237&r1=1735236&r2=1735237&view=diff
==============================================================================
--- uima/ruta/trunk/ruta-core/src/main/java/org/apache/uima/ruta/expression/NullExpression.java (original)
+++ uima/ruta/trunk/ruta-core/src/main/java/org/apache/uima/ruta/expression/NullExpression.java Wed Mar 16 15:04:01 2016
@@ -65,8 +65,8 @@ public class NullExpression extends Feat
}
@Override
- public ITypeExpression getTypeExpr(MatchContext context, RutaStream stream) {
+ public Type getInitialType(MatchContext context, RutaStream stream) {
return null;
}
-
+
}
Modified: uima/ruta/trunk/ruta-core/src/main/java/org/apache/uima/ruta/expression/RutaExpression.java
URL: http://svn.apache.org/viewvc/uima/ruta/trunk/ruta-core/src/main/java/org/apache/uima/ruta/expression/RutaExpression.java?rev=1735237&r1=1735236&r2=1735237&view=diff
==============================================================================
--- uima/ruta/trunk/ruta-core/src/main/java/org/apache/uima/ruta/expression/RutaExpression.java (original)
+++ uima/ruta/trunk/ruta-core/src/main/java/org/apache/uima/ruta/expression/RutaExpression.java Wed Mar 16 15:04:01 2016
@@ -29,14 +29,19 @@ import org.apache.uima.cas.Type;
import org.apache.uima.cas.text.AnnotationFS;
import org.apache.uima.ruta.RutaElement;
import org.apache.uima.ruta.RutaStream;
+import org.apache.uima.ruta.expression.feature.FeatureExpression;
+import org.apache.uima.ruta.rule.MatchContext;
public class RutaExpression extends RutaElement implements IRutaExpression {
- protected List<AnnotationFS> getTargetAnnotation(AnnotationFS annotation, Type type,
- RutaStream stream) {
- if (annotation == null) {
+ protected List<AnnotationFS> getTargetAnnotation(AnnotationFS matchedAnnotation,
+ FeatureExpression fe, MatchContext context, RutaStream stream) {
+ if (matchedAnnotation == null) {
return Collections.emptyList();
}
+ // TODO refactor
+
+ Type type = fe.getInitialType(context, stream);
// "autocast" to document annotation when mentioning document.
// This is either the actual document annotation or the current one in a block or inlined rule
@@ -54,19 +59,19 @@ public class RutaExpression extends Ruta
}
}
- if (annotation.getType().equals(type)
- || stream.getCas().getTypeSystem().subsumes(type, annotation.getType())) {
+ if (matchedAnnotation.getType().equals(type)
+ || stream.getCas().getTypeSystem().subsumes(type, matchedAnnotation.getType())) {
List<AnnotationFS> result = new ArrayList<AnnotationFS>(1);
- result.add(annotation);
+ result.add(matchedAnnotation);
return result;
} else {
- Collection<AnnotationFS> beginAnchors = stream.getBeginAnchor(annotation.getBegin())
+ Collection<AnnotationFS> beginAnchors = stream.getBeginAnchor(matchedAnnotation.getBegin())
.getBeginAnchors(type);
- Collection<AnnotationFS> endAnchors = stream.getEndAnchor(annotation.getEnd()).getEndAnchors(
- type);
+ Collection<AnnotationFS> endAnchors = stream.getEndAnchor(matchedAnnotation.getEnd())
+ .getEndAnchors(type);
@SuppressWarnings("unchecked")
- Collection<AnnotationFS> intersection = CollectionUtils
- .intersection(beginAnchors, endAnchors);
+ Collection<AnnotationFS> intersection = CollectionUtils.intersection(beginAnchors,
+ endAnchors);
return new ArrayList<AnnotationFS>(intersection);
}
}
Modified: uima/ruta/trunk/ruta-core/src/main/java/org/apache/uima/ruta/expression/annotation/AnnotationFeatureExpression.java
URL: http://svn.apache.org/viewvc/uima/ruta/trunk/ruta-core/src/main/java/org/apache/uima/ruta/expression/annotation/AnnotationFeatureExpression.java?rev=1735237&r1=1735236&r2=1735237&view=diff
==============================================================================
--- uima/ruta/trunk/ruta-core/src/main/java/org/apache/uima/ruta/expression/annotation/AnnotationFeatureExpression.java (original)
+++ uima/ruta/trunk/ruta-core/src/main/java/org/apache/uima/ruta/expression/annotation/AnnotationFeatureExpression.java Wed Mar 16 15:04:01 2016
@@ -22,7 +22,6 @@ package org.apache.uima.ruta.expression.
import java.util.Collection;
import java.util.List;
-import org.apache.uima.cas.Type;
import org.apache.uima.cas.text.AnnotationFS;
import org.apache.uima.ruta.RutaStream;
import org.apache.uima.ruta.expression.feature.FeatureExpression;
@@ -44,8 +43,7 @@ public class AnnotationFeatureExpression
@Override
public AnnotationFS getAnnotation(MatchContext context, RutaStream stream) {
AnnotationFS annotation = context.getAnnotation();
- Type type = fe.getTypeExpr(context, stream).getType(context, stream);
- List<AnnotationFS> list = getTargetAnnotation(annotation, type, stream);
+ List<AnnotationFS> list = getTargetAnnotation(annotation, fe, context, stream);
Collection<AnnotationFS> featureAnnotations = fe.getFeatureAnnotations(list, stream, context,
false);
if (!featureAnnotations.isEmpty()) {
Modified: uima/ruta/trunk/ruta-core/src/main/java/org/apache/uima/ruta/expression/annotation/AnnotationListFeatureExpression.java
URL: http://svn.apache.org/viewvc/uima/ruta/trunk/ruta-core/src/main/java/org/apache/uima/ruta/expression/annotation/AnnotationListFeatureExpression.java?rev=1735237&r1=1735236&r2=1735237&view=diff
==============================================================================
--- uima/ruta/trunk/ruta-core/src/main/java/org/apache/uima/ruta/expression/annotation/AnnotationListFeatureExpression.java (original)
+++ uima/ruta/trunk/ruta-core/src/main/java/org/apache/uima/ruta/expression/annotation/AnnotationListFeatureExpression.java Wed Mar 16 15:04:01 2016
@@ -23,7 +23,6 @@ import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
-import org.apache.uima.cas.Type;
import org.apache.uima.cas.text.AnnotationFS;
import org.apache.uima.ruta.RutaStream;
import org.apache.uima.ruta.expression.feature.FeatureExpression;
@@ -45,8 +44,7 @@ public class AnnotationListFeatureExpres
@Override
public List<AnnotationFS> getList(MatchContext context, RutaStream stream) {
AnnotationFS annotation = context.getAnnotation();
- Type type = fe.getTypeExpr(context, stream).getType(context, stream);
- List<AnnotationFS> list = getTargetAnnotation(annotation, type, stream);
+ List<AnnotationFS> list = getTargetAnnotation(annotation, fe, context, stream);
Collection<AnnotationFS> featureAnnotations = fe.getFeatureAnnotations(list, stream, context,
false);
return new ArrayList<AnnotationFS>(featureAnnotations);
Modified: uima/ruta/trunk/ruta-core/src/main/java/org/apache/uima/ruta/expression/bool/BooleanFeatureExpression.java
URL: http://svn.apache.org/viewvc/uima/ruta/trunk/ruta-core/src/main/java/org/apache/uima/ruta/expression/bool/BooleanFeatureExpression.java?rev=1735237&r1=1735236&r2=1735237&view=diff
==============================================================================
--- uima/ruta/trunk/ruta-core/src/main/java/org/apache/uima/ruta/expression/bool/BooleanFeatureExpression.java (original)
+++ uima/ruta/trunk/ruta-core/src/main/java/org/apache/uima/ruta/expression/bool/BooleanFeatureExpression.java Wed Mar 16 15:04:01 2016
@@ -23,7 +23,6 @@ import java.util.Collection;
import java.util.List;
import org.apache.uima.cas.Feature;
-import org.apache.uima.cas.Type;
import org.apache.uima.cas.text.AnnotationFS;
import org.apache.uima.ruta.RutaStream;
import org.apache.uima.ruta.expression.feature.FeatureExpression;
@@ -41,9 +40,8 @@ public class BooleanFeatureExpression ex
@Override
public boolean getBooleanValue(MatchContext context, RutaStream stream) {
AnnotationFS annotation = context.getAnnotation();
- Type type = fe.getTypeExpr(context, stream).getType(context, stream);
Feature feature = fe.getFeature(context, stream);
- List<AnnotationFS> list = getTargetAnnotation(annotation, type, stream);
+ List<AnnotationFS> list = getTargetAnnotation(annotation, fe, context, stream);
Collection<AnnotationFS> featureAnnotations = fe.getFeatureAnnotations(list, stream, context,
false);
if (!featureAnnotations.isEmpty()) {
Modified: uima/ruta/trunk/ruta-core/src/main/java/org/apache/uima/ruta/expression/bool/BooleanListFeatureExpression.java
URL: http://svn.apache.org/viewvc/uima/ruta/trunk/ruta-core/src/main/java/org/apache/uima/ruta/expression/bool/BooleanListFeatureExpression.java?rev=1735237&r1=1735236&r2=1735237&view=diff
==============================================================================
--- uima/ruta/trunk/ruta-core/src/main/java/org/apache/uima/ruta/expression/bool/BooleanListFeatureExpression.java (original)
+++ uima/ruta/trunk/ruta-core/src/main/java/org/apache/uima/ruta/expression/bool/BooleanListFeatureExpression.java Wed Mar 16 15:04:01 2016
@@ -28,7 +28,6 @@ import org.apache.commons.lang3.StringUt
import org.apache.uima.cas.BooleanArrayFS;
import org.apache.uima.cas.Feature;
import org.apache.uima.cas.FeatureStructure;
-import org.apache.uima.cas.Type;
import org.apache.uima.cas.text.AnnotationFS;
import org.apache.uima.ruta.RutaStream;
import org.apache.uima.ruta.UIMAConstants;
@@ -51,13 +50,12 @@ public class BooleanListFeatureExpressio
@Override
public List<Boolean> getList(MatchContext context, RutaStream stream) {
AnnotationFS annotation = context.getAnnotation();
- Type type = fe.getTypeExpr(context, stream).getType(context, stream);
Feature feature = fe.getFeature(context, stream);
if(feature == null || !feature.getRange().isArray() || !StringUtils.equals(feature.getRange().getName(), UIMAConstants.TYPE_BOOLEANARRAY)) {
// throw runtime exception?
return Collections.emptyList();
}
- List<AnnotationFS> list = getTargetAnnotation(annotation, type, stream);
+ List<AnnotationFS> list = getTargetAnnotation(annotation, fe, context, stream);
Collection<AnnotationFS> featureAnnotations = fe.getFeatureAnnotations(list, stream, context,
false);
List<Boolean> result = new ArrayList<>();
Modified: uima/ruta/trunk/ruta-core/src/main/java/org/apache/uima/ruta/expression/feature/FeatureExpression.java
URL: http://svn.apache.org/viewvc/uima/ruta/trunk/ruta-core/src/main/java/org/apache/uima/ruta/expression/feature/FeatureExpression.java?rev=1735237&r1=1735236&r2=1735237&view=diff
==============================================================================
--- uima/ruta/trunk/ruta-core/src/main/java/org/apache/uima/ruta/expression/feature/FeatureExpression.java (original)
+++ uima/ruta/trunk/ruta-core/src/main/java/org/apache/uima/ruta/expression/feature/FeatureExpression.java Wed Mar 16 15:04:01 2016
@@ -23,10 +23,10 @@ import java.util.Collection;
import java.util.List;
import org.apache.uima.cas.Feature;
+import org.apache.uima.cas.Type;
import org.apache.uima.cas.text.AnnotationFS;
import org.apache.uima.ruta.RutaStream;
import org.apache.uima.ruta.expression.RutaExpression;
-import org.apache.uima.ruta.expression.type.ITypeExpression;
import org.apache.uima.ruta.rule.MatchContext;
public abstract class FeatureExpression extends RutaExpression {
@@ -37,10 +37,10 @@ public abstract class FeatureExpression
public abstract List<String> getFeatureStringList(MatchContext context, RutaStream stream);
- public abstract ITypeExpression getTypeExpr(MatchContext context, RutaStream stream);
-
public abstract Collection<AnnotationFS> getFeatureAnnotations(
Collection<AnnotationFS> annotations, RutaStream stream, MatchContext context,
boolean checkOnFeatureValue);
+ public abstract Type getInitialType(MatchContext context, RutaStream stream);
+
}
Modified: uima/ruta/trunk/ruta-core/src/main/java/org/apache/uima/ruta/expression/feature/GenericFeatureExpression.java
URL: http://svn.apache.org/viewvc/uima/ruta/trunk/ruta-core/src/main/java/org/apache/uima/ruta/expression/feature/GenericFeatureExpression.java?rev=1735237&r1=1735236&r2=1735237&view=diff
==============================================================================
--- uima/ruta/trunk/ruta-core/src/main/java/org/apache/uima/ruta/expression/feature/GenericFeatureExpression.java (original)
+++ uima/ruta/trunk/ruta-core/src/main/java/org/apache/uima/ruta/expression/feature/GenericFeatureExpression.java Wed Mar 16 15:04:01 2016
@@ -64,8 +64,6 @@ public class GenericFeatureExpression ex
private IAnnotationListExpression annotationListExpression;
- private ITypeExpression typeExpression;
-
public GenericFeatureExpression(FeatureExpression fe) {
super();
this.featureExpression = fe;
@@ -122,10 +120,7 @@ public class GenericFeatureExpression ex
@Override
public Type getType(MatchContext context, RutaStream stream) {
// special case where an argument is interpreted as a type expression
- if (typeExpression == null) {
- typeExpression = featureExpression.getTypeExpr(context, stream);
- }
- return typeExpression.getType(context, stream);
+ return featureExpression.getInitialType(context, stream);
}
public FeatureExpression getFeatureExpression() {
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=1735237&r1=1735236&r2=1735237&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 Wed Mar 16 15:04:01 2016
@@ -33,6 +33,7 @@ import org.apache.uima.jcas.cas.FSArray;
import org.apache.uima.ruta.RutaStream;
import org.apache.uima.ruta.UIMAConstants;
import org.apache.uima.ruta.expression.MatchReference;
+import org.apache.uima.ruta.expression.annotation.IAnnotationExpression;
import org.apache.uima.ruta.expression.type.ITypeExpression;
import org.apache.uima.ruta.rule.AnnotationComparator;
import org.apache.uima.ruta.rule.MatchContext;
@@ -43,18 +44,8 @@ public class SimpleFeatureExpression ext
private MatchReference mr;
- private ITypeExpression typeExpr;
-
- private List<String> features;
-
protected AnnotationComparator comparator = new AnnotationComparator();
- public SimpleFeatureExpression(ITypeExpression te, List<String> featureReferences) {
- super();
- this.typeExpr = te;
- this.features = featureReferences;
- }
-
public SimpleFeatureExpression(MatchReference mr) {
super();
this.mr = mr;
@@ -77,18 +68,10 @@ public class SimpleFeatureExpression ext
@Override
public List<Feature> getFeatures(MatchContext context, RutaStream stream) {
- if (mr != null) {
- typeExpr = mr.getTypeExpression(context, stream);
- FeatureExpression featureExpression = mr.getFeatureExpression(context, stream);
- if (featureExpression == null) {
- return null;
- }
- features = featureExpression.getFeatureStringList(context, stream);
- }
List<Feature> result = new ArrayList<Feature>();
- Type type = typeExpr.getType(context, stream);
+ Type type = getInitialType(context, stream);
Feature feature = null;
- for (String each : features) {
+ for (String each : getFeatureStringList(context, stream)) {
IndexedReference indexedReference = ParsingUtils.parseIndexedReference(each);
if (indexedReference.index != -1) {
Feature delegate = type.getFeatureByBaseName(indexedReference.reference);
@@ -125,26 +108,23 @@ public class SimpleFeatureExpression ext
return result;
}
- public ITypeExpression getTypeExpr(MatchContext context, RutaStream stream) {
- if (mr != null) {
- return mr.getTypeExpression(context, stream);
+ @Override
+ public Type getInitialType(MatchContext context, RutaStream stream) {
+ ITypeExpression typeExpression = mr.getTypeExpression(context, stream);
+ if(typeExpression!= null) {
+ return typeExpression.getType(context, stream);
+ } else {
+ IAnnotationExpression annotationExpression = mr.getAnnotationExpression(context, stream);
+ if(annotationExpression != null) {
+ AnnotationFS annotation = annotationExpression.getAnnotation(context, stream);
+ return annotation.getType();
+ }
}
- return typeExpr;
- }
-
- public void setTypeExpr(ITypeExpression typeExpr) {
- this.typeExpr = typeExpr;
+ return null;
}
public List<String> getFeatureStringList(MatchContext context, RutaStream stream) {
- if (mr != null) {
- features = mr.getFeatureExpression(context, stream).getFeatureStringList(context, stream);
- }
- return features;
- }
-
- public void setFeatures(List<String> features) {
- this.features = features;
+ return mr.getFeatureList();
}
public Collection<AnnotationFS> getFeatureAnnotations(Collection<AnnotationFS> annotations,
@@ -152,8 +132,12 @@ public class SimpleFeatureExpression ext
Collection<AnnotationFS> result = new TreeSet<AnnotationFS>(comparator);
List<Feature> features = getFeatures(context, stream);
- collectFeatureAnnotations(annotations, features, checkOnFeatureValue, result, stream, context);
+ if(features!= null &&!features.isEmpty()) {
+ collectFeatureAnnotations(annotations, features, checkOnFeatureValue, result, stream, context);
return result;
+ } else {
+ return annotations;
+ }
}
private void collectFeatureAnnotations(Collection<AnnotationFS> annotations,
Modified: uima/ruta/trunk/ruta-core/src/main/java/org/apache/uima/ruta/expression/number/NumberFeatureExpression.java
URL: http://svn.apache.org/viewvc/uima/ruta/trunk/ruta-core/src/main/java/org/apache/uima/ruta/expression/number/NumberFeatureExpression.java?rev=1735237&r1=1735236&r2=1735237&view=diff
==============================================================================
--- uima/ruta/trunk/ruta-core/src/main/java/org/apache/uima/ruta/expression/number/NumberFeatureExpression.java (original)
+++ uima/ruta/trunk/ruta-core/src/main/java/org/apache/uima/ruta/expression/number/NumberFeatureExpression.java Wed Mar 16 15:04:01 2016
@@ -57,10 +57,9 @@ public class NumberFeatureExpression ext
private Number getNumberValue(MatchContext context, RutaStream stream) {
AnnotationFS annotation = context.getAnnotation();
Number result = null;
- Type type = fe.getTypeExpr(context, stream).getType(context, stream);
Feature feature = fe.getFeature(context, stream);
Type range = feature.getRange();
- List<AnnotationFS> list = getTargetAnnotation(annotation, type, stream);
+ List<AnnotationFS> list = getTargetAnnotation(annotation, fe, context, stream);
Collection<AnnotationFS> featureAnnotations = fe.getFeatureAnnotations(list, stream, context,
false);
if (!featureAnnotations.isEmpty()) {
Modified: uima/ruta/trunk/ruta-core/src/main/java/org/apache/uima/ruta/expression/number/NumberListFeatureExpression.java
URL: http://svn.apache.org/viewvc/uima/ruta/trunk/ruta-core/src/main/java/org/apache/uima/ruta/expression/number/NumberListFeatureExpression.java?rev=1735237&r1=1735236&r2=1735237&view=diff
==============================================================================
--- uima/ruta/trunk/ruta-core/src/main/java/org/apache/uima/ruta/expression/number/NumberListFeatureExpression.java (original)
+++ uima/ruta/trunk/ruta-core/src/main/java/org/apache/uima/ruta/expression/number/NumberListFeatureExpression.java Wed Mar 16 15:04:01 2016
@@ -30,7 +30,6 @@ import org.apache.uima.cas.Feature;
import org.apache.uima.cas.FeatureStructure;
import org.apache.uima.cas.FloatArrayFS;
import org.apache.uima.cas.IntArrayFS;
-import org.apache.uima.cas.Type;
import org.apache.uima.cas.text.AnnotationFS;
import org.apache.uima.ruta.RutaStream;
import org.apache.uima.ruta.UIMAConstants;
@@ -53,13 +52,12 @@ public class NumberListFeatureExpression
@Override
public List<Number> getList(MatchContext context, RutaStream stream) {
AnnotationFS annotation = context.getAnnotation();
- Type type = fe.getTypeExpr(context, stream).getType(context, stream);
Feature feature = fe.getFeature(context, stream);
if (feature == null || !feature.getRange().isArray() || !validType(feature)) {
// throw runtime exception?
return Collections.emptyList();
}
- List<AnnotationFS> list = getTargetAnnotation(annotation, type, stream);
+ List<AnnotationFS> list = getTargetAnnotation(annotation, fe, context, stream);
Collection<AnnotationFS> featureAnnotations = fe.getFeatureAnnotations(list, stream, context,
false);
List<Number> result = new ArrayList<>();
Modified: uima/ruta/trunk/ruta-core/src/main/java/org/apache/uima/ruta/expression/string/StringFeatureExpression.java
URL: http://svn.apache.org/viewvc/uima/ruta/trunk/ruta-core/src/main/java/org/apache/uima/ruta/expression/string/StringFeatureExpression.java?rev=1735237&r1=1735236&r2=1735237&view=diff
==============================================================================
--- uima/ruta/trunk/ruta-core/src/main/java/org/apache/uima/ruta/expression/string/StringFeatureExpression.java (original)
+++ uima/ruta/trunk/ruta-core/src/main/java/org/apache/uima/ruta/expression/string/StringFeatureExpression.java Wed Mar 16 15:04:01 2016
@@ -23,7 +23,6 @@ import java.util.Collection;
import java.util.List;
import org.apache.uima.cas.Feature;
-import org.apache.uima.cas.Type;
import org.apache.uima.cas.text.AnnotationFS;
import org.apache.uima.ruta.RutaStream;
import org.apache.uima.ruta.expression.feature.CoveredTextFeature;
@@ -42,9 +41,8 @@ public class StringFeatureExpression ext
@Override
public String getStringValue(MatchContext context, RutaStream stream) {
AnnotationFS annotation = context.getAnnotation();
- Type type = fe.getTypeExpr(context, stream).getType(context, stream);
Feature feature = fe.getFeature(context, stream);
- List<AnnotationFS> list = getTargetAnnotation(annotation, type, stream);
+ List<AnnotationFS> list = getTargetAnnotation(annotation, fe, context, stream);
Collection<AnnotationFS> featureAnnotations = fe.getFeatureAnnotations(list, stream, context,
false);
if (!featureAnnotations.isEmpty()) {
Modified: uima/ruta/trunk/ruta-core/src/main/java/org/apache/uima/ruta/expression/string/StringListFeatureExpression.java
URL: http://svn.apache.org/viewvc/uima/ruta/trunk/ruta-core/src/main/java/org/apache/uima/ruta/expression/string/StringListFeatureExpression.java?rev=1735237&r1=1735236&r2=1735237&view=diff
==============================================================================
--- uima/ruta/trunk/ruta-core/src/main/java/org/apache/uima/ruta/expression/string/StringListFeatureExpression.java (original)
+++ uima/ruta/trunk/ruta-core/src/main/java/org/apache/uima/ruta/expression/string/StringListFeatureExpression.java Wed Mar 16 15:04:01 2016
@@ -28,7 +28,6 @@ import org.apache.commons.lang3.StringUt
import org.apache.uima.cas.Feature;
import org.apache.uima.cas.FeatureStructure;
import org.apache.uima.cas.StringArrayFS;
-import org.apache.uima.cas.Type;
import org.apache.uima.cas.text.AnnotationFS;
import org.apache.uima.ruta.RutaStream;
import org.apache.uima.ruta.UIMAConstants;
@@ -51,13 +50,12 @@ public class StringListFeatureExpression
@Override
public List<String> getList(MatchContext context, RutaStream stream) {
AnnotationFS annotation = context.getAnnotation();
- Type type = fe.getTypeExpr(context, stream).getType(context, stream);
Feature feature = fe.getFeature(context, stream);
if(feature == null || !feature.getRange().isArray() || !StringUtils.equals(feature.getRange().getName(), UIMAConstants.TYPE_STRINGARRAY)) {
// throw runtime exception?
return Collections.emptyList();
}
- List<AnnotationFS> list = getTargetAnnotation(annotation, type, stream);
+ List<AnnotationFS> list = getTargetAnnotation(annotation, fe, context, stream);
Collection<AnnotationFS> featureAnnotations = fe.getFeatureAnnotations(list, stream, context,
false);
List<String> result = new ArrayList<>();
Modified: uima/ruta/trunk/ruta-core/src/main/java/org/apache/uima/ruta/rule/RuleElementMatch.java
URL: http://svn.apache.org/viewvc/uima/ruta/trunk/ruta-core/src/main/java/org/apache/uima/ruta/rule/RuleElementMatch.java?rev=1735237&r1=1735236&r2=1735237&view=diff
==============================================================================
--- uima/ruta/trunk/ruta-core/src/main/java/org/apache/uima/ruta/rule/RuleElementMatch.java (original)
+++ uima/ruta/trunk/ruta-core/src/main/java/org/apache/uima/ruta/rule/RuleElementMatch.java Wed Mar 16 15:04:01 2016
@@ -55,9 +55,17 @@ public class RuleElementMatch {
}
public void setMatchInfo(boolean baseCondition, List<AnnotationFS> texts,
- List<EvaluatedCondition> conditionList, RutaStream stream) {
+ RutaStream stream) {
baseConditionMatched = baseCondition;
textsMatched = texts;
+ conditionsMatched = baseConditionMatched;
+ if (containerMatch != null) {
+ containerMatch.addInnerMatch(ruleElement, this, stream);
+ }
+ }
+
+ public void setConditionInfo(boolean baseCondition, List<EvaluatedCondition> conditionList) {
+ baseConditionMatched = baseCondition;
conditions = conditionList;
conditionsMatched = baseConditionMatched;
if (baseConditionMatched) {
@@ -65,10 +73,8 @@ public class RuleElementMatch {
conditionsMatched = conditionsMatched && each.isValue();
}
}
- if (containerMatch != null) {
- containerMatch.addInnerMatch(ruleElement, this, stream);
- }
}
+
public boolean matched() {
return baseConditionMatched && conditionsMatched && inlinedRulesMatched;
Modified: uima/ruta/trunk/ruta-core/src/main/java/org/apache/uima/ruta/rule/RutaRuleElement.java
URL: http://svn.apache.org/viewvc/uima/ruta/trunk/ruta-core/src/main/java/org/apache/uima/ruta/rule/RutaRuleElement.java?rev=1735237&r1=1735236&r2=1735237&view=diff
==============================================================================
--- uima/ruta/trunk/ruta-core/src/main/java/org/apache/uima/ruta/rule/RutaRuleElement.java (original)
+++ uima/ruta/trunk/ruta-core/src/main/java/org/apache/uima/ruta/rule/RutaRuleElement.java Wed Mar 16 15:04:01 2016
@@ -381,6 +381,11 @@ public class RutaRuleElement extends Abs
MatchContext context = new MatchContext(annotation, this, ruleMatch, after);
List<AnnotationFS> textsMatched = new ArrayList<AnnotationFS>(1);
+ if (annotation != null) {
+ textsMatched.add(annotation);
+ }
+ // already set the matched text and inform others
+ result.setMatchInfo(base, textsMatched, stream);
if (base) {
for (AbstractRutaCondition condition : conditions) {
crowd.beginVisit(condition, null);
@@ -389,10 +394,7 @@ public class RutaRuleElement extends Abs
evaluatedConditions.add(eval);
}
}
- if (annotation != null) {
- textsMatched.add(annotation);
- }
- result.setMatchInfo(base, textsMatched, evaluatedConditions, stream);
+ result.setConditionInfo(base, evaluatedConditions);
boolean inlinedRulesMatched = matchInnerRules(ruleMatch, stream, crowd);
result.setInlinedRulesMatched(inlinedRulesMatched);
ruleMatch.setMatched(ruleMatch.matched() && result.matched());
Modified: uima/ruta/trunk/ruta-core/src/main/java/org/apache/uima/ruta/rule/RutaTypeMatcher.java
URL: http://svn.apache.org/viewvc/uima/ruta/trunk/ruta-core/src/main/java/org/apache/uima/ruta/rule/RutaTypeMatcher.java?rev=1735237&r1=1735236&r2=1735237&view=diff
==============================================================================
--- uima/ruta/trunk/ruta-core/src/main/java/org/apache/uima/ruta/rule/RutaTypeMatcher.java (original)
+++ uima/ruta/trunk/ruta-core/src/main/java/org/apache/uima/ruta/rule/RutaTypeMatcher.java Wed Mar 16 15:04:01 2016
@@ -305,8 +305,7 @@ public class RutaTypeMatcher implements
Type type = getType(typeExpression, parent, stream, false);
result.add(type);
} else if (featureExpression != null) {
- Type type = getType(featureExpression.getTypeExpr(new MatchContext(parent), stream), parent,
- stream, false);
+ Type type = featureExpression.getInitialType(new MatchContext(parent), stream);
result.add(type);
}
return result;
Modified: uima/ruta/trunk/ruta-core/src/main/java/org/apache/uima/ruta/rule/WildCardRuleElement.java
URL: http://svn.apache.org/viewvc/uima/ruta/trunk/ruta-core/src/main/java/org/apache/uima/ruta/rule/WildCardRuleElement.java?rev=1735237&r1=1735236&r2=1735237&view=diff
==============================================================================
--- uima/ruta/trunk/ruta-core/src/main/java/org/apache/uima/ruta/rule/WildCardRuleElement.java (original)
+++ uima/ruta/trunk/ruta-core/src/main/java/org/apache/uima/ruta/rule/WildCardRuleElement.java Wed Mar 16 15:04:01 2016
@@ -636,6 +636,10 @@ public class WildCardRuleElement extends
MatchContext context = new MatchContext(annotation, this, ruleMatch, true);
List<AnnotationFS> textsMatched = new ArrayList<AnnotationFS>(1);
+ if (annotation != null) {
+ textsMatched.add(annotation);
+ }
+ result.setMatchInfo(base, textsMatched, stream);
if (base) {
for (AbstractRutaCondition condition : conditions) {
crowd.beginVisit(condition, null);
@@ -644,10 +648,7 @@ public class WildCardRuleElement extends
evaluatedConditions.add(eval);
}
}
- if (annotation != null) {
- textsMatched.add(annotation);
- }
- result.setMatchInfo(base, textsMatched, evaluatedConditions, stream);
+ result.setConditionInfo(base, evaluatedConditions);
ruleMatch.setMatched(ruleMatch.matched() && result.matched());
}
Modified: uima/ruta/trunk/ruta-core/src/main/java/org/apache/uima/ruta/verbalize/ExpressionVerbalizer.java
URL: http://svn.apache.org/viewvc/uima/ruta/trunk/ruta-core/src/main/java/org/apache/uima/ruta/verbalize/ExpressionVerbalizer.java?rev=1735237&r1=1735236&r2=1735237&view=diff
==============================================================================
--- uima/ruta/trunk/ruta-core/src/main/java/org/apache/uima/ruta/verbalize/ExpressionVerbalizer.java (original)
+++ uima/ruta/trunk/ruta-core/src/main/java/org/apache/uima/ruta/verbalize/ExpressionVerbalizer.java Wed Mar 16 15:04:01 2016
@@ -20,11 +20,11 @@
package org.apache.uima.ruta.verbalize;
import java.util.Iterator;
-import java.util.List;
import org.apache.uima.ruta.expression.AnnotationTypeExpression;
import org.apache.uima.ruta.expression.IRutaExpression;
import org.apache.uima.ruta.expression.MatchReference;
+import org.apache.uima.ruta.expression.NullExpression;
import org.apache.uima.ruta.expression.bool.BooleanFeatureExpression;
import org.apache.uima.ruta.expression.bool.BooleanListVariableExpression;
import org.apache.uima.ruta.expression.bool.BooleanNumberExpression;
@@ -286,15 +286,8 @@ public class ExpressionVerbalizer {
if (expression instanceof SimpleFeatureExpression) {
SimpleFeatureExpression sfe = (SimpleFeatureExpression) expression;
sb.append(sfe.getMatchReference().getMatch());
- } else {
- sb.append(verbalize(expression.getTypeExpr(null, null)));
- List<String> list = expression.getFeatureStringList(null, null);
- if (list != null) {
- for (String string : list) {
- sb.append(".");
- sb.append(string);
- }
- }
+ } else if(expression instanceof NullExpression) {
+ sb.append("null");
}
return sb.toString();
}
Modified: uima/ruta/trunk/ruta-core/src/test/java/org/apache/uima/ruta/condition/ContextCountTest.java
URL: http://svn.apache.org/viewvc/uima/ruta/trunk/ruta-core/src/test/java/org/apache/uima/ruta/condition/ContextCountTest.java?rev=1735237&r1=1735236&r2=1735237&view=diff
==============================================================================
--- uima/ruta/trunk/ruta-core/src/test/java/org/apache/uima/ruta/condition/ContextCountTest.java (original)
+++ uima/ruta/trunk/ruta-core/src/test/java/org/apache/uima/ruta/condition/ContextCountTest.java Wed Mar 16 15:04:01 2016
@@ -23,8 +23,6 @@ import static org.junit.Assert.assertEqu
import java.io.IOException;
-import junit.framework.Assert;
-
import org.apache.uima.analysis_engine.AnalysisEngineProcessException;
import org.apache.uima.cas.CAS;
import org.apache.uima.cas.CASException;
@@ -39,6 +37,8 @@ import org.apache.uima.ruta.engine.RutaT
import org.apache.uima.util.InvalidXMLException;
import org.junit.Test;
+import junit.framework.Assert;
+
public class ContextCountTest {
@Test
Modified: uima/ruta/trunk/ruta-core/src/test/java/org/apache/uima/ruta/expression/annotation/AnnotationLabelExpressionTest.java
URL: http://svn.apache.org/viewvc/uima/ruta/trunk/ruta-core/src/test/java/org/apache/uima/ruta/expression/annotation/AnnotationLabelExpressionTest.java?rev=1735237&r1=1735236&r2=1735237&view=diff
==============================================================================
--- uima/ruta/trunk/ruta-core/src/test/java/org/apache/uima/ruta/expression/annotation/AnnotationLabelExpressionTest.java (original)
+++ uima/ruta/trunk/ruta-core/src/test/java/org/apache/uima/ruta/expression/annotation/AnnotationLabelExpressionTest.java Wed Mar 16 15:04:01 2016
@@ -28,8 +28,6 @@ import java.util.List;
import java.util.Map;
import java.util.TreeMap;
-import junit.framework.Assert;
-
import org.apache.uima.analysis_engine.AnalysisEngineProcessException;
import org.apache.uima.cas.CAS;
import org.apache.uima.cas.CASException;
@@ -43,6 +41,7 @@ import org.apache.uima.ruta.engine.Ruta;
import org.apache.uima.ruta.engine.RutaTestUtils;
import org.apache.uima.ruta.engine.RutaTestUtils.TestFeature;
import org.apache.uima.util.InvalidXMLException;
+import org.junit.Assert;
import org.junit.Ignore;
import org.junit.Test;
@@ -274,16 +273,16 @@ public class AnnotationLabelExpressionTe
String script = "Document{-> Struct, Struct.a = i}<-{i:SW PERIOD;};";
script += "i:Document->{PERIOD{-> Struct2, Struct2.a = i};};";
script += "i:Document<-{PERIOD{-> Struct2, Struct2.a = i};};";
-
+
CAS cas = applyOnStruct4Cas(script);
-
+
Type t = null;
AnnotationIndex<AnnotationFS> ai = null;
FSIterator<AnnotationFS> iterator = null;
AnnotationFS a = null;
AnnotationFS next = null;
Feature f = null;
-
+
t = cas.getTypeSystem().getType("Struct1");
ai = cas.getAnnotationIndex(t);
assertEquals(1, ai.size());
@@ -307,9 +306,8 @@ public class AnnotationLabelExpressionTe
assertEquals("Some text.", a.getCoveredText());
}
-
+
@Test
- @Ignore
public void testFeature() throws ResourceInitializationException, InvalidXMLException,
IOException, AnalysisEngineProcessException, CASException {
CAS cas = RutaTestUtils.getCAS("Some text.");
@@ -317,6 +315,21 @@ public class AnnotationLabelExpressionTe
RutaTestUtils.assertAnnotationsEquals(cas, 1, 1, "text");
}
+ @Test
+ public void testComplexFeature() throws ResourceInitializationException, InvalidXMLException,
+ IOException, AnalysisEngineProcessException, CASException {
+ String script = "a:W W{-> CREATE(Struct1, \"a\"=a)};";
+ CAS cas = applyOnStruct4Cas(script);
+ Assert.assertTrue(Ruta.matches(cas.getJCas(), "a:Struct1{a.a.begin == 0 -> T1};"));
+ RutaTestUtils.assertAnnotationsEquals(cas, 1, 1, "text");
+ }
+
+ @Test(expected=AnalysisEngineProcessException.class)
+ public void testWrongFeature() throws ResourceInitializationException, InvalidXMLException,
+ IOException, AnalysisEngineProcessException, CASException {
+ CAS cas = RutaTestUtils.getCAS("Some text.");
+ Ruta.matches(cas.getJCas(), "a:W b:W{a.x == (b.y-1)-> T1};");
+ }
private CAS applyOnStruct4Cas(String script) {
String document = "Some text.";
@@ -343,6 +356,5 @@ public class AnnotationLabelExpressionTe
}
return cas;
}
-
-
+
}