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/11/08 20:02:07 UTC
svn commit: r1713281 - in
/uima/ruta/branches/UIMA-4408/ruta-core/src/main/java/org/apache/uima/ruta:
./ action/
Author: pkluegl
Date: Sun Nov 8 19:02:06 2015
New Revision: 1713281
URL: http://svn.apache.org/viewvc?rev=1713281&view=rev
Log:
UIMA-4408
- started to refactor feature assignment method to RutaStream
Modified:
uima/ruta/branches/UIMA-4408/ruta-core/src/main/java/org/apache/uima/ruta/RutaStream.java
uima/ruta/branches/UIMA-4408/ruta-core/src/main/java/org/apache/uima/ruta/action/AbstractRutaAction.java
uima/ruta/branches/UIMA-4408/ruta-core/src/main/java/org/apache/uima/ruta/action/AbstractStructureAction.java
uima/ruta/branches/UIMA-4408/ruta-core/src/main/java/org/apache/uima/ruta/action/CreateAction.java
uima/ruta/branches/UIMA-4408/ruta-core/src/main/java/org/apache/uima/ruta/action/FillAction.java
uima/ruta/branches/UIMA-4408/ruta-core/src/main/java/org/apache/uima/ruta/action/GatherAction.java
uima/ruta/branches/UIMA-4408/ruta-core/src/main/java/org/apache/uima/ruta/action/ImplicitFeatureAction.java
uima/ruta/branches/UIMA-4408/ruta-core/src/main/java/org/apache/uima/ruta/action/MatchedTextAction.java
Modified: uima/ruta/branches/UIMA-4408/ruta-core/src/main/java/org/apache/uima/ruta/RutaStream.java
URL: http://svn.apache.org/viewvc/uima/ruta/branches/UIMA-4408/ruta-core/src/main/java/org/apache/uima/ruta/RutaStream.java?rev=1713281&r1=1713280&r2=1713281&view=diff
==============================================================================
--- uima/ruta/branches/UIMA-4408/ruta-core/src/main/java/org/apache/uima/ruta/RutaStream.java (original)
+++ uima/ruta/branches/UIMA-4408/ruta-core/src/main/java/org/apache/uima/ruta/RutaStream.java Sun Nov 8 19:02:06 2015
@@ -24,6 +24,7 @@ import java.util.Collection;
import java.util.Collections;
import java.util.LinkedList;
import java.util.List;
+import java.util.Map;
import java.util.Map.Entry;
import java.util.NavigableMap;
import java.util.NoSuchElementException;
@@ -36,6 +37,7 @@ import org.apache.uima.cas.CASException;
import org.apache.uima.cas.ConstraintFactory;
import org.apache.uima.cas.FSIterator;
import org.apache.uima.cas.FSMatchConstraint;
+import org.apache.uima.cas.Feature;
import org.apache.uima.cas.FeatureStructure;
import org.apache.uima.cas.Type;
import org.apache.uima.cas.impl.FSIteratorImplBase;
@@ -44,10 +46,21 @@ import org.apache.uima.cas.text.Annotati
import org.apache.uima.jcas.JCas;
import org.apache.uima.jcas.tcas.Annotation;
import org.apache.uima.ruta.engine.RutaEngine;
+import org.apache.uima.ruta.expression.IRutaExpression;
+import org.apache.uima.ruta.expression.bool.IBooleanExpression;
+import org.apache.uima.ruta.expression.feature.FeatureExpression;
+import org.apache.uima.ruta.expression.feature.GenericFeatureExpression;
+import org.apache.uima.ruta.expression.feature.SimpleFeatureExpression;
+import org.apache.uima.ruta.expression.number.INumberExpression;
+import org.apache.uima.ruta.expression.string.IStringExpression;
+import org.apache.uima.ruta.expression.type.ITypeExpression;
+import org.apache.uima.ruta.expression.type.TypeExpression;
import org.apache.uima.ruta.rule.AbstractRule;
import org.apache.uima.ruta.rule.AbstractRuleMatch;
+import org.apache.uima.ruta.rule.MatchContext;
import org.apache.uima.ruta.type.RutaAnnotation;
import org.apache.uima.ruta.type.RutaBasic;
+import org.apache.uima.ruta.utils.UIMAUtils;
import org.apache.uima.ruta.visitor.InferenceCrowd;
public class RutaStream extends FSIteratorImplBase<AnnotationFS> {
@@ -893,4 +906,95 @@ public class RutaStream extends FSIterat
return result.toString();
}
+ public void assignFeatureValues(AnnotationFS annotation,
+ Map<IStringExpression, IRutaExpression> map, MatchContext context) {
+ Type type = annotation.getType();
+ Set<Entry<IStringExpression, IRutaExpression>> entrySet = map.entrySet();
+ for (Entry<IStringExpression, IRutaExpression> entry : entrySet) {
+ IStringExpression key = entry.getKey();
+ IRutaExpression value = entry.getValue();
+ String featureName = key.getStringValue(context, this);
+ Feature feature = type.getFeatureByBaseName(featureName);
+ assignFeatureValue(annotation, feature, value, context);
+ }
+ }
+
+ public void assignFeatureValue(AnnotationFS annotation, Feature feature, IRutaExpression value,
+ MatchContext context) {
+ if (feature == null) {
+ throw new IllegalArgumentException("Not able to assign feature value (e.g., coveredText).");
+ }
+ String range = feature.getRange().getName();
+ if (range.equals(UIMAConstants.TYPE_STRING)) {
+ if (value instanceof IStringExpression) {
+ IStringExpression stringExpr = (IStringExpression) value;
+ String string = stringExpr.getStringValue(context, this);
+ annotation.setStringValue(feature, string);
+ }
+ } else if (value instanceof INumberExpression
+ && (range.equals(UIMAConstants.TYPE_INTEGER) || range.equals(UIMAConstants.TYPE_LONG)
+ || range.equals(UIMAConstants.TYPE_SHORT) || range
+ .equals(UIMAConstants.TYPE_BYTE))) {
+ INumberExpression numberExpr = (INumberExpression) value;
+ int v = numberExpr.getIntegerValue(context, this);
+ annotation.setIntValue(feature, v);
+ } else if (value instanceof INumberExpression && (range.equals(UIMAConstants.TYPE_DOUBLE))) {
+ INumberExpression numberExpr = (INumberExpression) value;
+ double v = numberExpr.getDoubleValue(context, this);
+ annotation.setDoubleValue(feature, v);
+ } else if (value instanceof INumberExpression && (range.equals(UIMAConstants.TYPE_FLOAT))) {
+ INumberExpression numberExpr = (INumberExpression) value;
+ float v = numberExpr.getFloatValue(context, this);
+ annotation.setFloatValue(feature, v);
+ } else if (value instanceof IBooleanExpression && (range.equals(UIMAConstants.TYPE_BOOLEAN))) {
+ IBooleanExpression booleanExpr = (IBooleanExpression) value;
+ boolean v = booleanExpr.getBooleanValue(context, this);
+ annotation.setBooleanValue(feature, v);
+ } else if (value instanceof IBooleanExpression && (range.equals(UIMAConstants.TYPE_BOOLEAN))) {
+ IBooleanExpression booleanExpr = (IBooleanExpression) value;
+ boolean v = booleanExpr.getBooleanValue(context, this);
+ annotation.setBooleanValue(feature, v);
+ } else if (value instanceof ITypeExpression && !feature.getRange().isPrimitive()) {
+ ITypeExpression typeExpr = (ITypeExpression) value;
+ Type t = typeExpr.getType(context, this);
+ List<AnnotationFS> inWindow = this.getAnnotationsInWindow(context.getAnnotation(), t);
+ if (feature.getRange().isArray()) {
+ annotation.setFeatureValue(feature, UIMAUtils.toFSArray(this.getJCas(), inWindow));
+ } else {
+ if (inWindow != null && !inWindow.isEmpty()) {
+ AnnotationFS a = inWindow.get(0);
+ annotation.setFeatureValue(feature, a);
+ } else {
+ annotation.setFeatureValue(feature, null);
+ }
+ }
+ } else if (value instanceof GenericFeatureExpression && !feature.getRange().isPrimitive()) {
+ FeatureExpression fe = ((GenericFeatureExpression) value).getFeatureExpression();
+ TypeExpression typeExpr = fe.getTypeExpr(context, this);
+ Type t = typeExpr.getType(context, this);
+ List<AnnotationFS> inWindow = this.getAnnotationsInWindow(context.getAnnotation(), t);
+ if (fe instanceof SimpleFeatureExpression) {
+ SimpleFeatureExpression sfe = (SimpleFeatureExpression) fe;
+ List<AnnotationFS> featureAnnotations = inWindow;
+ if (fe.getFeatures(context, this) != null) {
+ featureAnnotations = new ArrayList<AnnotationFS>(sfe.getFeatureAnnotations(inWindow,
+ this, context, false));
+ }
+ if (feature.getRange().isArray()) {
+ annotation.setFeatureValue(feature,
+ UIMAUtils.toFSArray(this.getJCas(), featureAnnotations));
+ } else if (!featureAnnotations.isEmpty()) {
+ AnnotationFS a = featureAnnotations.get(0);
+ annotation.setFeatureValue(feature, a);
+ }
+ } else {
+ if (feature.getRange().isArray()) {
+ annotation.setFeatureValue(feature, UIMAUtils.toFSArray(this.getJCas(), inWindow));
+ } else {
+ AnnotationFS a = inWindow.get(0);
+ annotation.setFeatureValue(feature, a);
+ }
+ }
+ }
+ }
}
Modified: uima/ruta/branches/UIMA-4408/ruta-core/src/main/java/org/apache/uima/ruta/action/AbstractRutaAction.java
URL: http://svn.apache.org/viewvc/uima/ruta/branches/UIMA-4408/ruta-core/src/main/java/org/apache/uima/ruta/action/AbstractRutaAction.java?rev=1713281&r1=1713280&r2=1713281&view=diff
==============================================================================
--- uima/ruta/branches/UIMA-4408/ruta-core/src/main/java/org/apache/uima/ruta/action/AbstractRutaAction.java (original)
+++ uima/ruta/branches/UIMA-4408/ruta-core/src/main/java/org/apache/uima/ruta/action/AbstractRutaAction.java Sun Nov 8 19:02:06 2015
@@ -19,9 +19,14 @@
package org.apache.uima.ruta.action;
+import java.util.ArrayList;
+import java.util.List;
+
import org.apache.uima.ruta.RutaElement;
import org.apache.uima.ruta.RutaStream;
+import org.apache.uima.ruta.expression.number.INumberExpression;
import org.apache.uima.ruta.rule.MatchContext;
+import org.apache.uima.ruta.rule.RuleElement;
import org.apache.uima.ruta.visitor.InferenceCrowd;
public abstract class AbstractRutaAction extends RutaElement {
@@ -37,4 +42,24 @@ public abstract class AbstractRutaAction
return getClass().getSimpleName();
}
+ protected List<Integer> getIndexList(List<INumberExpression> indexes, MatchContext context, RutaStream stream) {
+ RuleElement element = context.getElement();
+ List<Integer> indexList = new ArrayList<Integer>();
+ if (indexes == null || indexes.isEmpty()) {
+ int self = element.getContainer().getRuleElements().indexOf(element) + 1;
+ indexList.add(self);
+ return indexList;
+ }
+ int last = Integer.MAX_VALUE - 1;
+ for (INumberExpression each : indexes) {
+ // no feature matches allowed
+ int value = each.getIntegerValue(context, stream);
+ for (int i = Math.min(value, last + 1); i < value; i++) {
+ indexList.add(i);
+ }
+ indexList.add(value);
+ }
+ return indexList;
+ }
+
}
Modified: uima/ruta/branches/UIMA-4408/ruta-core/src/main/java/org/apache/uima/ruta/action/AbstractStructureAction.java
URL: http://svn.apache.org/viewvc/uima/ruta/branches/UIMA-4408/ruta-core/src/main/java/org/apache/uima/ruta/action/AbstractStructureAction.java?rev=1713281&r1=1713280&r2=1713281&view=diff
==============================================================================
--- uima/ruta/branches/UIMA-4408/ruta-core/src/main/java/org/apache/uima/ruta/action/AbstractStructureAction.java (original)
+++ uima/ruta/branches/UIMA-4408/ruta-core/src/main/java/org/apache/uima/ruta/action/AbstractStructureAction.java Sun Nov 8 19:02:06 2015
@@ -50,7 +50,7 @@ public abstract class AbstractStructureA
super();
}
- protected void fillFeatures(TOP structure, Map<IStringExpression, IRutaExpression> features,
+ protected void fillFeatures2(TOP structure, Map<IStringExpression, IRutaExpression> features,
AnnotationFS matchedAnnotation, MatchContext context, RutaStream stream) {
Map<String, IRutaExpression> map = new HashMap<String, IRutaExpression>();
for (Entry<IStringExpression, IRutaExpression> each : features.entrySet()) {
Modified: uima/ruta/branches/UIMA-4408/ruta-core/src/main/java/org/apache/uima/ruta/action/CreateAction.java
URL: http://svn.apache.org/viewvc/uima/ruta/branches/UIMA-4408/ruta-core/src/main/java/org/apache/uima/ruta/action/CreateAction.java?rev=1713281&r1=1713280&r2=1713281&view=diff
==============================================================================
--- uima/ruta/branches/UIMA-4408/ruta-core/src/main/java/org/apache/uima/ruta/action/CreateAction.java (original)
+++ uima/ruta/branches/UIMA-4408/ruta-core/src/main/java/org/apache/uima/ruta/action/CreateAction.java Sun Nov 8 19:02:06 2015
@@ -19,15 +19,12 @@
package org.apache.uima.ruta.action;
-import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
-import org.apache.uima.cas.FeatureStructure;
import org.apache.uima.cas.Type;
import org.apache.uima.cas.text.AnnotationFS;
-import org.apache.uima.jcas.cas.TOP;
import org.apache.uima.jcas.tcas.Annotation;
import org.apache.uima.ruta.RutaStream;
import org.apache.uima.ruta.expression.IRutaExpression;
@@ -59,7 +56,7 @@ public class CreateAction extends Abstra
public void execute(MatchContext context, RutaStream stream, InferenceCrowd crowd) {
RuleMatch match = context.getRuleMatch();
RuleElement element = context.getElement();
- List<Integer> indexList = getIndexList(context, stream);
+ List<Integer> indexList = getIndexList(indexes, context, stream);
List<AnnotationFS> matchedAnnotations = match.getMatchedAnnotations(indexList,
element.getContainer());
for (AnnotationFS matchedAnnotation : matchedAnnotations) {
@@ -68,41 +65,16 @@ public class CreateAction extends Abstra
return;
}
Type type = structureType.getType(context, stream);
- FeatureStructure newFS = stream.getCas().createFS(type);
- if (newFS instanceof Annotation) {
- Annotation a = (Annotation) newFS;
+ AnnotationFS annotation = stream.getCas().createAnnotation(type, 0, 0);
+ if (annotation instanceof Annotation) {
+ Annotation a = (Annotation) annotation;
a.setBegin(matchedAnnotation.getBegin());
a.setEnd(matchedAnnotation.getEnd());
- stream.addAnnotation(a, match);
+ context.setAnnotation(matchedAnnotation);
+ stream.assignFeatureValues(annotation, features, context);
+ stream.addAnnotation(a, true, match);
}
- TOP newStructure = null;
- if (newFS instanceof TOP) {
- newStructure = (TOP) newFS;
- fillFeatures(newStructure, features, matchedAnnotation, context, stream);
- newStructure.addToIndexes();
- }
- }
- }
-
- // TODO refactor duplicate methods -> MarkAction
- protected List<Integer> getIndexList(MatchContext context, RutaStream stream) {
- RuleElement element = context.getElement();
- List<Integer> indexList = new ArrayList<Integer>();
- if (indexes == null || indexes.isEmpty()) {
- int self = element.getContainer().getRuleElements().indexOf(element) + 1;
- indexList.add(self);
- return indexList;
- }
- int last = Integer.MAX_VALUE - 1;
- for (INumberExpression each : indexes) {
- // no feature matches allowed
- int value = each.getIntegerValue(context, stream);
- for (int i = Math.min(value, last + 1); i < value; i++) {
- indexList.add(i);
- }
- indexList.add(value);
}
- return indexList;
}
public TypeExpression getStructureType() {
Modified: uima/ruta/branches/UIMA-4408/ruta-core/src/main/java/org/apache/uima/ruta/action/FillAction.java
URL: http://svn.apache.org/viewvc/uima/ruta/branches/UIMA-4408/ruta-core/src/main/java/org/apache/uima/ruta/action/FillAction.java?rev=1713281&r1=1713280&r2=1713281&view=diff
==============================================================================
--- uima/ruta/branches/UIMA-4408/ruta-core/src/main/java/org/apache/uima/ruta/action/FillAction.java (original)
+++ uima/ruta/branches/UIMA-4408/ruta-core/src/main/java/org/apache/uima/ruta/action/FillAction.java Sun Nov 8 19:02:06 2015
@@ -24,7 +24,6 @@ import java.util.Map;
import org.apache.uima.cas.Type;
import org.apache.uima.cas.text.AnnotationFS;
-import org.apache.uima.jcas.tcas.Annotation;
import org.apache.uima.ruta.RutaStream;
import org.apache.uima.ruta.expression.IRutaExpression;
import org.apache.uima.ruta.expression.string.IStringExpression;
@@ -75,7 +74,8 @@ public class FillAction extends Abstract
if (!list.isEmpty()) {
AnnotationFS annotationFS = list.get(0);
stream.getCas().removeFsFromIndexes(annotationFS);
- fillFeatures((Annotation) annotationFS, features, matchedAnnotation, context, stream);
+ context.setAnnotation(matchedAnnotation);
+ stream.assignFeatureValues(annotationFS, features, context);
stream.getCas().addFsToIndexes(annotationFS);
}
}
Modified: uima/ruta/branches/UIMA-4408/ruta-core/src/main/java/org/apache/uima/ruta/action/GatherAction.java
URL: http://svn.apache.org/viewvc/uima/ruta/branches/UIMA-4408/ruta-core/src/main/java/org/apache/uima/ruta/action/GatherAction.java?rev=1713281&r1=1713280&r2=1713281&view=diff
==============================================================================
--- uima/ruta/branches/UIMA-4408/ruta-core/src/main/java/org/apache/uima/ruta/action/GatherAction.java (original)
+++ uima/ruta/branches/UIMA-4408/ruta-core/src/main/java/org/apache/uima/ruta/action/GatherAction.java Sun Nov 8 19:02:06 2015
@@ -71,7 +71,7 @@ public class GatherAction extends Abstra
public void execute(MatchContext context, RutaStream stream, InferenceCrowd crowd) {
RuleMatch match = context.getRuleMatch();
RuleElement element = context.getElement();
- List<Integer> indexList = getIndexList(context, stream);
+ List<Integer> indexList = getIndexList(indexes, context, stream);
List<AnnotationFS> matchedAnnotations = match.getMatchedAnnotations(indexList,
element.getContainer());
for (AnnotationFS matchedAnnotation : matchedAnnotations) {
@@ -209,26 +209,6 @@ public class GatherAction extends Abstra
return result;
}
- // TODO refactor duplicate methods -> MarkAction
- protected List<Integer> getIndexList(MatchContext context, RutaStream stream) {
- RuleElement element = context.getElement();
- List<Integer> indexList = new ArrayList<Integer>();
- if (indexes == null || indexes.isEmpty()) {
- int self = element.getContainer().getRuleElements().indexOf(element) + 1;
- indexList.add(self);
- return indexList;
- }
- int last = Integer.MAX_VALUE - 1;
- for (INumberExpression each : indexes) {
- // no feature matches allowed
- int value = each.getIntegerValue(context, stream);
- for (int i = Math.min(value, last + 1); i < value; i++) {
- indexList.add(i);
- }
- indexList.add(value);
- }
- return indexList;
- }
public TypeExpression getStructureType() {
return structureType;
Modified: uima/ruta/branches/UIMA-4408/ruta-core/src/main/java/org/apache/uima/ruta/action/ImplicitFeatureAction.java
URL: http://svn.apache.org/viewvc/uima/ruta/branches/UIMA-4408/ruta-core/src/main/java/org/apache/uima/ruta/action/ImplicitFeatureAction.java?rev=1713281&r1=1713280&r2=1713281&view=diff
==============================================================================
--- uima/ruta/branches/UIMA-4408/ruta-core/src/main/java/org/apache/uima/ruta/action/ImplicitFeatureAction.java (original)
+++ uima/ruta/branches/UIMA-4408/ruta-core/src/main/java/org/apache/uima/ruta/action/ImplicitFeatureAction.java Sun Nov 8 19:02:06 2015
@@ -31,22 +31,13 @@ import org.apache.uima.cas.Type;
import org.apache.uima.cas.TypeSystem;
import org.apache.uima.cas.text.AnnotationFS;
import org.apache.uima.ruta.RutaStream;
-import org.apache.uima.ruta.UIMAConstants;
import org.apache.uima.ruta.expression.IRutaExpression;
-import org.apache.uima.ruta.expression.bool.IBooleanExpression;
-import org.apache.uima.ruta.expression.feature.FeatureExpression;
import org.apache.uima.ruta.expression.feature.FeatureMatchExpression;
-import org.apache.uima.ruta.expression.feature.GenericFeatureExpression;
-import org.apache.uima.ruta.expression.feature.SimpleFeatureExpression;
-import org.apache.uima.ruta.expression.number.INumberExpression;
-import org.apache.uima.ruta.expression.string.IStringExpression;
-import org.apache.uima.ruta.expression.type.ITypeExpression;
import org.apache.uima.ruta.expression.type.TypeExpression;
import org.apache.uima.ruta.rule.AnnotationComparator;
import org.apache.uima.ruta.rule.MatchContext;
import org.apache.uima.ruta.rule.RuleElement;
import org.apache.uima.ruta.rule.RuleMatch;
-import org.apache.uima.ruta.utils.UIMAUtils;
import org.apache.uima.ruta.visitor.InferenceCrowd;
public class ImplicitFeatureAction extends AbstractRutaAction {
@@ -83,87 +74,13 @@ public class ImplicitFeatureAction exten
Feature feature = expr.getFeature(context, stream);
IRutaExpression arg = expr.getArg();
for (AnnotationFS each : featureAnnotations) {
- setFeatureValue(each, feature, arg, context, stream);
+ stream.assignFeatureValue(each, feature, arg, context);
}
for (AnnotationFS each : annotations) {
stream.getCas().addFsToIndexes(each);
}
}
- private void setFeatureValue(AnnotationFS a, Feature feature, IRutaExpression argExpr,
- MatchContext context, RutaStream stream) {
- if (feature == null) {
- throw new IllegalArgumentException("Not able to assign feature value (e.g., coveredText).");
- }
- String range = feature.getRange().getName();
- if (range.equals(UIMAConstants.TYPE_STRING)) {
- if (argExpr instanceof IStringExpression) {
- IStringExpression stringExpr = (IStringExpression) argExpr;
- String string = stringExpr.getStringValue(context, stream);
- a.setStringValue(feature, string);
- }
- } else if (argExpr instanceof INumberExpression
- && (range.equals(UIMAConstants.TYPE_INTEGER) || range.equals(UIMAConstants.TYPE_LONG)
- || range.equals(UIMAConstants.TYPE_SHORT) || range
- .equals(UIMAConstants.TYPE_BYTE))) {
- INumberExpression numberExpr = (INumberExpression) argExpr;
- int v = numberExpr.getIntegerValue(context, stream);
- a.setIntValue(feature, v);
- } else if (argExpr instanceof INumberExpression && (range.equals(UIMAConstants.TYPE_DOUBLE))) {
- INumberExpression numberExpr = (INumberExpression) argExpr;
- double v = numberExpr.getDoubleValue(context, stream);
- a.setDoubleValue(feature, v);
- } else if (argExpr instanceof INumberExpression && (range.equals(UIMAConstants.TYPE_FLOAT))) {
- INumberExpression numberExpr = (INumberExpression) argExpr;
- float v = numberExpr.getFloatValue(context, stream);
- a.setFloatValue(feature, v);
- } else if (argExpr instanceof IBooleanExpression && (range.equals(UIMAConstants.TYPE_BOOLEAN))) {
- IBooleanExpression booleanExpr = (IBooleanExpression) argExpr;
- boolean v = booleanExpr.getBooleanValue(context, stream);
- a.setBooleanValue(feature, v);
- } else if (argExpr instanceof IBooleanExpression && (range.equals(UIMAConstants.TYPE_BOOLEAN))) {
- IBooleanExpression booleanExpr = (IBooleanExpression) argExpr;
- boolean v = booleanExpr.getBooleanValue(context, stream);
- a.setBooleanValue(feature, v);
- } else if (argExpr instanceof ITypeExpression && !feature.getRange().isPrimitive()) {
- ITypeExpression typeExpr = (ITypeExpression) argExpr;
- Type t = typeExpr.getType(context, stream);
- List<AnnotationFS> inWindow = stream.getAnnotationsInWindow(a, t);
- if (feature.getRange().isArray()) {
- a.setFeatureValue(feature, UIMAUtils.toFSArray(stream.getJCas(), inWindow));
- } else {
- if (inWindow != null && !inWindow.isEmpty()) {
- AnnotationFS annotation = inWindow.get(0);
- a.setFeatureValue(feature, annotation);
- } else {
- a.setFeatureValue(feature, null);
- }
- }
- } else if (argExpr instanceof GenericFeatureExpression && !feature.getRange().isPrimitive()) {
- FeatureExpression fe = ((GenericFeatureExpression) argExpr).getFeatureExpression();
- TypeExpression typeExpr = fe.getTypeExpr(context, stream);
- Type t = typeExpr.getType(context, stream);
- List<AnnotationFS> inWindow = stream.getAnnotationsInWindow(a, t);
- if (fe instanceof SimpleFeatureExpression) {
- SimpleFeatureExpression sfe = (SimpleFeatureExpression) fe;
- List<AnnotationFS> featureAnnotations = new ArrayList<>(sfe.getFeatureAnnotations(inWindow,
- stream, context, false));
- if (feature.getRange().isArray()) {
- a.setFeatureValue(feature, UIMAUtils.toFSArray(stream.getJCas(), featureAnnotations));
- } else if (!featureAnnotations.isEmpty()) {
- AnnotationFS annotation = featureAnnotations.get(0);
- a.setFeatureValue(feature, annotation);
- }
- } else {
- if (feature.getRange().isArray()) {
- a.setFeatureValue(feature, UIMAUtils.toFSArray(stream.getJCas(), inWindow));
- } else {
- AnnotationFS annotation = inWindow.get(0);
- a.setFeatureValue(feature, annotation);
- }
- }
- }
- }
private List<AnnotationFS> getAnnotations(AnnotationFS annotation, Type type,
FeatureMatchExpression fme, RutaStream stream) {
Modified: uima/ruta/branches/UIMA-4408/ruta-core/src/main/java/org/apache/uima/ruta/action/MatchedTextAction.java
URL: http://svn.apache.org/viewvc/uima/ruta/branches/UIMA-4408/ruta-core/src/main/java/org/apache/uima/ruta/action/MatchedTextAction.java?rev=1713281&r1=1713280&r2=1713281&view=diff
==============================================================================
--- uima/ruta/branches/UIMA-4408/ruta-core/src/main/java/org/apache/uima/ruta/action/MatchedTextAction.java (original)
+++ uima/ruta/branches/UIMA-4408/ruta-core/src/main/java/org/apache/uima/ruta/action/MatchedTextAction.java Sun Nov 8 19:02:06 2015
@@ -19,7 +19,6 @@
package org.apache.uima.ruta.action;
-import java.util.ArrayList;
import java.util.List;
import org.apache.uima.cas.text.AnnotationFS;
@@ -46,7 +45,7 @@ public class MatchedTextAction extends A
public void execute(MatchContext context, RutaStream stream, InferenceCrowd crowd) {
RuleMatch match = context.getRuleMatch();
RuleElement element = context.getElement();
- List<Integer> indexList = getIndexList(context, stream);
+ List<Integer> indexList = getIndexList(list, context, stream);
List<AnnotationFS> matchedAnnotations = match.getMatchedAnnotations(indexList,
element.getContainer());
for (AnnotationFS matchedAnnotation : matchedAnnotations) {
@@ -63,23 +62,4 @@ public class MatchedTextAction extends A
return list;
}
- protected List<Integer> getIndexList(MatchContext context, RutaStream stream) {
- RuleElement element = context.getElement();
- List<Integer> indexList = new ArrayList<Integer>();
- if (list == null || list.isEmpty()) {
- int self = element.getContainer().getRuleElements().indexOf(element) + 1;
- indexList.add(self);
- return indexList;
- }
- int last = Integer.MAX_VALUE - 1;
- for (INumberExpression each : list) {
- // not allowed for feature matches
- int value = each.getIntegerValue(context, stream);
- for (int i = Math.min(value, last + 1); i < value; i++) {
- indexList.add(i);
- }
- indexList.add(value);
- }
- return indexList;
- }
}