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/06 18:17:45 UTC
svn commit: r1712988 [4/5] - in /uima/ruta/branches/UIMA-4408:
example-projects/ruta-ep-example-extensions/src/main/java/org/apache/uima/ruta/example/extensions/
ruta-core-ext/src/main/java/org/apache/uima/ruta/block/fst/
ruta-core-ext/src/main/java/or...
Modified: uima/ruta/branches/UIMA-4408/ruta-core/src/main/java/org/apache/uima/ruta/expression/number/INumberExpression.java
URL: http://svn.apache.org/viewvc/uima/ruta/branches/UIMA-4408/ruta-core/src/main/java/org/apache/uima/ruta/expression/number/INumberExpression.java?rev=1712988&r1=1712987&r2=1712988&view=diff
==============================================================================
--- uima/ruta/branches/UIMA-4408/ruta-core/src/main/java/org/apache/uima/ruta/expression/number/INumberExpression.java (original)
+++ uima/ruta/branches/UIMA-4408/ruta-core/src/main/java/org/apache/uima/ruta/expression/number/INumberExpression.java Fri Nov 6 17:17:42 2015
@@ -19,25 +19,18 @@
package org.apache.uima.ruta.expression.number;
-import org.apache.uima.cas.text.AnnotationFS;
-import org.apache.uima.ruta.RutaBlock;
import org.apache.uima.ruta.RutaStream;
import org.apache.uima.ruta.expression.string.IStringExpression;
+import org.apache.uima.ruta.rule.MatchContext;
import org.apache.uima.ruta.rule.RuleElement;
import org.apache.uima.ruta.rule.RuleMatch;
public interface INumberExpression extends IStringExpression {
- int getIntegerValue(RutaBlock parent, RuleMatch match, RuleElement element, RutaStream stream);
+ int getIntegerValue(MatchContext context, RutaStream stream);
- double getDoubleValue(RutaBlock parent, RuleMatch match, RuleElement element, RutaStream stream);
+ double getDoubleValue(MatchContext context, RutaStream stream);
- float getFloatValue(RutaBlock parent, RuleMatch match, RuleElement element, RutaStream stream);
-
- int getIntegerValue(RutaBlock parent, AnnotationFS annotation, RutaStream stream);
-
- double getDoubleValue(RutaBlock parent, AnnotationFS annotation, RutaStream stream);
-
- float getFloatValue(RutaBlock parent, AnnotationFS annotation, RutaStream stream);
+ float getFloatValue(MatchContext context, RutaStream stream);
}
Modified: uima/ruta/branches/UIMA-4408/ruta-core/src/main/java/org/apache/uima/ruta/expression/number/NegativeNumberExpression.java
URL: http://svn.apache.org/viewvc/uima/ruta/branches/UIMA-4408/ruta-core/src/main/java/org/apache/uima/ruta/expression/number/NegativeNumberExpression.java?rev=1712988&r1=1712987&r2=1712988&view=diff
==============================================================================
--- uima/ruta/branches/UIMA-4408/ruta-core/src/main/java/org/apache/uima/ruta/expression/number/NegativeNumberExpression.java (original)
+++ uima/ruta/branches/UIMA-4408/ruta-core/src/main/java/org/apache/uima/ruta/expression/number/NegativeNumberExpression.java Fri Nov 6 17:17:42 2015
@@ -19,9 +19,8 @@
package org.apache.uima.ruta.expression.number;
-import org.apache.uima.cas.text.AnnotationFS;
-import org.apache.uima.ruta.RutaBlock;
import org.apache.uima.ruta.RutaStream;
+import org.apache.uima.ruta.rule.MatchContext;
public class NegativeNumberExpression extends AbstractNumberExpression {
@@ -32,20 +31,20 @@ public class NegativeNumberExpression ex
this.ne = simpleNumberExpression;
}
- public double getDoubleValue(RutaBlock parent, AnnotationFS annotation, RutaStream stream) {
- return -ne.getDoubleValue(parent, annotation, stream);
+ public double getDoubleValue(MatchContext context, RutaStream stream) {
+ return -ne.getDoubleValue(context, stream);
}
- public float getFloatValue(RutaBlock parent, AnnotationFS annotation, RutaStream stream) {
- return -ne.getFloatValue(parent, annotation, stream);
+ public float getFloatValue(MatchContext context, RutaStream stream) {
+ return -ne.getFloatValue(context, stream);
}
- public int getIntegerValue(RutaBlock parent, AnnotationFS annotation, RutaStream stream) {
- return -ne.getIntegerValue(parent, annotation, stream);
+ public int getIntegerValue(MatchContext context, RutaStream stream) {
+ return -ne.getIntegerValue(context, stream);
}
- public String getStringValue(RutaBlock parent, AnnotationFS annotation, RutaStream stream) {
- return "-" + ne.getStringValue(parent, annotation, stream);
+ public String getStringValue(MatchContext context, RutaStream stream) {
+ return "-" + ne.getStringValue(context, stream);
}
public INumberExpression getExpression() {
Modified: uima/ruta/branches/UIMA-4408/ruta-core/src/main/java/org/apache/uima/ruta/expression/number/NumberFeatureExpression.java
URL: http://svn.apache.org/viewvc/uima/ruta/branches/UIMA-4408/ruta-core/src/main/java/org/apache/uima/ruta/expression/number/NumberFeatureExpression.java?rev=1712988&r1=1712987&r2=1712988&view=diff
==============================================================================
--- uima/ruta/branches/UIMA-4408/ruta-core/src/main/java/org/apache/uima/ruta/expression/number/NumberFeatureExpression.java (original)
+++ uima/ruta/branches/UIMA-4408/ruta-core/src/main/java/org/apache/uima/ruta/expression/number/NumberFeatureExpression.java Fri Nov 6 17:17:42 2015
@@ -29,6 +29,7 @@ import org.apache.uima.ruta.RutaBlock;
import org.apache.uima.ruta.RutaStream;
import org.apache.uima.ruta.UIMAConstants;
import org.apache.uima.ruta.expression.feature.FeatureExpression;
+import org.apache.uima.ruta.rule.MatchContext;
public class NumberFeatureExpression extends AbstractNumberExpression {
@@ -39,28 +40,30 @@ public class NumberFeatureExpression ext
this.fe = fe;
}
- public int getIntegerValue(RutaBlock parent, AnnotationFS annotation, RutaStream stream) {
- Number v = getNumberValue(parent, annotation, stream);
+ public int getIntegerValue(MatchContext context, RutaStream stream) {
+ Number v = getNumberValue(context, stream);
return v == null ? 0 : v.intValue();
}
- public double getDoubleValue(RutaBlock parent, AnnotationFS annotation, RutaStream stream) {
- Number v = getNumberValue(parent, annotation, stream);
+ public double getDoubleValue(MatchContext context, RutaStream stream) {
+ Number v = getNumberValue(context, stream);
return v == null ? 0 : v.doubleValue();
}
- public float getFloatValue(RutaBlock parent, AnnotationFS annotation, RutaStream stream) {
- Number v = getNumberValue(parent, annotation, stream);
+ public float getFloatValue(MatchContext context, RutaStream stream) {
+ Number v = getNumberValue(context, stream);
return v == null ? 0 : v.floatValue();
}
- private Number getNumberValue(RutaBlock parent, AnnotationFS annotation, RutaStream stream) {
+ private Number getNumberValue(MatchContext context, RutaStream stream) {
+ AnnotationFS annotation = context.getAnnotation();
+ RutaBlock parent = context.getParent();
Number result = null;
- Type type = fe.getTypeExpr(parent).getType(parent);
- Feature feature = fe.getFeature(parent);
+ 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);
- Collection<AnnotationFS> featureAnnotations = fe.getFeatureAnnotations(list, stream, parent,
+ Collection<AnnotationFS> featureAnnotations = fe.getFeatureAnnotations(list, stream, context,
false);
if (!featureAnnotations.isEmpty()) {
AnnotationFS next = featureAnnotations.iterator().next();
@@ -82,8 +85,8 @@ public class NumberFeatureExpression ext
}
@Override
- public String getStringValue(RutaBlock parent, AnnotationFS annotation, RutaStream stream) {
- return "" + getNumberValue(parent, annotation, stream);
+ public String getStringValue(MatchContext context, RutaStream stream) {
+ return "" + getNumberValue(context, stream);
}
public FeatureExpression getFe() {
Modified: uima/ruta/branches/UIMA-4408/ruta-core/src/main/java/org/apache/uima/ruta/expression/number/NumberVariableExpression.java
URL: http://svn.apache.org/viewvc/uima/ruta/branches/UIMA-4408/ruta-core/src/main/java/org/apache/uima/ruta/expression/number/NumberVariableExpression.java?rev=1712988&r1=1712987&r2=1712988&view=diff
==============================================================================
--- uima/ruta/branches/UIMA-4408/ruta-core/src/main/java/org/apache/uima/ruta/expression/number/NumberVariableExpression.java (original)
+++ uima/ruta/branches/UIMA-4408/ruta-core/src/main/java/org/apache/uima/ruta/expression/number/NumberVariableExpression.java Fri Nov 6 17:17:42 2015
@@ -19,9 +19,9 @@
package org.apache.uima.ruta.expression.number;
-import org.apache.uima.cas.text.AnnotationFS;
import org.apache.uima.ruta.RutaBlock;
import org.apache.uima.ruta.RutaStream;
+import org.apache.uima.ruta.rule.MatchContext;
public class NumberVariableExpression extends AbstractNumberExpression {
@@ -32,7 +32,8 @@ public class NumberVariableExpression ex
this.var = var;
}
- public double getDoubleValue(RutaBlock parent, AnnotationFS annotation, RutaStream stream) {
+ public double getDoubleValue(MatchContext context, RutaStream stream) {
+ RutaBlock parent = context.getParent();
Object value = parent.getEnvironment().getVariableValue(getVar());
double variableValue = 0;
if (value instanceof Number) {
@@ -41,7 +42,8 @@ public class NumberVariableExpression ex
return variableValue;
}
- public float getFloatValue(RutaBlock parent, AnnotationFS annotation, RutaStream stream) {
+ public float getFloatValue(MatchContext context, RutaStream stream) {
+ RutaBlock parent = context.getParent();
Object value = parent.getEnvironment().getVariableValue(getVar());
float variableValue = 0;
if (value instanceof Number) {
@@ -50,7 +52,8 @@ public class NumberVariableExpression ex
return variableValue;
}
- public int getIntegerValue(RutaBlock parent, AnnotationFS annotation, RutaStream stream) {
+ public int getIntegerValue(MatchContext context, RutaStream stream) {
+ RutaBlock parent = context.getParent();
Object value = parent.getEnvironment().getVariableValue(getVar());
int variableValue = 0;
if (value instanceof Number) {
@@ -59,12 +62,13 @@ public class NumberVariableExpression ex
return variableValue;
}
- public String getStringValue(RutaBlock parent, AnnotationFS annotation, RutaStream stream) {
+ public String getStringValue(MatchContext context, RutaStream stream) {
+ RutaBlock parent = context.getParent();
Class<?> variableType = parent.getEnvironment().getVariableType(getVar());
if (variableType.equals(Integer.class)) {
- return "" + getIntegerValue(parent, annotation, stream);
+ return "" + getIntegerValue(context, stream);
} else {
- return "" + getDoubleValue(parent, annotation, stream);
+ return "" + getDoubleValue(context, stream);
}
}
Modified: uima/ruta/branches/UIMA-4408/ruta-core/src/main/java/org/apache/uima/ruta/expression/number/SimpleNumberExpression.java
URL: http://svn.apache.org/viewvc/uima/ruta/branches/UIMA-4408/ruta-core/src/main/java/org/apache/uima/ruta/expression/number/SimpleNumberExpression.java?rev=1712988&r1=1712987&r2=1712988&view=diff
==============================================================================
--- uima/ruta/branches/UIMA-4408/ruta-core/src/main/java/org/apache/uima/ruta/expression/number/SimpleNumberExpression.java (original)
+++ uima/ruta/branches/UIMA-4408/ruta-core/src/main/java/org/apache/uima/ruta/expression/number/SimpleNumberExpression.java Fri Nov 6 17:17:42 2015
@@ -19,9 +19,8 @@
package org.apache.uima.ruta.expression.number;
-import org.apache.uima.cas.text.AnnotationFS;
-import org.apache.uima.ruta.RutaBlock;
import org.apache.uima.ruta.RutaStream;
+import org.apache.uima.ruta.rule.MatchContext;
public class SimpleNumberExpression extends AbstractNumberExpression {
@@ -32,15 +31,15 @@ public class SimpleNumberExpression exte
this.number = number;
}
- public double getDoubleValue(RutaBlock parent, AnnotationFS annotation, RutaStream stream) {
+ public double getDoubleValue(MatchContext context, RutaStream stream) {
return number.doubleValue();
}
- public float getFloatValue(RutaBlock parent, AnnotationFS annotation, RutaStream stream) {
+ public float getFloatValue(MatchContext context, RutaStream stream) {
return number.floatValue();
}
- public int getIntegerValue(RutaBlock parent, AnnotationFS annotation, RutaStream stream) {
+ public int getIntegerValue(MatchContext context, RutaStream stream) {
return number.intValue();
}
@@ -48,12 +47,12 @@ public class SimpleNumberExpression exte
return number;
}
- public String getStringValue(RutaBlock parent, AnnotationFS annotation, RutaStream stream) {
+ public String getStringValue(MatchContext context, RutaStream stream) {
boolean floating = number.intValue() != number.doubleValue();
if (floating) {
- return "" + getDoubleValue(parent, annotation, stream);
+ return "" + getDoubleValue(context, stream);
} else {
- return "" + getIntegerValue(parent, annotation, stream);
+ return "" + getIntegerValue(context, stream);
}
}
Modified: uima/ruta/branches/UIMA-4408/ruta-core/src/main/java/org/apache/uima/ruta/expression/resource/ExternalWordListExpression.java
URL: http://svn.apache.org/viewvc/uima/ruta/branches/UIMA-4408/ruta-core/src/main/java/org/apache/uima/ruta/expression/resource/ExternalWordListExpression.java?rev=1712988&r1=1712987&r2=1712988&view=diff
==============================================================================
--- uima/ruta/branches/UIMA-4408/ruta-core/src/main/java/org/apache/uima/ruta/expression/resource/ExternalWordListExpression.java (original)
+++ uima/ruta/branches/UIMA-4408/ruta-core/src/main/java/org/apache/uima/ruta/expression/resource/ExternalWordListExpression.java Fri Nov 6 17:17:42 2015
@@ -22,9 +22,9 @@ package org.apache.uima.ruta.expression.
import java.util.ArrayList;
import java.util.List;
-import org.apache.uima.ruta.RutaStatement;
import org.apache.uima.ruta.expression.string.IStringExpression;
import org.apache.uima.ruta.resource.RutaWordList;
+import org.apache.uima.ruta.rule.MatchContext;
public class ExternalWordListExpression extends WordListExpression {
@@ -39,10 +39,10 @@ public class ExternalWordListExpression
}
@Override
- public RutaWordList getList(RutaStatement element) {
+ public RutaWordList getList(MatchContext context) {
List<String> argList = new ArrayList<String>();
for (IStringExpression each : args) {
- argList.add(each.getStringValue(element.getParent(), null, null));
+ argList.add(each.getStringValue(context, null));
}
Modified: uima/ruta/branches/UIMA-4408/ruta-core/src/main/java/org/apache/uima/ruta/expression/resource/ExternalWordTableExpression.java
URL: http://svn.apache.org/viewvc/uima/ruta/branches/UIMA-4408/ruta-core/src/main/java/org/apache/uima/ruta/expression/resource/ExternalWordTableExpression.java?rev=1712988&r1=1712987&r2=1712988&view=diff
==============================================================================
--- uima/ruta/branches/UIMA-4408/ruta-core/src/main/java/org/apache/uima/ruta/expression/resource/ExternalWordTableExpression.java (original)
+++ uima/ruta/branches/UIMA-4408/ruta-core/src/main/java/org/apache/uima/ruta/expression/resource/ExternalWordTableExpression.java Fri Nov 6 17:17:42 2015
@@ -22,9 +22,9 @@ package org.apache.uima.ruta.expression.
import java.util.ArrayList;
import java.util.List;
-import org.apache.uima.ruta.RutaStatement;
import org.apache.uima.ruta.expression.string.IStringExpression;
import org.apache.uima.ruta.resource.RutaTable;
+import org.apache.uima.ruta.rule.MatchContext;
public class ExternalWordTableExpression extends WordTableExpression {
@@ -39,10 +39,10 @@ public class ExternalWordTableExpression
}
@Override
- public RutaTable getTable(RutaStatement element) {
+ public RutaTable getTable(MatchContext context) {
List<String> argList = new ArrayList<String>();
for (IStringExpression each : args) {
- argList.add(each.getStringValue(element.getParent(), null, null));
+ argList.add(each.getStringValue(context, null));
}
return null;
Modified: uima/ruta/branches/UIMA-4408/ruta-core/src/main/java/org/apache/uima/ruta/expression/resource/LiteralWordListExpression.java
URL: http://svn.apache.org/viewvc/uima/ruta/branches/UIMA-4408/ruta-core/src/main/java/org/apache/uima/ruta/expression/resource/LiteralWordListExpression.java?rev=1712988&r1=1712987&r2=1712988&view=diff
==============================================================================
--- uima/ruta/branches/UIMA-4408/ruta-core/src/main/java/org/apache/uima/ruta/expression/resource/LiteralWordListExpression.java (original)
+++ uima/ruta/branches/UIMA-4408/ruta-core/src/main/java/org/apache/uima/ruta/expression/resource/LiteralWordListExpression.java Fri Nov 6 17:17:42 2015
@@ -19,8 +19,9 @@
package org.apache.uima.ruta.expression.resource;
-import org.apache.uima.ruta.RutaStatement;
+import org.apache.uima.ruta.RutaBlock;
import org.apache.uima.ruta.resource.RutaWordList;
+import org.apache.uima.ruta.rule.MatchContext;
public class LiteralWordListExpression extends WordListExpression {
@@ -40,8 +41,9 @@ public class LiteralWordListExpression e
}
@Override
- public RutaWordList getList(RutaStatement element) {
- RutaWordList list = element.getEnvironment().getWordList(getText());
+ public RutaWordList getList(MatchContext context) {
+ RutaBlock parent = context.getParent();
+ RutaWordList list = parent.getEnvironment().getWordList(getText());
return list;
}
Modified: uima/ruta/branches/UIMA-4408/ruta-core/src/main/java/org/apache/uima/ruta/expression/resource/LiteralWordTableExpression.java
URL: http://svn.apache.org/viewvc/uima/ruta/branches/UIMA-4408/ruta-core/src/main/java/org/apache/uima/ruta/expression/resource/LiteralWordTableExpression.java?rev=1712988&r1=1712987&r2=1712988&view=diff
==============================================================================
--- uima/ruta/branches/UIMA-4408/ruta-core/src/main/java/org/apache/uima/ruta/expression/resource/LiteralWordTableExpression.java (original)
+++ uima/ruta/branches/UIMA-4408/ruta-core/src/main/java/org/apache/uima/ruta/expression/resource/LiteralWordTableExpression.java Fri Nov 6 17:17:42 2015
@@ -19,8 +19,9 @@
package org.apache.uima.ruta.expression.resource;
-import org.apache.uima.ruta.RutaStatement;
+import org.apache.uima.ruta.RutaBlock;
import org.apache.uima.ruta.resource.RutaTable;
+import org.apache.uima.ruta.rule.MatchContext;
public class LiteralWordTableExpression extends WordTableExpression {
@@ -40,8 +41,9 @@ public class LiteralWordTableExpression
}
@Override
- public RutaTable getTable(RutaStatement element) {
- RutaTable table = element.getEnvironment().getWordTable(getText());
+ public RutaTable getTable(MatchContext context) {
+ RutaBlock parent = context.getParent();
+ RutaTable table = parent.getEnvironment().getWordTable(getText());
return table;
}
Modified: uima/ruta/branches/UIMA-4408/ruta-core/src/main/java/org/apache/uima/ruta/expression/resource/ReferenceWordListExpression.java
URL: http://svn.apache.org/viewvc/uima/ruta/branches/UIMA-4408/ruta-core/src/main/java/org/apache/uima/ruta/expression/resource/ReferenceWordListExpression.java?rev=1712988&r1=1712987&r2=1712988&view=diff
==============================================================================
--- uima/ruta/branches/UIMA-4408/ruta-core/src/main/java/org/apache/uima/ruta/expression/resource/ReferenceWordListExpression.java (original)
+++ uima/ruta/branches/UIMA-4408/ruta-core/src/main/java/org/apache/uima/ruta/expression/resource/ReferenceWordListExpression.java Fri Nov 6 17:17:42 2015
@@ -19,8 +19,9 @@
package org.apache.uima.ruta.expression.resource;
-import org.apache.uima.ruta.RutaStatement;
+import org.apache.uima.ruta.RutaBlock;
import org.apache.uima.ruta.resource.RutaWordList;
+import org.apache.uima.ruta.rule.MatchContext;
public class ReferenceWordListExpression extends WordListExpression {
@@ -32,8 +33,9 @@ public class ReferenceWordListExpression
}
@Override
- public RutaWordList getList(RutaStatement element) {
- return element.getEnvironment().getVariableValue(ref, RutaWordList.class);
+ public RutaWordList getList(MatchContext context) {
+ RutaBlock parent = context.getParent();
+ return parent.getEnvironment().getVariableValue(ref, RutaWordList.class);
}
public String getRef() {
Modified: uima/ruta/branches/UIMA-4408/ruta-core/src/main/java/org/apache/uima/ruta/expression/resource/ReferenceWordTableExpression.java
URL: http://svn.apache.org/viewvc/uima/ruta/branches/UIMA-4408/ruta-core/src/main/java/org/apache/uima/ruta/expression/resource/ReferenceWordTableExpression.java?rev=1712988&r1=1712987&r2=1712988&view=diff
==============================================================================
--- uima/ruta/branches/UIMA-4408/ruta-core/src/main/java/org/apache/uima/ruta/expression/resource/ReferenceWordTableExpression.java (original)
+++ uima/ruta/branches/UIMA-4408/ruta-core/src/main/java/org/apache/uima/ruta/expression/resource/ReferenceWordTableExpression.java Fri Nov 6 17:17:42 2015
@@ -19,8 +19,9 @@
package org.apache.uima.ruta.expression.resource;
-import org.apache.uima.ruta.RutaStatement;
+import org.apache.uima.ruta.RutaBlock;
import org.apache.uima.ruta.resource.RutaTable;
+import org.apache.uima.ruta.rule.MatchContext;
public class ReferenceWordTableExpression extends WordTableExpression {
@@ -32,8 +33,9 @@ public class ReferenceWordTableExpressio
}
@Override
- public RutaTable getTable(RutaStatement element) {
- return element.getEnvironment().getVariableValue(ref, RutaTable.class);
+ public RutaTable getTable(MatchContext context) {
+ RutaBlock parent = context.getParent();
+ return parent.getEnvironment().getVariableValue(ref, RutaTable.class);
}
public String getRef() {
Modified: uima/ruta/branches/UIMA-4408/ruta-core/src/main/java/org/apache/uima/ruta/expression/resource/WordListExpression.java
URL: http://svn.apache.org/viewvc/uima/ruta/branches/UIMA-4408/ruta-core/src/main/java/org/apache/uima/ruta/expression/resource/WordListExpression.java?rev=1712988&r1=1712987&r2=1712988&view=diff
==============================================================================
--- uima/ruta/branches/UIMA-4408/ruta-core/src/main/java/org/apache/uima/ruta/expression/resource/WordListExpression.java (original)
+++ uima/ruta/branches/UIMA-4408/ruta-core/src/main/java/org/apache/uima/ruta/expression/resource/WordListExpression.java Fri Nov 6 17:17:42 2015
@@ -19,12 +19,12 @@
package org.apache.uima.ruta.expression.resource;
-import org.apache.uima.ruta.RutaStatement;
import org.apache.uima.ruta.expression.RutaExpression;
import org.apache.uima.ruta.resource.RutaWordList;
+import org.apache.uima.ruta.rule.MatchContext;
public abstract class WordListExpression extends RutaExpression {
- public abstract RutaWordList getList(RutaStatement element);
+ public abstract RutaWordList getList(MatchContext context);
}
Modified: uima/ruta/branches/UIMA-4408/ruta-core/src/main/java/org/apache/uima/ruta/expression/resource/WordTableExpression.java
URL: http://svn.apache.org/viewvc/uima/ruta/branches/UIMA-4408/ruta-core/src/main/java/org/apache/uima/ruta/expression/resource/WordTableExpression.java?rev=1712988&r1=1712987&r2=1712988&view=diff
==============================================================================
--- uima/ruta/branches/UIMA-4408/ruta-core/src/main/java/org/apache/uima/ruta/expression/resource/WordTableExpression.java (original)
+++ uima/ruta/branches/UIMA-4408/ruta-core/src/main/java/org/apache/uima/ruta/expression/resource/WordTableExpression.java Fri Nov 6 17:17:42 2015
@@ -19,12 +19,12 @@
package org.apache.uima.ruta.expression.resource;
-import org.apache.uima.ruta.RutaStatement;
import org.apache.uima.ruta.expression.RutaExpression;
import org.apache.uima.ruta.resource.RutaTable;
+import org.apache.uima.ruta.rule.MatchContext;
public abstract class WordTableExpression extends RutaExpression {
- public abstract RutaTable getTable(RutaStatement element);
+ public abstract RutaTable getTable(MatchContext context);
}
Modified: uima/ruta/branches/UIMA-4408/ruta-core/src/main/java/org/apache/uima/ruta/expression/string/AbstractStringExpression.java
URL: http://svn.apache.org/viewvc/uima/ruta/branches/UIMA-4408/ruta-core/src/main/java/org/apache/uima/ruta/expression/string/AbstractStringExpression.java?rev=1712988&r1=1712987&r2=1712988&view=diff
==============================================================================
--- uima/ruta/branches/UIMA-4408/ruta-core/src/main/java/org/apache/uima/ruta/expression/string/AbstractStringExpression.java (original)
+++ uima/ruta/branches/UIMA-4408/ruta-core/src/main/java/org/apache/uima/ruta/expression/string/AbstractStringExpression.java Fri Nov 6 17:17:42 2015
@@ -25,22 +25,10 @@ import org.apache.uima.cas.text.Annotati
import org.apache.uima.ruta.RutaBlock;
import org.apache.uima.ruta.RutaStream;
import org.apache.uima.ruta.expression.RutaExpression;
+import org.apache.uima.ruta.rule.MatchContext;
import org.apache.uima.ruta.rule.RuleElement;
import org.apache.uima.ruta.rule.RuleMatch;
public abstract class AbstractStringExpression extends RutaExpression implements IStringExpression {
- public String getStringValue(RutaBlock parent, RuleMatch match, RuleElement element,
- RutaStream stream) {
- List<AnnotationFS> matchedAnnotationsOf = match.getMatchedAnnotationsOfElement(element);
- // TODO: do we need to select the correct annotation?
- AnnotationFS annotation = null;
- if (!matchedAnnotationsOf.isEmpty()) {
- annotation = matchedAnnotationsOf.get(0);
- }
- return getStringValue(parent, annotation, stream);
- }
-
- public abstract String getStringValue(RutaBlock parent, AnnotationFS annotation, RutaStream stream);
-
}
Modified: uima/ruta/branches/UIMA-4408/ruta-core/src/main/java/org/apache/uima/ruta/expression/string/ComposedStringExpression.java
URL: http://svn.apache.org/viewvc/uima/ruta/branches/UIMA-4408/ruta-core/src/main/java/org/apache/uima/ruta/expression/string/ComposedStringExpression.java?rev=1712988&r1=1712987&r2=1712988&view=diff
==============================================================================
--- uima/ruta/branches/UIMA-4408/ruta-core/src/main/java/org/apache/uima/ruta/expression/string/ComposedStringExpression.java (original)
+++ uima/ruta/branches/UIMA-4408/ruta-core/src/main/java/org/apache/uima/ruta/expression/string/ComposedStringExpression.java Fri Nov 6 17:17:42 2015
@@ -21,9 +21,8 @@ package org.apache.uima.ruta.expression.
import java.util.List;
-import org.apache.uima.cas.text.AnnotationFS;
-import org.apache.uima.ruta.RutaBlock;
import org.apache.uima.ruta.RutaStream;
+import org.apache.uima.ruta.rule.MatchContext;
public class ComposedStringExpression extends LiteralStringExpression {
@@ -35,10 +34,10 @@ public class ComposedStringExpression ex
}
@Override
- public String getStringValue(RutaBlock parent, AnnotationFS annotation, RutaStream stream) {
+ public String getStringValue(MatchContext context, RutaStream stream) {
StringBuilder result = new StringBuilder();
for (IStringExpression each : getExpressions()) {
- result.append(each.getStringValue(parent, annotation, stream));
+ result.append(each.getStringValue(context, stream));
}
return result.toString();
}
Modified: uima/ruta/branches/UIMA-4408/ruta-core/src/main/java/org/apache/uima/ruta/expression/string/IStringExpression.java
URL: http://svn.apache.org/viewvc/uima/ruta/branches/UIMA-4408/ruta-core/src/main/java/org/apache/uima/ruta/expression/string/IStringExpression.java?rev=1712988&r1=1712987&r2=1712988&view=diff
==============================================================================
--- uima/ruta/branches/UIMA-4408/ruta-core/src/main/java/org/apache/uima/ruta/expression/string/IStringExpression.java (original)
+++ uima/ruta/branches/UIMA-4408/ruta-core/src/main/java/org/apache/uima/ruta/expression/string/IStringExpression.java Fri Nov 6 17:17:42 2015
@@ -19,17 +19,15 @@
package org.apache.uima.ruta.expression.string;
-import org.apache.uima.cas.text.AnnotationFS;
-import org.apache.uima.ruta.RutaBlock;
import org.apache.uima.ruta.RutaStream;
import org.apache.uima.ruta.expression.IRutaExpression;
+import org.apache.uima.ruta.rule.MatchContext;
import org.apache.uima.ruta.rule.RuleElement;
import org.apache.uima.ruta.rule.RuleMatch;
public interface IStringExpression extends IRutaExpression {
- String getStringValue(RutaBlock parent, AnnotationFS annotation, RutaStream stream);
+ String getStringValue(MatchContext context, RutaStream stream);
- String getStringValue(RutaBlock parent, RuleMatch match, RuleElement element, RutaStream stream);
}
Modified: uima/ruta/branches/UIMA-4408/ruta-core/src/main/java/org/apache/uima/ruta/expression/string/RemoveFunction.java
URL: http://svn.apache.org/viewvc/uima/ruta/branches/UIMA-4408/ruta-core/src/main/java/org/apache/uima/ruta/expression/string/RemoveFunction.java?rev=1712988&r1=1712987&r2=1712988&view=diff
==============================================================================
--- uima/ruta/branches/UIMA-4408/ruta-core/src/main/java/org/apache/uima/ruta/expression/string/RemoveFunction.java (original)
+++ uima/ruta/branches/UIMA-4408/ruta-core/src/main/java/org/apache/uima/ruta/expression/string/RemoveFunction.java Fri Nov 6 17:17:42 2015
@@ -21,9 +21,9 @@ package org.apache.uima.ruta.expression.
import java.util.List;
-import org.apache.uima.cas.text.AnnotationFS;
import org.apache.uima.ruta.RutaBlock;
import org.apache.uima.ruta.RutaStream;
+import org.apache.uima.ruta.rule.MatchContext;
public class RemoveFunction extends StringFunctionExpression {
@@ -38,11 +38,12 @@ public class RemoveFunction extends Stri
}
@Override
- public String getStringValue(RutaBlock parent, AnnotationFS annotation, RutaStream stream) {
+ public String getStringValue(MatchContext context, RutaStream stream) {
+ RutaBlock parent = context.getParent();
StringBuilder result = new StringBuilder();
String value = parent.getEnvironment().getVariableValue(var, String.class);
for (IStringExpression each : list) {
- String string = each.getStringValue(parent, annotation, stream);
+ String string = each.getStringValue(context, stream);
String[] split = value.split(string);
for (String r : split) {
result.append(r);
Modified: uima/ruta/branches/UIMA-4408/ruta-core/src/main/java/org/apache/uima/ruta/expression/string/SimpleStringExpression.java
URL: http://svn.apache.org/viewvc/uima/ruta/branches/UIMA-4408/ruta-core/src/main/java/org/apache/uima/ruta/expression/string/SimpleStringExpression.java?rev=1712988&r1=1712987&r2=1712988&view=diff
==============================================================================
--- uima/ruta/branches/UIMA-4408/ruta-core/src/main/java/org/apache/uima/ruta/expression/string/SimpleStringExpression.java (original)
+++ uima/ruta/branches/UIMA-4408/ruta-core/src/main/java/org/apache/uima/ruta/expression/string/SimpleStringExpression.java Fri Nov 6 17:17:42 2015
@@ -19,9 +19,8 @@
package org.apache.uima.ruta.expression.string;
-import org.apache.uima.cas.text.AnnotationFS;
-import org.apache.uima.ruta.RutaBlock;
import org.apache.uima.ruta.RutaStream;
+import org.apache.uima.ruta.rule.MatchContext;
public class SimpleStringExpression extends LiteralStringExpression {
@@ -41,7 +40,7 @@ public class SimpleStringExpression exte
}
@Override
- public String getStringValue(RutaBlock parent, AnnotationFS annotation, RutaStream stream) {
+ public String getStringValue(MatchContext context, RutaStream stream) {
return getValue();
}
Modified: uima/ruta/branches/UIMA-4408/ruta-core/src/main/java/org/apache/uima/ruta/expression/string/StringFeatureExpression.java
URL: http://svn.apache.org/viewvc/uima/ruta/branches/UIMA-4408/ruta-core/src/main/java/org/apache/uima/ruta/expression/string/StringFeatureExpression.java?rev=1712988&r1=1712987&r2=1712988&view=diff
==============================================================================
--- uima/ruta/branches/UIMA-4408/ruta-core/src/main/java/org/apache/uima/ruta/expression/string/StringFeatureExpression.java (original)
+++ uima/ruta/branches/UIMA-4408/ruta-core/src/main/java/org/apache/uima/ruta/expression/string/StringFeatureExpression.java Fri Nov 6 17:17:42 2015
@@ -28,6 +28,7 @@ import org.apache.uima.cas.text.Annotati
import org.apache.uima.ruta.RutaBlock;
import org.apache.uima.ruta.RutaStream;
import org.apache.uima.ruta.expression.feature.FeatureExpression;
+import org.apache.uima.ruta.rule.MatchContext;
public class StringFeatureExpression extends AbstractStringExpression {
@@ -39,11 +40,13 @@ public class StringFeatureExpression ext
}
@Override
- public String getStringValue(RutaBlock parent, AnnotationFS annotation, RutaStream stream) {
- Type type = fe.getTypeExpr(parent).getType(parent);
- Feature feature = fe.getFeature(parent);
+ public String getStringValue(MatchContext context, RutaStream stream) {
+ AnnotationFS annotation = context.getAnnotation();
+ RutaBlock parent = context.getParent();
+ Type type = fe.getTypeExpr(context, stream).getType(context, stream);
+ Feature feature = fe.getFeature(context, stream);
List<AnnotationFS> list = getTargetAnnotation(annotation, type, stream);
- Collection<AnnotationFS> featureAnnotations = fe.getFeatureAnnotations(list, stream, parent,
+ Collection<AnnotationFS> featureAnnotations = fe.getFeatureAnnotations(list, stream, context,
false);
if (!featureAnnotations.isEmpty()) {
AnnotationFS next = featureAnnotations.iterator().next();
Modified: uima/ruta/branches/UIMA-4408/ruta-core/src/main/java/org/apache/uima/ruta/expression/string/StringVariableExpression.java
URL: http://svn.apache.org/viewvc/uima/ruta/branches/UIMA-4408/ruta-core/src/main/java/org/apache/uima/ruta/expression/string/StringVariableExpression.java?rev=1712988&r1=1712987&r2=1712988&view=diff
==============================================================================
--- uima/ruta/branches/UIMA-4408/ruta-core/src/main/java/org/apache/uima/ruta/expression/string/StringVariableExpression.java (original)
+++ uima/ruta/branches/UIMA-4408/ruta-core/src/main/java/org/apache/uima/ruta/expression/string/StringVariableExpression.java Fri Nov 6 17:17:42 2015
@@ -22,6 +22,7 @@ package org.apache.uima.ruta.expression.
import org.apache.uima.cas.text.AnnotationFS;
import org.apache.uima.ruta.RutaBlock;
import org.apache.uima.ruta.RutaStream;
+import org.apache.uima.ruta.rule.MatchContext;
public class StringVariableExpression extends LiteralStringExpression {
@@ -33,7 +34,9 @@ public class StringVariableExpression ex
}
@Override
- public String getStringValue(RutaBlock parent, AnnotationFS annotation, RutaStream stream) {
+ public String getStringValue(MatchContext context, RutaStream stream) {
+ AnnotationFS annotation = context.getAnnotation();
+ RutaBlock parent = context.getParent();
String variableValue = parent.getEnvironment().getVariableValue(getVar(), String.class);
return variableValue;
}
Modified: uima/ruta/branches/UIMA-4408/ruta-core/src/main/java/org/apache/uima/ruta/expression/type/ITypeExpression.java
URL: http://svn.apache.org/viewvc/uima/ruta/branches/UIMA-4408/ruta-core/src/main/java/org/apache/uima/ruta/expression/type/ITypeExpression.java?rev=1712988&r1=1712987&r2=1712988&view=diff
==============================================================================
--- uima/ruta/branches/UIMA-4408/ruta-core/src/main/java/org/apache/uima/ruta/expression/type/ITypeExpression.java (original)
+++ uima/ruta/branches/UIMA-4408/ruta-core/src/main/java/org/apache/uima/ruta/expression/type/ITypeExpression.java Fri Nov 6 17:17:42 2015
@@ -20,19 +20,21 @@
package org.apache.uima.ruta.expression.type;
import org.apache.uima.cas.Type;
-import org.apache.uima.ruta.RutaBlock;
+import org.apache.uima.ruta.RutaStream;
import org.apache.uima.ruta.expression.string.IStringExpression;
+import org.apache.uima.ruta.rule.MatchContext;
public interface ITypeExpression extends IStringExpression {
/**
* Returns the actual type of the TypeExpression
+ * @param context - the match context
+ * @param stream
*
- * @param parent - the block of the element
* @return annotation type
* @throws IllegalArgumentException if the type cannot be resolved.
*/
- Type getType(RutaBlock parent);
+ Type getType(MatchContext context, RutaStream stream);
}
Modified: uima/ruta/branches/UIMA-4408/ruta-core/src/main/java/org/apache/uima/ruta/expression/type/SimpleTypeExpression.java
URL: http://svn.apache.org/viewvc/uima/ruta/branches/UIMA-4408/ruta-core/src/main/java/org/apache/uima/ruta/expression/type/SimpleTypeExpression.java?rev=1712988&r1=1712987&r2=1712988&view=diff
==============================================================================
--- uima/ruta/branches/UIMA-4408/ruta-core/src/main/java/org/apache/uima/ruta/expression/type/SimpleTypeExpression.java (original)
+++ uima/ruta/branches/UIMA-4408/ruta-core/src/main/java/org/apache/uima/ruta/expression/type/SimpleTypeExpression.java Fri Nov 6 17:17:42 2015
@@ -23,6 +23,7 @@ import org.apache.uima.cas.Type;
import org.apache.uima.cas.text.AnnotationFS;
import org.apache.uima.ruta.RutaBlock;
import org.apache.uima.ruta.RutaStream;
+import org.apache.uima.ruta.rule.MatchContext;
public class SimpleTypeExpression extends TypeExpression {
@@ -36,12 +37,12 @@ public class SimpleTypeExpression extend
/**
* Returns the actual type of the TypeExpression
*
- * @param parent - the block of the element
* @return annotation type
* @throws IllegalArgumentException if the type cannot be resolved.
*/
@Override
- public Type getType(RutaBlock parent) {
+ public Type getType(MatchContext context, RutaStream stream) {
+ RutaBlock parent = context.getParent();
Type type = parent.getEnvironment().getType(typeString);
if(type == null) {
throw new IllegalArgumentException("Not able to resolve type: " + typeString);
@@ -55,7 +56,7 @@ public class SimpleTypeExpression extend
}
@Override
- public String getStringValue(RutaBlock parent, AnnotationFS annotation, RutaStream stream) {
+ public String getStringValue(MatchContext context, RutaStream stream) {
return typeString;
}
Modified: uima/ruta/branches/UIMA-4408/ruta-core/src/main/java/org/apache/uima/ruta/expression/type/TypeVariableExpression.java
URL: http://svn.apache.org/viewvc/uima/ruta/branches/UIMA-4408/ruta-core/src/main/java/org/apache/uima/ruta/expression/type/TypeVariableExpression.java?rev=1712988&r1=1712987&r2=1712988&view=diff
==============================================================================
--- uima/ruta/branches/UIMA-4408/ruta-core/src/main/java/org/apache/uima/ruta/expression/type/TypeVariableExpression.java (original)
+++ uima/ruta/branches/UIMA-4408/ruta-core/src/main/java/org/apache/uima/ruta/expression/type/TypeVariableExpression.java Fri Nov 6 17:17:42 2015
@@ -23,6 +23,7 @@ import org.apache.uima.cas.Type;
import org.apache.uima.cas.text.AnnotationFS;
import org.apache.uima.ruta.RutaBlock;
import org.apache.uima.ruta.RutaStream;
+import org.apache.uima.ruta.rule.MatchContext;
public class TypeVariableExpression extends TypeExpression {
@@ -45,12 +46,12 @@ public class TypeVariableExpression exte
/**
* Returns the actual type of the TypeExpression
*
- * @param parent - the block of the element
* @return annotation type
* @throws IllegalArgumentException if the type cannot be resolved.
*/
@Override
- public Type getType(RutaBlock parent) {
+ public Type getType(MatchContext context, RutaStream stream) {
+ RutaBlock parent = context.getParent();
Type type = parent.getEnvironment().getVariableValue(var, Type.class);
if(type == null) {
throw new IllegalArgumentException("Not able to resolve type variable: " + var);
@@ -59,8 +60,8 @@ public class TypeVariableExpression exte
}
@Override
- public String getStringValue(RutaBlock parent, AnnotationFS annotation, RutaStream stream) {
- Type type = getType(parent);
+ public String getStringValue(MatchContext context, RutaStream stream) {
+ Type type = getType(context, stream);
return type != null ? type.getName() : "null";
}
Modified: uima/ruta/branches/UIMA-4408/ruta-core/src/main/java/org/apache/uima/ruta/rule/AbstractRuleElement.java
URL: http://svn.apache.org/viewvc/uima/ruta/branches/UIMA-4408/ruta-core/src/main/java/org/apache/uima/ruta/rule/AbstractRuleElement.java?rev=1712988&r1=1712987&r2=1712988&view=diff
==============================================================================
--- uima/ruta/branches/UIMA-4408/ruta-core/src/main/java/org/apache/uima/ruta/rule/AbstractRuleElement.java (original)
+++ uima/ruta/branches/UIMA-4408/ruta-core/src/main/java/org/apache/uima/ruta/rule/AbstractRuleElement.java Fri Nov 6 17:17:42 2015
@@ -165,9 +165,9 @@ public abstract class AbstractRuleElemen
return matchInfo;
}
- public List<RuleElementMatch> evaluateMatches(List<RuleElementMatch> matches, RutaBlock parent,
+ public List<RuleElementMatch> evaluateMatches(List<RuleElementMatch> matches, MatchContext context,
RutaStream stream) {
- return quantifier.evaluateMatches(matches, parent, stream, emptyCrowd);
+ return quantifier.evaluateMatches(matches, context, stream, emptyCrowd);
}
public List<Integer> getSelfIndexList() {
Modified: uima/ruta/branches/UIMA-4408/ruta-core/src/main/java/org/apache/uima/ruta/rule/ComposedRuleElement.java
URL: http://svn.apache.org/viewvc/uima/ruta/branches/UIMA-4408/ruta-core/src/main/java/org/apache/uima/ruta/rule/ComposedRuleElement.java?rev=1712988&r1=1712987&r2=1712988&view=diff
==============================================================================
--- uima/ruta/branches/UIMA-4408/ruta-core/src/main/java/org/apache/uima/ruta/rule/ComposedRuleElement.java (original)
+++ uima/ruta/branches/UIMA-4408/ruta-core/src/main/java/org/apache/uima/ruta/rule/ComposedRuleElement.java Fri Nov 6 17:17:42 2015
@@ -96,8 +96,8 @@ public class ComposedRuleElement extends
for (Entry<RuleMatch, ComposedRuleElementMatch> entry : entrySet) {
RuleMatch eachRuleMatch = entry.getKey();
ComposedRuleElementMatch eachComposedMatch = entry.getValue();
- AnnotationFS lastAnnotation = eachRuleMatch.getLastMatchedAnnotation(this, true, null,
- parent, stream);
+ MatchContext context = new MatchContext(null, this, eachRuleMatch, true);
+ AnnotationFS lastAnnotation = eachRuleMatch.getLastMatchedAnnotation(context, stream);
boolean failed = !eachComposedMatch.matched();
List<RuleMatch> fallbackContinue = fallbackContinue(true, failed, lastAnnotation,
eachRuleMatch, ruleApply, eachComposedMatch, null, entryPoint, stream, crowd);
@@ -142,8 +142,8 @@ public class ComposedRuleElement extends
for (Entry<RuleMatch, ComposedRuleElementMatch> entry : entrySet) {
RuleMatch eachRuleMatch = entry.getKey();
ComposedRuleElementMatch eachComposedMatch = entry.getValue();
- AnnotationFS lastAnnotation = eachRuleMatch.getLastMatchedAnnotation(this, true, null,
- parent, stream);
+MatchContext context = new MatchContext(this, eachRuleMatch);
+ AnnotationFS lastAnnotation = eachRuleMatch.getLastMatchedAnnotation(context, stream);
boolean failed = !eachComposedMatch.matched();
List<AnnotationFS> textsMatched = eachComposedMatch.getTextsMatched();
if ((!stream.isGreedyAnchoring() && !stream.isOnlyOnce())
@@ -159,8 +159,8 @@ public class ComposedRuleElement extends
}
private AnnotationFS getPrefixAnnotation(RuleMatch ruleMatch, RutaStream stream) {
- AnnotationFS lastMatchedAnnotation = ruleMatch.getLastMatchedAnnotation(this, true, null,
- parent, stream);
+ MatchContext context = new MatchContext(this, ruleMatch);
+ AnnotationFS lastMatchedAnnotation = ruleMatch.getLastMatchedAnnotation(context, stream);
if (lastMatchedAnnotation.getBegin() == 0) {
JCas jCas = stream.getJCas();
AnnotationFS dummy = new RutaFrame(jCas, 0, 0);
@@ -216,8 +216,8 @@ public class ComposedRuleElement extends
for (Entry<RuleMatch, ComposedRuleElementMatch> entry : entrySet) {
RuleMatch eachRuleMatch = entry.getKey();
ComposedRuleElementMatch eachComposedMatch = entry.getValue();
- AnnotationFS lastAnnotation = eachRuleMatch.getLastMatchedAnnotation(this, after,
- annotation, parent, stream);
+ MatchContext context = new MatchContext(annotation, this, eachRuleMatch, after);
+ AnnotationFS lastAnnotation = eachRuleMatch.getLastMatchedAnnotation(context, stream);
boolean failed = !eachComposedMatch.matched();
List<AnnotationFS> textsMatched = eachRuleMatch.getMatchedAnnotationsOfRoot();
if ((!stream.isGreedyAnchoring() && !stream.isOnlyOnce())
@@ -260,8 +260,8 @@ public class ComposedRuleElement extends
for (Entry<RuleMatch, ComposedRuleElementMatch> entry : entrySet) {
RuleMatch eachRuleMatch = entry.getKey();
ComposedRuleElementMatch eachComposedMatch = entry.getValue();
- AnnotationFS lastAnnotation = eachRuleMatch.getLastMatchedAnnotation(this, after,
- annotation, parent, stream);
+ MatchContext context = new MatchContext(this, eachRuleMatch);
+ AnnotationFS lastAnnotation = eachRuleMatch.getLastMatchedAnnotation(context, stream);
boolean failed = !eachComposedMatch.matched();
@@ -327,8 +327,8 @@ public class ComposedRuleElement extends
if (elementMatch.matched()) {
result.put(ruleMatch, elementMatch);
} else {
- AnnotationFS lastMatchedAnnotation = ruleMatch.getLastMatchedAnnotation(getFirstElement(),
- direction, null, parent, stream);
+ MatchContext context = new MatchContext(getFirstElement(), ruleMatch, direction);
+ AnnotationFS lastMatchedAnnotation = ruleMatch.getLastMatchedAnnotation(context, stream);
if (largestEntry == null) {
largestEntry = entry;
largestAnnotation = lastMatchedAnnotation;
@@ -376,15 +376,16 @@ public class ComposedRuleElement extends
ComposedRuleElementMatch parentContainerMatch = containerMatch.getContainerMatch();
List<RuleElementMatch> match = getMatch(ruleMatch, parentContainerMatch);
int lenghtBefore = match.size();
- List<RuleElementMatch> evaluateMatches = quantifier.evaluateMatches(match, parent,
+ MatchContext context = new MatchContext(this, ruleMatch, after);
+ List<RuleElementMatch> evaluateMatches = quantifier.evaluateMatches(match, context,
stream, crowd);
ruleMatch.setMatched(ruleMatch.matched() && evaluateMatches != null);
if (evaluateMatches != null && evaluateMatches.size() != lenghtBefore) {
failed = true;
stopMatching = true;
}
- if (!quantifier.continueMatch(after, nextAnnotation, this, ruleMatch, containerMatch,
- stream, crowd)) {
+ if (!quantifier.continueMatch(after, context, nextAnnotation, containerMatch, stream,
+ crowd)) {
stopMatching = true;
}
if (evaluateMatches != null) {
@@ -419,9 +420,10 @@ public class ComposedRuleElement extends
RuleElement nextElement = container.getNextElement(after, this);
List<RuleElementMatch> match = getMatch(ruleMatch, parentContainerMatch);
int sizeBefore = match.size();
- boolean continueMatch = quantifier.continueMatch(after, annotation, this, ruleMatch,
- parentContainerMatch, stream, crowd);
- List<RuleElementMatch> evaluateMatches = quantifier.evaluateMatches(match, parent, stream,
+ MatchContext context = new MatchContext(annotation, this, ruleMatch, after);
+ boolean continueMatch = quantifier.continueMatch(after, context, annotation, parentContainerMatch,
+ stream, crowd);
+ List<RuleElementMatch> evaluateMatches = quantifier.evaluateMatches(match, context, stream,
crowd);
int sizeAfter = evaluateMatches != null ? evaluateMatches.size() : sizeBefore;
boolean removedFailedMatches = sizeAfter < sizeBefore;
@@ -569,7 +571,8 @@ public class ComposedRuleElement extends
for (RuleElement each : elements) {
result += each.estimateAnchors(stream);
}
- if (quantifier.isOptional(getParent(), stream)) {
+ MatchContext context = new MatchContext(null, null);
+ if (quantifier.isOptional(context, stream)) {
// three times since sibling elements maybe need to be checked
result *= 3 * (int) stream.getIndexPenalty();
}
Modified: uima/ruta/branches/UIMA-4408/ruta-core/src/main/java/org/apache/uima/ruta/rule/ComposedRuleElementMatch.java
URL: http://svn.apache.org/viewvc/uima/ruta/branches/UIMA-4408/ruta-core/src/main/java/org/apache/uima/ruta/rule/ComposedRuleElementMatch.java?rev=1712988&r1=1712987&r2=1712988&view=diff
==============================================================================
--- uima/ruta/branches/UIMA-4408/ruta-core/src/main/java/org/apache/uima/ruta/rule/ComposedRuleElementMatch.java (original)
+++ uima/ruta/branches/UIMA-4408/ruta-core/src/main/java/org/apache/uima/ruta/rule/ComposedRuleElementMatch.java Fri Nov 6 17:17:42 2015
@@ -90,7 +90,8 @@ public class ComposedRuleElementMatch ex
for (Entry<RuleElement, List<RuleElementMatch>> entry : entrySet) {
RuleElement element = entry.getKey();
List<RuleElementMatch> value = entry.getValue();
- allDone &= (element.getQuantifier().isOptional(element.getParent(), stream) || value != null);
+ MatchContext context = new MatchContext(element, null, true);
+ allDone &= (element.getQuantifier().isOptional(context, stream) || value != null);
if (value != null && !value.isEmpty() && included) {
for (RuleElementMatch ruleElementMatch : value) {
allDone &= ruleElementMatch.matched();
Modified: uima/ruta/branches/UIMA-4408/ruta-core/src/main/java/org/apache/uima/ruta/rule/MatchContext.java
URL: http://svn.apache.org/viewvc/uima/ruta/branches/UIMA-4408/ruta-core/src/main/java/org/apache/uima/ruta/rule/MatchContext.java?rev=1712988&r1=1712987&r2=1712988&view=diff
==============================================================================
--- uima/ruta/branches/UIMA-4408/ruta-core/src/main/java/org/apache/uima/ruta/rule/MatchContext.java (original)
+++ uima/ruta/branches/UIMA-4408/ruta-core/src/main/java/org/apache/uima/ruta/rule/MatchContext.java Fri Nov 6 17:17:42 2015
@@ -19,6 +19,7 @@
package org.apache.uima.ruta.rule;
import org.apache.uima.cas.text.AnnotationFS;
+import org.apache.uima.ruta.RutaBlock;
/**
* This is a generic container class for contextual information during rule matching
@@ -26,83 +27,116 @@ import org.apache.uima.cas.text.Annotati
*/
public class MatchContext {
- private AnnotationFS annotation;
- private RuleElement element;
- private RuleMatch ruleMatch;
- private boolean direction;
-
- /**
- * Container object of the current context during matching
- *
- * @param annotation
- * @param element
- * @param ruleMatch
- * @param direction, true: left to right, false, right to left
- */
- public MatchContext(AnnotationFS annotation, RuleElement element, RuleMatch ruleMatch, boolean direction) {
- super();
- this.annotation = annotation;
- this.element = element;
- this.ruleMatch = ruleMatch;
- this.direction = direction;
- }
-
- /**
- * Container object of the current context during matching
- *
- * @param element
- * @param ruleMatch
- * @param direction, true: left to right, false, right to left
- */
- public MatchContext(RuleElement element, RuleMatch ruleMatch, boolean direction) {
- this(null, element, ruleMatch, direction);
- }
-
- /**
- * Container object of the current context during matching
- *
- * @param element
- * @param ruleMatch
- */
- public MatchContext(AbstractRuleElement element,
- RuleMatch ruleMatch) {
- this(element, ruleMatch, true);
- }
-
- public AnnotationFS getAnnotation() {
- if(annotation!= null) {
- return annotation;
- } else {
- return null;
- }
- }
-
- public void setAnnotation(AnnotationFS annotation) {
- this.annotation = annotation;
- }
-
- public RuleElement getElement() {
- return element;
- }
-
- public void setElement(RuleElement element) {
- this.element = element;
- }
-
- public RuleMatch getRuleMatch() {
- return ruleMatch;
- }
-
- public void setRuleMatch(RuleMatch ruleMatch) {
- this.ruleMatch = ruleMatch;
- }
-
- public boolean isDirection() {
- return direction;
- }
-
- public void setDirection(boolean direction) {
- this.direction = direction;
- }
-
+ private AnnotationFS annotation;
+
+ private RuleElement element;
+
+ private RutaBlock parent;
+
+ private RuleMatch ruleMatch;
+
+ private boolean direction = true;
+
+ /**
+ * Container object of the current context during matching
+ *
+ * @param annotation
+ * @param element
+ * @param ruleMatch
+ * @param direction
+ * , true: left to right, false, right to left
+ */
+ public MatchContext(AnnotationFS annotation, RuleElement element, RuleMatch ruleMatch,
+ boolean direction) {
+ super();
+ this.annotation = annotation;
+ this.element = element;
+ if (element != null) {
+ this.parent = element.getParent();
+ }
+ this.ruleMatch = ruleMatch;
+ this.direction = direction;
+ }
+
+ /**
+ * Container object of the current context during matching
+ *
+ * @param element
+ * @param ruleMatch
+ * @param direction
+ * , true: left to right, false, right to left
+ */
+ public MatchContext(RuleElement element, RuleMatch ruleMatch, boolean direction) {
+ this(null, element, ruleMatch, direction);
+ }
+
+ /**
+ * Container object of the current context during matching
+ *
+ * @param element
+ * @param ruleMatch
+ */
+ public MatchContext(AbstractRuleElement element, RuleMatch ruleMatch) {
+ this(element, ruleMatch, true);
+ }
+
+
+ /**
+ * Container object of the current context during matching
+ *
+ * @param annotation
+ * @param element
+ * @param ruleMatch
+ * @param direction
+ * , true: left to right, false, right to left
+ */
+ public MatchContext(RutaBlock parent) {
+ super();
+ this.parent = parent;
+ }
+
+ public AnnotationFS getAnnotation() {
+ if (annotation != null) {
+ return annotation;
+ } else {
+ return null;
+ }
+ }
+
+ public void setAnnotation(AnnotationFS annotation) {
+ this.annotation = annotation;
+ }
+
+ public RuleElement getElement() {
+ return element;
+ }
+
+ public void setElement(RuleElement element) {
+ this.element = element;
+ }
+
+ public RuleMatch getRuleMatch() {
+ return ruleMatch;
+ }
+
+ public void setRuleMatch(RuleMatch ruleMatch) {
+ this.ruleMatch = ruleMatch;
+ }
+
+ public boolean getDirection() {
+ return direction;
+ }
+
+ public void setDirection(boolean direction) {
+ this.direction = direction;
+ }
+
+ public RutaBlock getParent() {
+ return parent;
+ }
+
+ public void setParent(RutaBlock parent) {
+ this.parent = parent;
+ }
+
}
Modified: uima/ruta/branches/UIMA-4408/ruta-core/src/main/java/org/apache/uima/ruta/rule/RegExpRule.java
URL: http://svn.apache.org/viewvc/uima/ruta/branches/UIMA-4408/ruta-core/src/main/java/org/apache/uima/ruta/rule/RegExpRule.java?rev=1712988&r1=1712987&r2=1712988&view=diff
==============================================================================
--- uima/ruta/branches/UIMA-4408/ruta-core/src/main/java/org/apache/uima/ruta/rule/RegExpRule.java (original)
+++ uima/ruta/branches/UIMA-4408/ruta-core/src/main/java/org/apache/uima/ruta/rule/RegExpRule.java Fri Nov 6 17:17:42 2015
@@ -71,13 +71,13 @@ public class RegExpRule extends Abstract
public ScriptApply apply(RutaStream stream, InferenceCrowd crowd) {
RuleApply ruleApply = new RuleApply(this, false);
crowd.beginVisit(this, ruleApply);
-
- String regexpString = regexpExpr.getStringValue(getParent(), null, stream);
+ MatchContext context = new MatchContext(getParent());
+ String regexpString = regexpExpr.getStringValue(context, stream);
AnnotationFS documentAnnotation = stream.getDocumentAnnotation();
String document = documentAnnotation.getCoveredText();
int delta = documentAnnotation.getBegin();
- Map<Integer, List<Type>> groupTypes = getGroup2Types(stream);
+ Map<Integer, List<Type>> groupTypes = getGroup2Types(context, stream);
Map<Integer, Map<Type, Map<String, Object>>> fa = getFeatureAssignmentMap(stream);
Pattern pattern = Pattern.compile(regexpString, Pattern.MULTILINE | Pattern.DOTALL);
@@ -113,12 +113,13 @@ public class RegExpRule extends Abstract
Map<Integer, Map<Type, Map<String, Object>>> result = new HashMap<Integer, Map<Type, Map<String, Object>>>();
Set<Entry<TypeExpression, Map<IStringExpression, IRutaExpression>>> entrySet = featureAssignments
.entrySet();
+ MatchContext context = new MatchContext(getParent());
for (Entry<TypeExpression, Map<IStringExpression, IRutaExpression>> entry : entrySet) {
TypeExpression key = entry.getKey();
- Type type = key.getType(getParent());
+ Type type = key.getType(context, stream);
Map<IStringExpression, IRutaExpression> value = entry.getValue();
INumberExpression cgExpr = typeMap.get(key);
- int cg = cgExpr == null ? 0 : cgExpr.getIntegerValue(getParent(), null, stream);
+ int cg = cgExpr == null ? 0 : cgExpr.getIntegerValue(context, stream);
Map<Type, Map<String, Object>> map = result.get(cg);
if (map == null) {
map = new HashMap<Type, Map<String, Object>>();
@@ -133,20 +134,20 @@ public class RegExpRule extends Abstract
for (Entry<IStringExpression, IRutaExpression> entry2 : entrySet2) {
IStringExpression key2 = entry2.getKey();
IRutaExpression value2 = entry2.getValue();
- String stringValue = key2.getStringValue(getParent(), null, stream);
+ String stringValue = key2.getStringValue(context, stream);
typeMap.put(stringValue, value2);
}
}
return result;
}
- private Map<Integer, List<Type>> getGroup2Types(RutaStream stream) {
+ private Map<Integer, List<Type>> getGroup2Types(MatchContext context, RutaStream stream) {
Map<Integer, List<Type>> groupTypes = new TreeMap<Integer, List<Type>>();
Set<Entry<TypeExpression, INumberExpression>> entrySet = typeMap.entrySet();
for (Entry<TypeExpression, INumberExpression> entry : entrySet) {
- Type type = entry.getKey().getType(getParent());
+ Type type = entry.getKey().getType(context, stream);
INumberExpression value = entry.getValue();
- int group = value == null ? 0 : value.getIntegerValue(getParent(), null, stream);
+ int group = value == null ? 0 : value.getIntegerValue(context, stream);
List<Type> list = groupTypes.get(group);
if (list == null) {
list = new ArrayList<Type>();
@@ -181,6 +182,7 @@ public class RegExpRule extends Abstract
jcas = cas.getJCas();
} catch (CASException e) {
}
+ MatchContext context = new MatchContext(null, null, null, true);
TypeSystem typeSystem = cas.getTypeSystem();
Map<Type, Map<String, Object>> typeMap = fa.get(group);
if (typeMap != null) {
@@ -194,7 +196,7 @@ public class RegExpRule extends Abstract
Type range = feature.getRange();
if (argExpr instanceof INumberExpression) {
INumberExpression ne = (INumberExpression) argExpr;
- int cg = ne.getIntegerValue(getParent(), afs, stream);
+ int cg = ne.getIntegerValue(context, stream);
if (range.getName().equals(UIMAConstants.TYPE_STRING)) {
String s = matchResult.group(cg);
afs.setStringValue(feature, s);
@@ -226,7 +228,7 @@ public class RegExpRule extends Abstract
&& range.getName().equals(UIMAConstants.TYPE_STRING)) {
TypeExpression typeExpr = (TypeExpression) argExpr;
List<AnnotationFS> annotationsInWindow = stream.getAnnotationsInWindow(afs,
- typeExpr.getType(getParent()));
+ typeExpr.getType(context, stream));
if (annotationsInWindow != null && !annotationsInWindow.isEmpty()) {
AnnotationFS annotation = annotationsInWindow.get(0);
afs.setStringValue(feature, annotation.getCoveredText());
@@ -234,7 +236,7 @@ public class RegExpRule extends Abstract
} else if (argExpr instanceof AbstractStringExpression
&& range.getName().equals(UIMAConstants.TYPE_STRING)) {
afs.setStringValue(feature,
- ((AbstractStringExpression) argExpr).getStringValue(getParent(), afs, stream));
+ ((AbstractStringExpression) argExpr).getStringValue(context, stream));
// numbers are reserved for capturing groups
//
// } else if (argExpr instanceof NumberExpression) {
@@ -260,14 +262,14 @@ public class RegExpRule extends Abstract
} else if (argExpr instanceof IBooleanExpression
&& range.getName().equals(UIMAConstants.TYPE_BOOLEAN)) {
afs.setBooleanValue(feature,
- ((IBooleanExpression) argExpr).getBooleanValue(getParent(), null, stream));
+ ((IBooleanExpression) argExpr).getBooleanValue(context, stream));
} else if (argExpr instanceof TypeExpression) {
TypeExpression typeExpr = (TypeExpression) argExpr;
List<AnnotationFS> annotationsInWindow = stream.getAnnotationsInWindow(afs,
- typeExpr.getType(getParent()));
+ typeExpr.getType(context, stream));
if (typeSystem.subsumes(jcas.getCasType(FSArray.type), range)) {
afs.setFeatureValue(feature, UIMAUtils.toFSArray(jcas, annotationsInWindow));
- } else if (typeSystem.subsumes(range, typeExpr.getType(getParent()))
+ } else if (typeSystem.subsumes(range, typeExpr.getType(context, stream))
&& !annotationsInWindow.isEmpty()) {
AnnotationFS annotation = annotationsInWindow.get(0);
afs.setFeatureValue(feature, annotation);
Modified: uima/ruta/branches/UIMA-4408/ruta-core/src/main/java/org/apache/uima/ruta/rule/RuleElement.java
URL: http://svn.apache.org/viewvc/uima/ruta/branches/UIMA-4408/ruta-core/src/main/java/org/apache/uima/ruta/rule/RuleElement.java?rev=1712988&r1=1712987&r2=1712988&view=diff
==============================================================================
--- uima/ruta/branches/UIMA-4408/ruta-core/src/main/java/org/apache/uima/ruta/rule/RuleElement.java (original)
+++ uima/ruta/branches/UIMA-4408/ruta-core/src/main/java/org/apache/uima/ruta/rule/RuleElement.java Fri Nov 6 17:17:42 2015
@@ -49,7 +49,7 @@ public interface RuleElement {
RutaRuleElement sideStepOrigin, RuleElement entryPoint, RutaStream stream,
InferenceCrowd crowd);
- List<RuleElementMatch> evaluateMatches(List<RuleElementMatch> matches, RutaBlock parent,
+ List<RuleElementMatch> evaluateMatches(List<RuleElementMatch> matches, MatchContext context,
RutaStream stream);
Collection<AnnotationFS> getAnchors(RutaStream symbolStream);
Modified: uima/ruta/branches/UIMA-4408/ruta-core/src/main/java/org/apache/uima/ruta/rule/RuleMatch.java
URL: http://svn.apache.org/viewvc/uima/ruta/branches/UIMA-4408/ruta-core/src/main/java/org/apache/uima/ruta/rule/RuleMatch.java?rev=1712988&r1=1712987&r2=1712988&view=diff
==============================================================================
--- uima/ruta/branches/UIMA-4408/ruta-core/src/main/java/org/apache/uima/ruta/rule/RuleMatch.java (original)
+++ uima/ruta/branches/UIMA-4408/ruta-core/src/main/java/org/apache/uima/ruta/rule/RuleMatch.java Fri Nov 6 17:17:42 2015
@@ -66,11 +66,13 @@ public class RuleMatch extends AbstractR
return element;
}
- public AnnotationFS getLastMatchedAnnotation(RuleElement element, boolean direction,
- AnnotationFS annotation, RutaBlock parent, RutaStream stream) {
+ public AnnotationFS getLastMatchedAnnotation(MatchContext context, RutaStream stream) {
+ RuleElement element = context.getElement();
+ AnnotationFS annotation = context.getAnnotation();
+ boolean direction = context.getDirection();
List<AnnotationFS> matchedAnnotations = getMatchedAnnotationsOfElement(element);
if (matchedAnnotations.isEmpty()) {
- if (element.getQuantifier().isOptional(parent, stream)) {
+ if (element.getQuantifier().isOptional(context, stream)) {
return annotation;
} else {
return null;
Modified: uima/ruta/branches/UIMA-4408/ruta-core/src/main/java/org/apache/uima/ruta/rule/RutaLiteralMatcher.java
URL: http://svn.apache.org/viewvc/uima/ruta/branches/UIMA-4408/ruta-core/src/main/java/org/apache/uima/ruta/rule/RutaLiteralMatcher.java?rev=1712988&r1=1712987&r2=1712988&view=diff
==============================================================================
--- uima/ruta/branches/UIMA-4408/ruta-core/src/main/java/org/apache/uima/ruta/rule/RutaLiteralMatcher.java (original)
+++ uima/ruta/branches/UIMA-4408/ruta-core/src/main/java/org/apache/uima/ruta/rule/RutaLiteralMatcher.java Fri Nov 6 17:17:42 2015
@@ -43,8 +43,11 @@ public class RutaLiteralMatcher implemen
List<AnnotationFS> result = new ArrayList<AnnotationFS>();
AnnotationFS windowAnnotation = stream.getDocumentAnnotation();
List<RutaBasic> list = stream.getBasicsInWindow(windowAnnotation);
+ // TODO improve matching on literal strings
for (RutaBasic each : list) {
- if (each.getCoveredText().equals(expression.getStringValue(parent, null, stream))) {
+ MatchContext context = new MatchContext(each, null, null, true);
+ context.setParent(parent);
+ if (each.getCoveredText().equals(expression.getStringValue(context, stream))) {
result.add(each);
}
}
@@ -55,7 +58,9 @@ public class RutaLiteralMatcher implemen
if (annotation == null) {
return false;
}
- return annotation.getCoveredText().equals(expression.getStringValue(parent, null, stream));
+ MatchContext context = new MatchContext(annotation, null, null, true);
+ context.setParent(parent);
+ return annotation.getCoveredText().equals(expression.getStringValue(context, stream));
}
@Override
@@ -88,7 +93,9 @@ public class RutaLiteralMatcher implemen
if (basicNextTo == null) {
return result;
}
- String stringValue = expression.getStringValue(parent, annotation, stream);
+ MatchContext context = new MatchContext(annotation, null, null, !before);
+ context.setParent(parent);
+ String stringValue = expression.getStringValue(context, stream);
if (stringValue.equals(basicNextTo.getCoveredText())) {
result.add(basicNextTo);
}
Modified: uima/ruta/branches/UIMA-4408/ruta-core/src/main/java/org/apache/uima/ruta/rule/RutaRuleElement.java
URL: http://svn.apache.org/viewvc/uima/ruta/branches/UIMA-4408/ruta-core/src/main/java/org/apache/uima/ruta/rule/RutaRuleElement.java?rev=1712988&r1=1712987&r2=1712988&view=diff
==============================================================================
--- uima/ruta/branches/UIMA-4408/ruta-core/src/main/java/org/apache/uima/ruta/rule/RutaRuleElement.java (original)
+++ uima/ruta/branches/UIMA-4408/ruta-core/src/main/java/org/apache/uima/ruta/rule/RutaRuleElement.java Fri Nov 6 17:17:42 2015
@@ -77,8 +77,9 @@ public class RutaRuleElement extends Abs
RuleElement after = getContainer().getNextElement(true, this);
RuleElement before = getContainer().getNextElement(false, this);
RutaRuleElement sideStepOrigin = hasAncestor(false) ? this : null;
- if (quantifier.continueMatch(true, eachAnchor, this, extendedMatch, extendedContainerMatch,
- stream, crowd)) {
+ MatchContext context = new MatchContext(this, extendedMatch, true);
+ if (quantifier.continueMatch(true, context, eachAnchor, extendedContainerMatch, stream,
+ crowd)) {
List<RuleMatch> continueOwnMatch = continueOwnMatch(true, eachAnchor, extendedMatch,
ruleApply, extendedContainerMatch, sideStepOrigin, entryPoint, stream, crowd);
result.addAll(continueOwnMatch);
@@ -127,15 +128,17 @@ public class RutaRuleElement extends Abs
RutaRuleElement sideStepOrigin, RuleElement entryPoint, RutaStream stream,
InferenceCrowd crowd) {
List<RuleMatch> result = new ArrayList<RuleMatch>();
- if (quantifier.continueMatch(after, annotation, this, ruleMatch, containerMatch, stream, crowd)) {
+ MatchContext context = new MatchContext(this, ruleMatch, after);
+ if (quantifier.continueMatch(after, context, annotation, containerMatch, stream, crowd)) {
boolean stopMatching = false;
AnnotationFS eachAnchor = annotation;
AnnotationFS lastAnchor = annotation;
ComposedRuleElementMatch extendedContainerMatch = containerMatch;
RuleMatch extendedMatch = ruleMatch;
while (!stopMatching) {
- if (!quantifier.continueMatch(after, eachAnchor, this, extendedMatch,
- extendedContainerMatch, stream, crowd)) {
+ context = new MatchContext(this, extendedMatch, after);
+ if (!quantifier.continueMatch(after, context, eachAnchor, extendedContainerMatch,
+ stream, crowd)) {
stopMatching = true;
stepbackMatch(after, lastAnchor, extendedMatch, ruleApply, extendedContainerMatch,
sideStepOrigin, stream, crowd, entryPoint);
@@ -153,8 +156,8 @@ public class RutaRuleElement extends Abs
if (this.equals(entryPoint)) {
result.add(extendedMatch);
} else if (extendedMatch.matched()) {
- if (quantifier.continueMatch(after, eachAnchor, this, extendedMatch,
- extendedContainerMatch, stream, crowd)) {
+ if (quantifier.continueMatch(after, context, eachAnchor, extendedContainerMatch,
+ stream, crowd)) {
// continue in while loop
} else {
stopMatching = true;
@@ -202,7 +205,8 @@ public class RutaRuleElement extends Abs
InferenceCrowd crowd) {
List<RuleMatch> result = new ArrayList<RuleMatch>();
// if() for really lazy quantifiers
- if (quantifier.continueMatch(after, annotation, this, ruleMatch, containerMatch, stream, crowd)) {
+ MatchContext context = new MatchContext(this, ruleMatch, after);
+ if (quantifier.continueMatch(after, context, annotation, containerMatch, stream, crowd)) {
Collection<AnnotationFS> nextAnnotations = getNextAnnotations(after, annotation, stream);
if (nextAnnotations.isEmpty()) {
result = stepbackMatch(after, annotation, ruleMatch, ruleApply, containerMatch,
@@ -226,8 +230,9 @@ public class RutaRuleElement extends Abs
if (this.equals(entryPoint) && ruleApply == null) {
result.add(extendedMatch);
} else if (extendedMatch.matched()) {
- if (quantifier.continueMatch(after, annotation, this, extendedMatch,
- extendedContainerMatch, stream, crowd)) {
+ context = new MatchContext(this, extendedMatch, after);
+ if (quantifier.continueMatch(after, context, annotation, extendedContainerMatch,
+ stream, crowd)) {
List<RuleMatch> continueOwnMatch = continueOwnMatch(after, eachAnchor, extendedMatch,
ruleApply, extendedContainerMatch, sideStepOrigin, entryPoint, stream, crowd);
result.addAll(continueOwnMatch);
@@ -265,8 +270,9 @@ public class RutaRuleElement extends Abs
return result;
}
List<RuleElementMatch> matchInfo = getMatch(ruleMatch, containerMatch);
+ MatchContext context =new MatchContext(this, ruleMatch, after);
if (matchInfo == null) {
- if (quantifier.isOptional(parent, stream)) {
+ if (quantifier.isOptional(context, stream)) {
result = continueMatchSomewhereElse(after, true, annotation, ruleMatch, ruleApply,
containerMatch, sideStepOrigin, entryPoint, stream, crowd);
} else if (getContainer() instanceof ComposedRuleElement) {
@@ -288,7 +294,7 @@ public class RutaRuleElement extends Abs
// }
}
} else {
- List<RuleElementMatch> evaluateMatches = quantifier.evaluateMatches(matchInfo, parent,
+ List<RuleElementMatch> evaluateMatches = quantifier.evaluateMatches(matchInfo, context,
stream, crowd);
// TODO enforce match update?
ruleMatch.setMatched(evaluateMatches != null);
@@ -335,9 +341,9 @@ public class RutaRuleElement extends Abs
sideStepContainerMatch = (ComposedRuleElementMatch) list.get(0);
}
}
-
- if (quantifier.continueMatch(newDirection, annotation, this, ruleMatch,
- sideStepContainerMatch, stream, crowd)) {
+ MatchContext context = new MatchContext(this, ruleMatch, newDirection);
+ if (quantifier.continueMatch(newDirection, context, annotation, sideStepContainerMatch,
+ stream, crowd)) {
continueMatch(newDirection, annotation, ruleMatch, ruleApply, sideStepContainerMatch, null,
entryPoint, stream, crowd);
} else {
@@ -367,7 +373,8 @@ public class RutaRuleElement extends Abs
if (matcher instanceof RutaTypeMatcher) {
RutaTypeMatcher rtm = (RutaTypeMatcher) matcher;
MatchReference mr = (MatchReference) rtm.getExpression();
- FeatureExpression featureExpression = mr.getFeatureExpression(parent);
+ MatchContext context = new MatchContext(this, ruleMatch, after);
+ FeatureExpression featureExpression = mr.getFeatureExpression(context, stream);
if (featureExpression != null) {
base = matcher.match(annotation, stream, getParent());
}
@@ -418,7 +425,8 @@ public class RutaRuleElement extends Abs
}
public long estimateAnchors(RutaStream stream) {
- if (quantifier.isOptional(getParent(), stream)) {
+ // TODO what about the match context?
+ if (quantifier.isOptional(null, stream)) {
return matcher.estimateAnchors(parent, stream) + Integer.MAX_VALUE;
}
return matcher.estimateAnchors(parent, stream);
Modified: uima/ruta/branches/UIMA-4408/ruta-core/src/main/java/org/apache/uima/ruta/rule/RutaTypeMatcher.java
URL: http://svn.apache.org/viewvc/uima/ruta/branches/UIMA-4408/ruta-core/src/main/java/org/apache/uima/ruta/rule/RutaTypeMatcher.java?rev=1712988&r1=1712987&r2=1712988&view=diff
==============================================================================
--- uima/ruta/branches/UIMA-4408/ruta-core/src/main/java/org/apache/uima/ruta/rule/RutaTypeMatcher.java (original)
+++ uima/ruta/branches/UIMA-4408/ruta-core/src/main/java/org/apache/uima/ruta/rule/RutaTypeMatcher.java Fri Nov 6 17:17:42 2015
@@ -75,9 +75,11 @@ public class RutaTypeMatcher implements
annotations.addAll(stream.getAnnotations(type));
}
}
- FeatureExpression featureExpression = mr.getFeatureExpression(parent);
+ MatchContext context = new MatchContext(null, null, true);
+ context.setParent(parent);
+ FeatureExpression featureExpression = mr.getFeatureExpression(context, stream);
if (featureExpression != null) {
- return featureExpression.getFeatureAnnotations(annotations, stream, parent, CHECK_ON_FEATURE);
+ return featureExpression.getFeatureAnnotations(annotations, stream, context, CHECK_ON_FEATURE);
} else {
return annotations;
}
@@ -127,9 +129,11 @@ public class RutaTypeMatcher implements
}
}
}
- FeatureExpression fm = mr.getFeatureExpression(parent);
+ MatchContext context = new MatchContext(null, null, true);
+ context.setParent(parent);
+ FeatureExpression fm = mr.getFeatureExpression(context, stream);
if (fm != null) {
- return fm.getFeatureAnnotations(anchors, stream, parent, CHECK_ON_FEATURE);
+ return fm.getFeatureAnnotations(anchors, stream, context, CHECK_ON_FEATURE);
} else {
return anchors;
}
@@ -172,9 +176,11 @@ public class RutaTypeMatcher implements
}
}
}
- FeatureExpression fm = mr.getFeatureExpression(parent);
+ MatchContext context = new MatchContext(null, null, true);
+ context.setParent(parent);
+ FeatureExpression fm = mr.getFeatureExpression(context, stream);
if (fm != null) {
- return fm.getFeatureAnnotations(anchors, stream, parent, CHECK_ON_FEATURE);
+ return fm.getFeatureAnnotations(anchors, stream, context, CHECK_ON_FEATURE);
} else {
return anchors;
}
@@ -186,7 +192,9 @@ public class RutaTypeMatcher implements
if (annotation == null) {
return false;
}
- FeatureExpression featureExpression = mr.getFeatureExpression(parent);
+ MatchContext context = new MatchContext(null, null, true);
+ context.setParent(parent);
+ FeatureExpression featureExpression = mr.getFeatureExpression(context, stream);
if (featureExpression == null) {
boolean b = checkType(annotation, stream, parent);
if (b) {
@@ -220,11 +228,13 @@ public class RutaTypeMatcher implements
}
private boolean checkFeature(AnnotationFS annotation, RutaStream stream, RutaBlock parent) {
- FeatureExpression fe = mr.getFeatureExpression(parent);
- Feature feature = fe.getFeature(parent);
+ MatchContext context = new MatchContext(annotation, null, null, true);
+ context.setParent(parent);
+ FeatureExpression fe = mr.getFeatureExpression(context, stream);
+ Feature feature = fe.getFeature(context, stream);
if (fe instanceof FeatureMatchExpression) {
FeatureMatchExpression fme = (FeatureMatchExpression) fe;
- boolean checkFeatureValue = fme.checkFeatureValue(annotation, stream, parent);
+ boolean checkFeatureValue = fme.checkFeatureValue(annotation, context, stream);
if (checkFeatureValue) {
return true;
}
@@ -248,7 +258,9 @@ public class RutaTypeMatcher implements
}
protected Type getType(TypeExpression expression, RutaBlock parent, RutaStream stream) {
- Type type = expression.getType(parent);
+ MatchContext context = new MatchContext(null, null, true);
+ context.setParent(parent);
+ Type type = expression.getType(context, stream);
if (type != null && "uima.tcas.DocumentAnnotation".equals(type.getName())) {
return stream.getDocumentAnnotationType();
}
@@ -256,13 +268,17 @@ public class RutaTypeMatcher implements
}
public long estimateAnchors(RutaBlock parent, RutaStream stream) {
- TypeExpression typeExpression = mr.getTypeExpression(parent);
+ MatchContext context = new MatchContext(null, null, true);
+ context.setParent(parent);
+ TypeExpression typeExpression = mr.getTypeExpression(context, stream);
return stream.getHistogram(getType(typeExpression, parent, stream));
}
public List<Type> getTypes(RutaBlock parent, RutaStream stream) {
List<Type> result = new ArrayList<Type>(1);
- TypeExpression typeExpression = mr.getTypeExpression(parent);
+ MatchContext context = new MatchContext(null, null, true);
+ context.setParent(parent);
+ TypeExpression typeExpression = mr.getTypeExpression(context, stream);
Type type = getType(typeExpression, parent, stream);
result.add(type);
return result;
Modified: uima/ruta/branches/UIMA-4408/ruta-core/src/main/java/org/apache/uima/ruta/rule/WildCardRuleElement.java
URL: http://svn.apache.org/viewvc/uima/ruta/branches/UIMA-4408/ruta-core/src/main/java/org/apache/uima/ruta/rule/WildCardRuleElement.java?rev=1712988&r1=1712987&r2=1712988&view=diff
==============================================================================
--- uima/ruta/branches/UIMA-4408/ruta-core/src/main/java/org/apache/uima/ruta/rule/WildCardRuleElement.java (original)
+++ uima/ruta/branches/UIMA-4408/ruta-core/src/main/java/org/apache/uima/ruta/rule/WildCardRuleElement.java Fri Nov 6 17:17:42 2015
@@ -252,7 +252,8 @@ public class WildCardRuleElement extends
} else if (matcher instanceof RutaLiteralMatcher) {
RutaLiteralMatcher lm = (RutaLiteralMatcher) matcher;
IStringExpression expression = lm.getExpression();
- String stringValue = expression.getStringValue(parent, annotation, stream);
+ MatchContext context = new MatchContext(this, null, after);
+ String stringValue = expression.getStringValue(context, stream);
AnnotationFS documentAnnotation = stream.getDocumentAnnotation();
int delta = documentAnnotation.getBegin();
String document = documentAnnotation.getCoveredText();
@@ -298,7 +299,8 @@ public class WildCardRuleElement extends
if (c instanceof ComposedRuleElement) {
ComposedRuleElement cre = (ComposedRuleElement) c;
- if (nextElement.getQuantifier().isOptional(parent, stream)) {
+ MatchContext context = new MatchContext(this, null, after);
+ if (nextElement.getQuantifier().isOptional(context, stream)) {
// optional did not match -> match complete window/document
// TODO refactor
@@ -494,7 +496,8 @@ public class WildCardRuleElement extends
List<RuleMatch> result = new ArrayList<RuleMatch>();
RutaLiteralMatcher matcher = (RutaLiteralMatcher) nextElement.getMatcher();
IStringExpression expression = matcher.getExpression();
- String stringValue = expression.getStringValue(parent, null, stream);
+ MatchContext context = new MatchContext(this, ruleMatch, true);
+ String stringValue = expression.getStringValue(context, stream);
AnnotationFS documentAnnotation = stream.getDocumentAnnotation();
int delta = documentAnnotation.getBegin();
String document = documentAnnotation.getCoveredText();
Modified: uima/ruta/branches/UIMA-4408/ruta-core/src/main/java/org/apache/uima/ruta/rule/quantifier/MinMaxGreedy.java
URL: http://svn.apache.org/viewvc/uima/ruta/branches/UIMA-4408/ruta-core/src/main/java/org/apache/uima/ruta/rule/quantifier/MinMaxGreedy.java?rev=1712988&r1=1712987&r2=1712988&view=diff
==============================================================================
--- uima/ruta/branches/UIMA-4408/ruta-core/src/main/java/org/apache/uima/ruta/rule/quantifier/MinMaxGreedy.java (original)
+++ uima/ruta/branches/UIMA-4408/ruta-core/src/main/java/org/apache/uima/ruta/rule/quantifier/MinMaxGreedy.java Fri Nov 6 17:17:42 2015
@@ -22,14 +22,12 @@ package org.apache.uima.ruta.rule.quanti
import java.util.List;
import org.apache.uima.cas.text.AnnotationFS;
-import org.apache.uima.ruta.RutaBlock;
import org.apache.uima.ruta.RutaStream;
import org.apache.uima.ruta.expression.number.INumberExpression;
import org.apache.uima.ruta.expression.number.SimpleNumberExpression;
import org.apache.uima.ruta.rule.ComposedRuleElementMatch;
-import org.apache.uima.ruta.rule.RuleElement;
+import org.apache.uima.ruta.rule.MatchContext;
import org.apache.uima.ruta.rule.RuleElementMatch;
-import org.apache.uima.ruta.rule.RuleMatch;
import org.apache.uima.ruta.visitor.InferenceCrowd;
public class MinMaxGreedy extends AbstractRuleElementQuantifier {
@@ -53,10 +51,10 @@ public class MinMaxGreedy extends Abstra
}
@Override
- public List<RuleElementMatch> evaluateMatches(List<RuleElementMatch> matches, RutaBlock parent,
+ public List<RuleElementMatch> evaluateMatches(List<RuleElementMatch> matches, MatchContext context,
RutaStream stream, InferenceCrowd crowd) {
- int minValue = min.getIntegerValue(parent, null, stream);
- int maxValue = max.getIntegerValue(parent, null, stream);
+ int minValue = min.getIntegerValue(context, stream);
+ int maxValue = max.getIntegerValue(context, stream);
if (matches.size() > 0) {
RuleElementMatch ruleElementMatch = matches.get(matches.size() - 1);
@@ -84,16 +82,15 @@ public class MinMaxGreedy extends Abstra
}
@Override
- public boolean continueMatch(boolean after, AnnotationFS annotation, RuleElement ruleElement,
- RuleMatch extendedMatch, ComposedRuleElementMatch containerMatch, RutaStream stream,
- InferenceCrowd crowd) {
+ public boolean continueMatch(boolean after, MatchContext context, AnnotationFS annotation,
+ ComposedRuleElementMatch containerMatch, RutaStream stream, InferenceCrowd crowd) {
if (annotation == null) {
// do not try to continue a match that totally failed
return false;
}
- int minValue = min.getIntegerValue(ruleElement.getParent(), annotation, stream);
- int maxValue = max.getIntegerValue(ruleElement.getParent(), annotation, stream);
- List<RuleElementMatch> list = containerMatch.getInnerMatches().get(ruleElement);
+ int minValue = min.getIntegerValue(context, stream);
+ int maxValue = max.getIntegerValue(context, stream);
+ List<RuleElementMatch> list = containerMatch.getInnerMatches().get(context.getElement());
if (list == null) {
if (maxValue > 0) {
return true;
@@ -116,8 +113,8 @@ public class MinMaxGreedy extends Abstra
}
@Override
- public boolean isOptional(RutaBlock parent, RutaStream stream) {
- int minValue = min.getIntegerValue(parent, null, stream);
+ public boolean isOptional(MatchContext context, RutaStream stream) {
+ int minValue = min.getIntegerValue(context, stream);
return minValue == 0;
}
}