You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@uima.apache.org by pk...@apache.org on 2016/01/04 11:33:50 UTC
svn commit: r1722834 [5/9] - in /uima/ruta/trunk: ./
example-projects/ruta-ep-example-extensions/
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/...
Modified: uima/ruta/trunk/ruta-core/src/main/java/org/apache/uima/ruta/condition/InListCondition.java
URL: http://svn.apache.org/viewvc/uima/ruta/trunk/ruta-core/src/main/java/org/apache/uima/ruta/condition/InListCondition.java?rev=1722834&r1=1722833&r2=1722834&view=diff
==============================================================================
--- uima/ruta/trunk/ruta-core/src/main/java/org/apache/uima/ruta/condition/InListCondition.java (original)
+++ uima/ruta/trunk/ruta-core/src/main/java/org/apache/uima/ruta/condition/InListCondition.java Mon Jan 4 10:33:48 2016
@@ -28,7 +28,7 @@ import org.apache.uima.ruta.expression.r
import org.apache.uima.ruta.expression.string.IStringExpression;
import org.apache.uima.ruta.resource.RutaWordList;
import org.apache.uima.ruta.rule.EvaluatedCondition;
-import org.apache.uima.ruta.rule.RuleElement;
+import org.apache.uima.ruta.rule.MatchContext;
import org.apache.uima.ruta.visitor.InferenceCrowd;
public class InListCondition extends TerminalRutaCondition {
@@ -52,20 +52,20 @@ public class InListCondition extends Ter
}
@Override
- public EvaluatedCondition eval(AnnotationFS annotation, RuleElement element, RutaStream stream,
- InferenceCrowd crowd) {
+ public EvaluatedCondition eval(MatchContext context, RutaStream stream, InferenceCrowd crowd) {
+ AnnotationFS annotation = context.getAnnotation();
String text = annotation.getCoveredText();
- if(arg != null) {
- text = arg.getStringValue(element.getParent(), annotation, stream);
+ if (arg != null) {
+ text = arg.getStringValue(context, stream);
}
- if(text == null) {
+ if (text == null) {
return new EvaluatedCondition(this, false);
}
if (stringList == null) {
- RutaWordList wordList = listExpr.getList(element.getParent());
+ RutaWordList wordList = listExpr.getList(context);
return new EvaluatedCondition(this, wordList.contains(text, false, 0, null, 0, true));
}
- List<String> sList = stringList.getList(element.getParent(), stream);
+ List<String> sList = stringList.getList(context, stream);
boolean contains = sList.contains(text);
return new EvaluatedCondition(this, contains);
}
Modified: uima/ruta/trunk/ruta-core/src/main/java/org/apache/uima/ruta/condition/IsCondition.java
URL: http://svn.apache.org/viewvc/uima/ruta/trunk/ruta-core/src/main/java/org/apache/uima/ruta/condition/IsCondition.java?rev=1722834&r1=1722833&r2=1722834&view=diff
==============================================================================
--- uima/ruta/trunk/ruta-core/src/main/java/org/apache/uima/ruta/condition/IsCondition.java (original)
+++ uima/ruta/trunk/ruta-core/src/main/java/org/apache/uima/ruta/condition/IsCondition.java Mon Jan 4 10:33:48 2016
@@ -26,15 +26,15 @@ import org.apache.uima.cas.Type;
import org.apache.uima.cas.text.AnnotationFS;
import org.apache.uima.ruta.RutaStream;
import org.apache.uima.ruta.expression.list.TypeListExpression;
-import org.apache.uima.ruta.expression.type.TypeExpression;
+import org.apache.uima.ruta.expression.type.ITypeExpression;
import org.apache.uima.ruta.rule.EvaluatedCondition;
-import org.apache.uima.ruta.rule.RuleElement;
+import org.apache.uima.ruta.rule.MatchContext;
import org.apache.uima.ruta.type.RutaBasic;
import org.apache.uima.ruta.visitor.InferenceCrowd;
public class IsCondition extends TypeSentiveCondition {
- public IsCondition(TypeExpression type) {
+ public IsCondition(ITypeExpression type) {
super(type);
}
@@ -43,12 +43,12 @@ public class IsCondition extends TypeSen
}
@Override
- public EvaluatedCondition eval(AnnotationFS annotation, RuleElement element, RutaStream stream,
- InferenceCrowd crowd) {
+ public EvaluatedCondition eval(MatchContext context, RutaStream stream, InferenceCrowd crowd) {
+ AnnotationFS annotation = context.getAnnotation();
RutaBasic beginAnchor = stream.getBeginAnchor(annotation.getBegin());
if (!isWorkingOnList()) {
- Collection<AnnotationFS> beginAnchors = beginAnchor
- .getBeginAnchors(type.getType(element.getParent()));
+ Collection<AnnotationFS> beginAnchors = beginAnchor.getBeginAnchors(type.getType(context,
+ stream));
boolean result = false;
if (beginAnchors != null) {
for (AnnotationFS annotationFS : beginAnchors) {
@@ -61,7 +61,7 @@ public class IsCondition extends TypeSen
return new EvaluatedCondition(this, result);
} else {
boolean result = false;
- List<Type> types = getList().getList(element.getParent(), stream);
+ List<Type> types = getList().getList(context, stream);
for (Type type : types) {
Collection<AnnotationFS> beginAnchors = beginAnchor.getBeginAnchors(type);
if (beginAnchors != null) {
Modified: uima/ruta/trunk/ruta-core/src/main/java/org/apache/uima/ruta/condition/LastCondition.java
URL: http://svn.apache.org/viewvc/uima/ruta/trunk/ruta-core/src/main/java/org/apache/uima/ruta/condition/LastCondition.java?rev=1722834&r1=1722833&r2=1722834&view=diff
==============================================================================
--- uima/ruta/trunk/ruta-core/src/main/java/org/apache/uima/ruta/condition/LastCondition.java (original)
+++ uima/ruta/trunk/ruta-core/src/main/java/org/apache/uima/ruta/condition/LastCondition.java Mon Jan 4 10:33:48 2016
@@ -22,23 +22,23 @@ package org.apache.uima.ruta.condition;
import org.apache.uima.cas.Type;
import org.apache.uima.cas.text.AnnotationFS;
import org.apache.uima.ruta.RutaStream;
-import org.apache.uima.ruta.expression.type.TypeExpression;
+import org.apache.uima.ruta.expression.type.ITypeExpression;
import org.apache.uima.ruta.rule.EvaluatedCondition;
-import org.apache.uima.ruta.rule.RuleElement;
+import org.apache.uima.ruta.rule.MatchContext;
import org.apache.uima.ruta.type.RutaBasic;
import org.apache.uima.ruta.visitor.InferenceCrowd;
public class LastCondition extends TypeSentiveCondition {
- public LastCondition(TypeExpression type) {
+ public LastCondition(ITypeExpression type) {
super(type);
}
@Override
- public EvaluatedCondition eval(AnnotationFS annotation, RuleElement element, RutaStream stream,
- InferenceCrowd crowd) {
+ public EvaluatedCondition eval(MatchContext context, RutaStream stream, InferenceCrowd crowd) {
+ AnnotationFS annotation = context.getAnnotation();
RutaBasic endAnchor = stream.getEndAnchor(annotation.getEnd());
- Type t = type.getType(element.getParent());
+ Type t = type.getType(context, stream);
boolean result = endAnchor.beginsWith(t) && endAnchor.endsWith(t);
return new EvaluatedCondition(this, result);
}
Modified: uima/ruta/trunk/ruta-core/src/main/java/org/apache/uima/ruta/condition/MOfNCondition.java
URL: http://svn.apache.org/viewvc/uima/ruta/trunk/ruta-core/src/main/java/org/apache/uima/ruta/condition/MOfNCondition.java?rev=1722834&r1=1722833&r2=1722834&view=diff
==============================================================================
--- uima/ruta/trunk/ruta-core/src/main/java/org/apache/uima/ruta/condition/MOfNCondition.java (original)
+++ uima/ruta/trunk/ruta-core/src/main/java/org/apache/uima/ruta/condition/MOfNCondition.java Mon Jan 4 10:33:48 2016
@@ -22,11 +22,10 @@ package org.apache.uima.ruta.condition;
import java.util.ArrayList;
import java.util.List;
-import org.apache.uima.cas.text.AnnotationFS;
import org.apache.uima.ruta.RutaStream;
import org.apache.uima.ruta.expression.number.INumberExpression;
import org.apache.uima.ruta.rule.EvaluatedCondition;
-import org.apache.uima.ruta.rule.RuleElement;
+import org.apache.uima.ruta.rule.MatchContext;
import org.apache.uima.ruta.visitor.InferenceCrowd;
public class MOfNCondition extends ComposedRutaCondition {
@@ -43,21 +42,20 @@ public class MOfNCondition extends Compo
}
@Override
- public EvaluatedCondition eval(AnnotationFS annotation, RuleElement element, RutaStream stream,
- InferenceCrowd crowd) {
+ public EvaluatedCondition eval(MatchContext context, RutaStream stream, InferenceCrowd crowd) {
int result = 0;
List<EvaluatedCondition> evals = new ArrayList<EvaluatedCondition>();
for (AbstractRutaCondition each : conditions) {
crowd.beginVisit(each, null);
- EvaluatedCondition eval = each.eval(annotation, element, stream, crowd);
+ EvaluatedCondition eval = each.eval(context, stream, crowd);
crowd.endVisit(each, null);
evals.add(eval);
if (eval.isValue()) {
result++;
}
}
- boolean value = result >= min.getIntegerValue(element.getParent(), annotation, stream)
- && result <= max.getIntegerValue(element.getParent(), annotation, stream);
+ boolean value = result >= min.getIntegerValue(context, stream)
+ && result <= max.getIntegerValue(context, stream);
return new EvaluatedCondition(this, value, evals);
}
Modified: uima/ruta/trunk/ruta-core/src/main/java/org/apache/uima/ruta/condition/NearCondition.java
URL: http://svn.apache.org/viewvc/uima/ruta/trunk/ruta-core/src/main/java/org/apache/uima/ruta/condition/NearCondition.java?rev=1722834&r1=1722833&r2=1722834&view=diff
==============================================================================
--- uima/ruta/trunk/ruta-core/src/main/java/org/apache/uima/ruta/condition/NearCondition.java (original)
+++ uima/ruta/trunk/ruta-core/src/main/java/org/apache/uima/ruta/condition/NearCondition.java Mon Jan 4 10:33:48 2016
@@ -27,9 +27,9 @@ import org.apache.uima.ruta.expression.b
import org.apache.uima.ruta.expression.bool.SimpleBooleanExpression;
import org.apache.uima.ruta.expression.number.INumberExpression;
import org.apache.uima.ruta.expression.number.SimpleNumberExpression;
-import org.apache.uima.ruta.expression.type.TypeExpression;
+import org.apache.uima.ruta.expression.type.ITypeExpression;
import org.apache.uima.ruta.rule.EvaluatedCondition;
-import org.apache.uima.ruta.rule.RuleElement;
+import org.apache.uima.ruta.rule.MatchContext;
import org.apache.uima.ruta.type.RutaBasic;
import org.apache.uima.ruta.visitor.InferenceCrowd;
@@ -43,7 +43,7 @@ public class NearCondition extends TypeS
private final IBooleanExpression filtered;
- public NearCondition(TypeExpression type, INumberExpression min, INumberExpression max,
+ public NearCondition(ITypeExpression type, INumberExpression min, INumberExpression max,
IBooleanExpression forward, IBooleanExpression filtered) {
super(type);
this.min = min == null ? new SimpleNumberExpression(1) : min;
@@ -53,14 +53,14 @@ public class NearCondition extends TypeS
}
@Override
- public EvaluatedCondition eval(AnnotationFS annotation, RuleElement element, RutaStream stream,
- InferenceCrowd crowd) {
- int maxValue = max.getIntegerValue(element.getParent(), annotation, stream);
- int minValue = min.getIntegerValue(element.getParent(), annotation, stream);
- boolean forwardValue = forward.getBooleanValue(element.getParent(), annotation, stream);
+ public EvaluatedCondition eval(MatchContext context, RutaStream stream, InferenceCrowd crowd) {
+ AnnotationFS annotation = context.getAnnotation();
+ int maxValue = max.getIntegerValue(context, stream);
+ int minValue = min.getIntegerValue(context, stream);
+ boolean forwardValue = forward.getBooleanValue(context, stream);
- FSIterator<AnnotationFS> it = filtered.getBooleanValue(element.getParent(), annotation, stream) ? stream
- : stream.getUnfilteredBasicIterator();
+ FSIterator<AnnotationFS> it = filtered.getBooleanValue(context, stream) ? stream : stream
+ .getUnfilteredBasicIterator();
AnnotationFS pointer = null;
if (forwardValue) {
pointer = stream.getEndAnchor(annotation.getEnd());
@@ -74,7 +74,7 @@ public class NearCondition extends TypeS
FeatureStructure featureStructure = it.get();
if (featureStructure instanceof RutaBasic) {
RutaBasic each = (RutaBasic) featureStructure;
- if (each.isPartOf(type.getType(element.getParent()))) {
+ if (each.isPartOf(type.getType(context, stream))) {
return new EvaluatedCondition(this, true);
}
}
Modified: uima/ruta/trunk/ruta-core/src/main/java/org/apache/uima/ruta/condition/NotCondition.java
URL: http://svn.apache.org/viewvc/uima/ruta/trunk/ruta-core/src/main/java/org/apache/uima/ruta/condition/NotCondition.java?rev=1722834&r1=1722833&r2=1722834&view=diff
==============================================================================
--- uima/ruta/trunk/ruta-core/src/main/java/org/apache/uima/ruta/condition/NotCondition.java (original)
+++ uima/ruta/trunk/ruta-core/src/main/java/org/apache/uima/ruta/condition/NotCondition.java Mon Jan 4 10:33:48 2016
@@ -19,10 +19,9 @@
package org.apache.uima.ruta.condition;
-import org.apache.uima.cas.text.AnnotationFS;
import org.apache.uima.ruta.RutaStream;
import org.apache.uima.ruta.rule.EvaluatedCondition;
-import org.apache.uima.ruta.rule.RuleElement;
+import org.apache.uima.ruta.rule.MatchContext;
import org.apache.uima.ruta.visitor.InferenceCrowd;
public class NotCondition extends ComposedRutaCondition {
@@ -32,11 +31,10 @@ public class NotCondition extends Compos
}
@Override
- public EvaluatedCondition eval(AnnotationFS annotation, RuleElement element, RutaStream stream,
- InferenceCrowd crowd) {
+ public EvaluatedCondition eval(MatchContext context, RutaStream stream, InferenceCrowd crowd) {
AbstractRutaCondition cond = conditions.get(0);
crowd.beginVisit(cond, null);
- EvaluatedCondition eval = cond.eval(annotation, element, stream, crowd);
+ EvaluatedCondition eval = cond.eval(context, stream, crowd);
crowd.endVisit(cond, null);
return new EvaluatedCondition(this, !eval.isValue(), eval);
}
Modified: uima/ruta/trunk/ruta-core/src/main/java/org/apache/uima/ruta/condition/OrCondition.java
URL: http://svn.apache.org/viewvc/uima/ruta/trunk/ruta-core/src/main/java/org/apache/uima/ruta/condition/OrCondition.java?rev=1722834&r1=1722833&r2=1722834&view=diff
==============================================================================
--- uima/ruta/trunk/ruta-core/src/main/java/org/apache/uima/ruta/condition/OrCondition.java (original)
+++ uima/ruta/trunk/ruta-core/src/main/java/org/apache/uima/ruta/condition/OrCondition.java Mon Jan 4 10:33:48 2016
@@ -22,10 +22,9 @@ package org.apache.uima.ruta.condition;
import java.util.ArrayList;
import java.util.List;
-import org.apache.uima.cas.text.AnnotationFS;
import org.apache.uima.ruta.RutaStream;
import org.apache.uima.ruta.rule.EvaluatedCondition;
-import org.apache.uima.ruta.rule.RuleElement;
+import org.apache.uima.ruta.rule.MatchContext;
import org.apache.uima.ruta.visitor.InferenceCrowd;
public class OrCondition extends ComposedRutaCondition {
@@ -34,13 +33,12 @@ public class OrCondition extends Compose
}
@Override
- public EvaluatedCondition eval(AnnotationFS currentSymbol, RuleElement element,
- RutaStream symbolStream, InferenceCrowd crowd) {
+ public EvaluatedCondition eval(MatchContext context, RutaStream symbolStream, InferenceCrowd crowd) {
boolean result = false;
List<EvaluatedCondition> evals = new ArrayList<EvaluatedCondition>();
for (AbstractRutaCondition each : conditions) {
crowd.beginVisit(each, null);
- EvaluatedCondition eval = each.eval(currentSymbol, element, symbolStream, crowd);
+ EvaluatedCondition eval = each.eval(context, symbolStream, crowd);
crowd.endVisit(each, null);
result |= eval.isValue();
evals.add(eval);
Modified: uima/ruta/trunk/ruta-core/src/main/java/org/apache/uima/ruta/condition/ParseCondition.java
URL: http://svn.apache.org/viewvc/uima/ruta/trunk/ruta-core/src/main/java/org/apache/uima/ruta/condition/ParseCondition.java?rev=1722834&r1=1722833&r2=1722834&view=diff
==============================================================================
--- uima/ruta/trunk/ruta-core/src/main/java/org/apache/uima/ruta/condition/ParseCondition.java (original)
+++ uima/ruta/trunk/ruta-core/src/main/java/org/apache/uima/ruta/condition/ParseCondition.java Mon Jan 4 10:33:48 2016
@@ -28,6 +28,7 @@ import org.apache.uima.ruta.RutaEnvironm
import org.apache.uima.ruta.RutaStream;
import org.apache.uima.ruta.expression.string.IStringExpression;
import org.apache.uima.ruta.rule.EvaluatedCondition;
+import org.apache.uima.ruta.rule.MatchContext;
import org.apache.uima.ruta.rule.RuleElement;
import org.apache.uima.ruta.visitor.InferenceCrowd;
@@ -36,12 +37,12 @@ public class ParseCondition extends Abst
private final String var;
private IStringExpression localeExpr;
-
+
public ParseCondition(String var) {
super();
this.var = var;
}
-
+
public ParseCondition(String var, IStringExpression localeExpr) {
super();
this.var = var;
@@ -49,20 +50,21 @@ public class ParseCondition extends Abst
}
@Override
- public EvaluatedCondition eval(AnnotationFS annotation, RuleElement element, RutaStream stream,
- InferenceCrowd crowd) {
+ public EvaluatedCondition eval(MatchContext context, RutaStream stream, InferenceCrowd crowd) {
+ AnnotationFS annotation = context.getAnnotation();
+ RuleElement element = context.getElement();
String text = annotation.getCoveredText();
RutaEnvironment env = element.getParent().getEnvironment();
Class<?> type = env.getVariableType(var);
NumberFormat nf = null;
String locale = annotation.getCAS().getDocumentLanguage();
- if(localeExpr != null) {
- locale = localeExpr.getStringValue(element.getParent(), annotation, stream);
+ if (localeExpr != null) {
+ locale = localeExpr.getStringValue(context, stream);
}
- if(locale == null) {
+ if (locale == null) {
locale = "x-unspecified";
}
- nf = NumberFormat.getInstance(Locale.forLanguageTag(locale));
+ nf = NumberFormat.getInstance(Locale.forLanguageTag(locale));
try {
if (Integer.class.equals(type)) {
Number parse = nf.parse(text);
Modified: uima/ruta/trunk/ruta-core/src/main/java/org/apache/uima/ruta/condition/PartOfCondition.java
URL: http://svn.apache.org/viewvc/uima/ruta/trunk/ruta-core/src/main/java/org/apache/uima/ruta/condition/PartOfCondition.java?rev=1722834&r1=1722833&r2=1722834&view=diff
==============================================================================
--- uima/ruta/trunk/ruta-core/src/main/java/org/apache/uima/ruta/condition/PartOfCondition.java (original)
+++ uima/ruta/trunk/ruta-core/src/main/java/org/apache/uima/ruta/condition/PartOfCondition.java Mon Jan 4 10:33:48 2016
@@ -26,15 +26,16 @@ import org.apache.uima.cas.Type;
import org.apache.uima.cas.text.AnnotationFS;
import org.apache.uima.ruta.RutaStream;
import org.apache.uima.ruta.expression.list.TypeListExpression;
-import org.apache.uima.ruta.expression.type.TypeExpression;
+import org.apache.uima.ruta.expression.type.ITypeExpression;
import org.apache.uima.ruta.rule.EvaluatedCondition;
+import org.apache.uima.ruta.rule.MatchContext;
import org.apache.uima.ruta.rule.RuleElement;
import org.apache.uima.ruta.type.RutaBasic;
import org.apache.uima.ruta.visitor.InferenceCrowd;
public class PartOfCondition extends TypeSentiveCondition {
- public PartOfCondition(TypeExpression type) {
+ public PartOfCondition(ITypeExpression type) {
super(type);
}
@@ -43,15 +44,16 @@ public class PartOfCondition extends Typ
}
@Override
- public EvaluatedCondition eval(AnnotationFS annotation, RuleElement element, RutaStream stream,
- InferenceCrowd crowd) {
+ public EvaluatedCondition eval(MatchContext context, RutaStream stream, InferenceCrowd crowd) {
+ AnnotationFS annotation = context.getAnnotation();
+ RuleElement element = context.getElement();
if (!isWorkingOnList()) {
- Type t = type.getType(element.getParent());
+ Type t = type.getType(context, stream);
boolean result = check(t, annotation, element, stream);
return new EvaluatedCondition(this, result);
} else {
boolean result = false;
- List<Type> types = getList().getList(element.getParent(), stream);
+ List<Type> types = getList().getList(context, stream);
for (Type t : types) {
result |= check(t, annotation, element, stream);
if (result == true) {
@@ -64,20 +66,20 @@ public class PartOfCondition extends Typ
private boolean check(Type t, AnnotationFS annotation, RuleElement element, RutaStream stream) {
RutaBasic beginAnchor = stream.getBeginAnchor(annotation.getBegin());
- if(beginAnchor!= null && beginAnchor.isPartOf(t)) {
+ if (beginAnchor != null && beginAnchor.isPartOf(t)) {
return true;
}
RutaBasic endAnchor = stream.getEndAnchor(annotation.getEnd());
- if(endAnchor!= null && endAnchor.isPartOf(t)) {
+ if (endAnchor != null && endAnchor.isPartOf(t)) {
return true;
}
// TODO: do we really need to check again on the anchors?
Collection<AnnotationFS> beginAnchors = beginAnchor.getBeginAnchors(t);
- if(beginAnchors != null && !beginAnchors.isEmpty()) {
+ if (beginAnchors != null && !beginAnchors.isEmpty()) {
return true;
}
Collection<AnnotationFS> endAnchors = beginAnchor.getEndAnchors(t);
- if(endAnchors != null && !endAnchors.isEmpty()) {
+ if (endAnchors != null && !endAnchors.isEmpty()) {
return true;
}
return false;
Modified: uima/ruta/trunk/ruta-core/src/main/java/org/apache/uima/ruta/condition/PartOfNeqCondition.java
URL: http://svn.apache.org/viewvc/uima/ruta/trunk/ruta-core/src/main/java/org/apache/uima/ruta/condition/PartOfNeqCondition.java?rev=1722834&r1=1722833&r2=1722834&view=diff
==============================================================================
--- uima/ruta/trunk/ruta-core/src/main/java/org/apache/uima/ruta/condition/PartOfNeqCondition.java (original)
+++ uima/ruta/trunk/ruta-core/src/main/java/org/apache/uima/ruta/condition/PartOfNeqCondition.java Mon Jan 4 10:33:48 2016
@@ -26,15 +26,15 @@ import org.apache.uima.cas.Type;
import org.apache.uima.cas.text.AnnotationFS;
import org.apache.uima.ruta.RutaStream;
import org.apache.uima.ruta.expression.list.TypeListExpression;
-import org.apache.uima.ruta.expression.type.TypeExpression;
+import org.apache.uima.ruta.expression.type.ITypeExpression;
import org.apache.uima.ruta.rule.EvaluatedCondition;
-import org.apache.uima.ruta.rule.RuleElement;
+import org.apache.uima.ruta.rule.MatchContext;
import org.apache.uima.ruta.type.RutaBasic;
import org.apache.uima.ruta.visitor.InferenceCrowd;
public class PartOfNeqCondition extends TypeSentiveCondition {
- public PartOfNeqCondition(TypeExpression type) {
+ public PartOfNeqCondition(ITypeExpression type) {
super(type);
}
@@ -43,15 +43,15 @@ public class PartOfNeqCondition extends
}
@Override
- public EvaluatedCondition eval(AnnotationFS annotation, RuleElement element, RutaStream stream,
- InferenceCrowd crowd) {
+ public EvaluatedCondition eval(MatchContext context, RutaStream stream, InferenceCrowd crowd) {
+ AnnotationFS annotation = context.getAnnotation();
if (!isWorkingOnList()) {
- Type t = type.getType(element.getParent());
+ Type t = type.getType(context, stream);
boolean result = check(annotation, stream, t);
return new EvaluatedCondition(this, result);
} else {
boolean result = false;
- List<Type> types = getList().getList(element.getParent(), stream);
+ List<Type> types = getList().getList(context, stream);
for (Type t : types) {
result |= check(annotation, stream, t);
if (result == true) {
Modified: uima/ruta/trunk/ruta-core/src/main/java/org/apache/uima/ruta/condition/PositionCondition.java
URL: http://svn.apache.org/viewvc/uima/ruta/trunk/ruta-core/src/main/java/org/apache/uima/ruta/condition/PositionCondition.java?rev=1722834&r1=1722833&r2=1722834&view=diff
==============================================================================
--- uima/ruta/trunk/ruta-core/src/main/java/org/apache/uima/ruta/condition/PositionCondition.java (original)
+++ uima/ruta/trunk/ruta-core/src/main/java/org/apache/uima/ruta/condition/PositionCondition.java Mon Jan 4 10:33:48 2016
@@ -28,8 +28,9 @@ import org.apache.uima.cas.text.Annotati
import org.apache.uima.ruta.RutaStream;
import org.apache.uima.ruta.expression.bool.IBooleanExpression;
import org.apache.uima.ruta.expression.number.INumberExpression;
-import org.apache.uima.ruta.expression.type.TypeExpression;
+import org.apache.uima.ruta.expression.type.ITypeExpression;
import org.apache.uima.ruta.rule.EvaluatedCondition;
+import org.apache.uima.ruta.rule.MatchContext;
import org.apache.uima.ruta.rule.RuleElement;
import org.apache.uima.ruta.rule.RutaRuleElement;
import org.apache.uima.ruta.type.RutaBasic;
@@ -41,7 +42,7 @@ public class PositionCondition extends T
private final IBooleanExpression relative;
- public PositionCondition(TypeExpression type, INumberExpression position,
+ public PositionCondition(ITypeExpression type, INumberExpression position,
IBooleanExpression relative) {
super(type);
this.position = position;
@@ -49,9 +50,10 @@ public class PositionCondition extends T
}
@Override
- public EvaluatedCondition eval(AnnotationFS annotation, RuleElement element, RutaStream stream,
- InferenceCrowd crowd) {
- Type t = type.getType(element.getParent());
+ public EvaluatedCondition eval(MatchContext context, RutaStream stream, InferenceCrowd crowd) {
+ AnnotationFS annotation = context.getAnnotation();
+ RuleElement element = context.getElement();
+ Type t = type.getType(context, stream);
RutaBasic beginAnchor = stream.getBeginAnchor(annotation.getBegin());
RutaBasic endAnchor = stream.getEndAnchor(annotation.getEnd());
@@ -60,8 +62,7 @@ public class PositionCondition extends T
return new EvaluatedCondition(this, false);
}
- boolean relatively = relative == null ? true : relative.getBooleanValue(element.getParent(),
- annotation, stream);
+ boolean relatively = relative == null ? true : relative.getBooleanValue(context, stream);
FSIterator<AnnotationFS> iterator = stream.getCas().getAnnotationIndex(t).iterator(beginAnchor);
if (!iterator.isValid()) {
@@ -92,7 +93,7 @@ public class PositionCondition extends T
if (window == null) {
return new EvaluatedCondition(this, false);
}
- int integerValue = position.getIntegerValue(element.getParent(), annotation, stream);
+ int integerValue = position.getIntegerValue(context, stream);
if (relatively) {
int counter = 0;
List<RutaBasic> inWindow = stream.getBasicsInWindow(window);
Modified: uima/ruta/trunk/ruta-core/src/main/java/org/apache/uima/ruta/condition/RegExpCondition.java
URL: http://svn.apache.org/viewvc/uima/ruta/trunk/ruta-core/src/main/java/org/apache/uima/ruta/condition/RegExpCondition.java?rev=1722834&r1=1722833&r2=1722834&view=diff
==============================================================================
--- uima/ruta/trunk/ruta-core/src/main/java/org/apache/uima/ruta/condition/RegExpCondition.java (original)
+++ uima/ruta/trunk/ruta-core/src/main/java/org/apache/uima/ruta/condition/RegExpCondition.java Mon Jan 4 10:33:48 2016
@@ -28,7 +28,7 @@ import org.apache.uima.ruta.expression.b
import org.apache.uima.ruta.expression.bool.SimpleBooleanExpression;
import org.apache.uima.ruta.expression.string.IStringExpression;
import org.apache.uima.ruta.rule.EvaluatedCondition;
-import org.apache.uima.ruta.rule.RuleElement;
+import org.apache.uima.ruta.rule.MatchContext;
import org.apache.uima.ruta.visitor.InferenceCrowd;
public class RegExpCondition extends TerminalRutaCondition {
@@ -44,35 +44,37 @@ public class RegExpCondition extends Ter
this.ignoreCase = ignoreCase == null ? new SimpleBooleanExpression(false) : ignoreCase;
}
- public RegExpCondition(IStringExpression v, IStringExpression pattern, IBooleanExpression ignoreCase) {
+ public RegExpCondition(IStringExpression v, IStringExpression pattern,
+ IBooleanExpression ignoreCase) {
this(pattern, ignoreCase);
this.variable = v;
}
@Override
- public EvaluatedCondition eval(AnnotationFS annotation, RuleElement element, RutaStream stream,
- InferenceCrowd crowd) {
+ public EvaluatedCondition eval(MatchContext context, RutaStream stream, InferenceCrowd crowd) {
+ AnnotationFS annotation = context.getAnnotation();
Matcher matcher = null;
- boolean ignore = ignoreCase == null ? false : ignoreCase.getBooleanValue(element.getParent(),
- annotation, stream);
- String stringValue = pattern.getStringValue(element.getParent(), annotation, stream);
+ boolean ignore = ignoreCase == null ? false : ignoreCase.getBooleanValue(context, stream);
+ String stringValue = pattern.getStringValue(context, stream);
if (variable == null) {
String coveredText = annotation.getCoveredText();
Pattern regularExpPattern = null;
if (ignore) {
- regularExpPattern = Pattern.compile(stringValue, Pattern.MULTILINE + Pattern.DOTALL + Pattern.CASE_INSENSITIVE + Pattern.UNICODE_CASE);
+ regularExpPattern = Pattern.compile(stringValue, Pattern.MULTILINE + Pattern.DOTALL
+ + Pattern.CASE_INSENSITIVE + Pattern.UNICODE_CASE);
} else {
regularExpPattern = Pattern.compile(stringValue, Pattern.MULTILINE + Pattern.DOTALL);
}
matcher = regularExpPattern.matcher(coveredText);
} else {
- String variableValue = variable.getStringValue(element.getParent(), annotation, stream);
- if(variableValue == null) {
+ String variableValue = variable.getStringValue(context, stream);
+ if (variableValue == null) {
return new EvaluatedCondition(this, false);
}
Pattern regularExpPattern = null;
if (ignore) {
- regularExpPattern = Pattern.compile(stringValue, Pattern.MULTILINE + Pattern.DOTALL + Pattern.CASE_INSENSITIVE + Pattern.UNICODE_CASE);
+ regularExpPattern = Pattern.compile(stringValue, Pattern.MULTILINE + Pattern.DOTALL
+ + Pattern.CASE_INSENSITIVE + Pattern.UNICODE_CASE);
} else {
regularExpPattern = Pattern.compile(stringValue, Pattern.MULTILINE + Pattern.DOTALL);
}
Modified: uima/ruta/trunk/ruta-core/src/main/java/org/apache/uima/ruta/condition/ScoreCondition.java
URL: http://svn.apache.org/viewvc/uima/ruta/trunk/ruta-core/src/main/java/org/apache/uima/ruta/condition/ScoreCondition.java?rev=1722834&r1=1722833&r2=1722834&view=diff
==============================================================================
--- uima/ruta/trunk/ruta-core/src/main/java/org/apache/uima/ruta/condition/ScoreCondition.java (original)
+++ uima/ruta/trunk/ruta-core/src/main/java/org/apache/uima/ruta/condition/ScoreCondition.java Mon Jan 4 10:33:48 2016
@@ -28,6 +28,7 @@ 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.EvaluatedCondition;
+import org.apache.uima.ruta.rule.MatchContext;
import org.apache.uima.ruta.rule.RuleElement;
import org.apache.uima.ruta.type.RutaAnnotation;
import org.apache.uima.ruta.visitor.InferenceCrowd;
@@ -47,8 +48,9 @@ public class ScoreCondition extends Term
}
@Override
- public EvaluatedCondition eval(AnnotationFS annotation, RuleElement element, RutaStream stream,
- InferenceCrowd crowd) {
+ public EvaluatedCondition eval(MatchContext context, RutaStream stream, InferenceCrowd crowd) {
+ AnnotationFS annotation = context.getAnnotation();
+ RuleElement element = context.getElement();
Type heuristicType = stream.getJCas().getCasType(RutaAnnotation.type);
List<AnnotationFS> annotationsInWindow = stream.getAnnotationsInWindow(annotation,
heuristicType);
@@ -63,8 +65,8 @@ public class ScoreCondition extends Term
if (var != null) {
element.getParent().getEnvironment().setVariableValue(var, score);
}
- boolean value = score >= min.getDoubleValue(element.getParent(), annotation, stream)
- && score <= max.getDoubleValue(element.getParent(), annotation, stream);
+ boolean value = score >= min.getDoubleValue(context, stream)
+ && score <= max.getDoubleValue(context, stream);
return new EvaluatedCondition(this, value);
}
Modified: uima/ruta/trunk/ruta-core/src/main/java/org/apache/uima/ruta/condition/SizeCondition.java
URL: http://svn.apache.org/viewvc/uima/ruta/trunk/ruta-core/src/main/java/org/apache/uima/ruta/condition/SizeCondition.java?rev=1722834&r1=1722833&r2=1722834&view=diff
==============================================================================
--- uima/ruta/trunk/ruta-core/src/main/java/org/apache/uima/ruta/condition/SizeCondition.java (original)
+++ uima/ruta/trunk/ruta-core/src/main/java/org/apache/uima/ruta/condition/SizeCondition.java Mon Jan 4 10:33:48 2016
@@ -19,12 +19,12 @@
package org.apache.uima.ruta.condition;
-import org.apache.uima.cas.text.AnnotationFS;
import org.apache.uima.ruta.RutaStream;
import org.apache.uima.ruta.expression.list.ListExpression;
import org.apache.uima.ruta.expression.number.INumberExpression;
import org.apache.uima.ruta.expression.number.SimpleNumberExpression;
import org.apache.uima.ruta.rule.EvaluatedCondition;
+import org.apache.uima.ruta.rule.MatchContext;
import org.apache.uima.ruta.rule.RuleElement;
import org.apache.uima.ruta.visitor.InferenceCrowd;
@@ -48,11 +48,11 @@ public class SizeCondition extends Abstr
}
@Override
- public EvaluatedCondition eval(AnnotationFS annotation, RuleElement element, RutaStream stream,
- InferenceCrowd crowd) {
- int count = listExpr.getList(element.getParent(), stream).size();
- boolean value = count >= minExpr.getIntegerValue(element.getParent(), annotation, stream)
- && count <= maxExpr.getIntegerValue(element.getParent(), annotation, stream);
+ public EvaluatedCondition eval(MatchContext context, RutaStream stream, InferenceCrowd crowd) {
+ RuleElement element = context.getElement();
+ int count = listExpr.getList(context, stream).size();
+ boolean value = count >= minExpr.getIntegerValue(context, stream)
+ && count <= maxExpr.getIntegerValue(context, stream);
if (varExpr != null) {
element.getParent().getEnvironment().setVariableValue(varExpr, count);
}
Modified: uima/ruta/trunk/ruta-core/src/main/java/org/apache/uima/ruta/condition/StartsWithCondition.java
URL: http://svn.apache.org/viewvc/uima/ruta/trunk/ruta-core/src/main/java/org/apache/uima/ruta/condition/StartsWithCondition.java?rev=1722834&r1=1722833&r2=1722834&view=diff
==============================================================================
--- uima/ruta/trunk/ruta-core/src/main/java/org/apache/uima/ruta/condition/StartsWithCondition.java (original)
+++ uima/ruta/trunk/ruta-core/src/main/java/org/apache/uima/ruta/condition/StartsWithCondition.java Mon Jan 4 10:33:48 2016
@@ -25,15 +25,15 @@ import org.apache.uima.cas.Type;
import org.apache.uima.cas.text.AnnotationFS;
import org.apache.uima.ruta.RutaStream;
import org.apache.uima.ruta.expression.list.TypeListExpression;
-import org.apache.uima.ruta.expression.type.TypeExpression;
+import org.apache.uima.ruta.expression.type.ITypeExpression;
import org.apache.uima.ruta.rule.EvaluatedCondition;
-import org.apache.uima.ruta.rule.RuleElement;
+import org.apache.uima.ruta.rule.MatchContext;
import org.apache.uima.ruta.type.RutaBasic;
import org.apache.uima.ruta.visitor.InferenceCrowd;
public class StartsWithCondition extends TypeSentiveCondition {
- public StartsWithCondition(TypeExpression type) {
+ public StartsWithCondition(ITypeExpression type) {
super(type);
}
@@ -42,17 +42,17 @@ public class StartsWithCondition extends
}
@Override
- public EvaluatedCondition eval(AnnotationFS annotation, RuleElement element, RutaStream stream,
- InferenceCrowd crowd) {
+ public EvaluatedCondition eval(MatchContext context, RutaStream stream, InferenceCrowd crowd) {
+ AnnotationFS annotation = context.getAnnotation();
// TODO rewrite
if (!isWorkingOnList()) {
- Type t = type.getType(element.getParent());
+ Type t = type.getType(context, stream);
boolean result = check(annotation, t, stream);
return new EvaluatedCondition(this, result);
} else {
boolean result = false;
- List<Type> types = getList().getList(element.getParent(), stream);
+ List<Type> types = getList().getList(context, stream);
for (Type t : types) {
result |= check(annotation, t, stream);
if (result == true) {
@@ -69,7 +69,7 @@ public class StartsWithCondition extends
return false;
}
RutaBasic beginAnchor = stream.getBeginAnchor(annotation.getBegin());
- if(beginAnchor != null) {
+ if (beginAnchor != null) {
return beginAnchor.beginsWith(t);
} else {
return false;
Modified: uima/ruta/trunk/ruta-core/src/main/java/org/apache/uima/ruta/condition/TotalCountCondition.java
URL: http://svn.apache.org/viewvc/uima/ruta/trunk/ruta-core/src/main/java/org/apache/uima/ruta/condition/TotalCountCondition.java?rev=1722834&r1=1722833&r2=1722834&view=diff
==============================================================================
--- uima/ruta/trunk/ruta-core/src/main/java/org/apache/uima/ruta/condition/TotalCountCondition.java (original)
+++ uima/ruta/trunk/ruta-core/src/main/java/org/apache/uima/ruta/condition/TotalCountCondition.java Mon Jan 4 10:33:48 2016
@@ -19,14 +19,15 @@
package org.apache.uima.ruta.condition;
-import java.util.Iterator;
-
-import org.apache.uima.cas.text.AnnotationFS;
+import org.apache.uima.cas.Type;
+import org.apache.uima.cas.text.AnnotationIndex;
+import org.apache.uima.jcas.tcas.Annotation;
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.expression.type.TypeExpression;
+import org.apache.uima.ruta.expression.type.ITypeExpression;
import org.apache.uima.ruta.rule.EvaluatedCondition;
+import org.apache.uima.ruta.rule.MatchContext;
import org.apache.uima.ruta.rule.RuleElement;
import org.apache.uima.ruta.visitor.InferenceCrowd;
@@ -37,7 +38,7 @@ public class TotalCountCondition extends
private final String var;
- public TotalCountCondition(TypeExpression type, INumberExpression min, INumberExpression max,
+ public TotalCountCondition(ITypeExpression type, INumberExpression min, INumberExpression max,
String var) {
super(type);
this.min = min == null ? new SimpleNumberExpression(Integer.MIN_VALUE) : min;
@@ -46,20 +47,17 @@ public class TotalCountCondition extends
}
@Override
- public EvaluatedCondition eval(AnnotationFS annotation, RuleElement element, RutaStream stream,
- InferenceCrowd crowd) {
+ public EvaluatedCondition eval(MatchContext context, RutaStream stream, InferenceCrowd crowd) {
+ RuleElement element = context.getElement();
int count = 0;
- Iterator<?> it = stream.getJCas().getAnnotationIndex(type.getType(element.getParent()))
- .iterator();
- while (it.hasNext()) {
- it.next();
- count++;
- }
+ Type t = type.getType(context, stream);
+ AnnotationIndex<Annotation> annotationIndex = stream.getJCas().getAnnotationIndex(t);
+ count = annotationIndex.size();
if (var != null) {
element.getParent().getEnvironment().setVariableValue(var, count);
}
- boolean value = count >= min.getIntegerValue(element.getParent(), annotation, stream)
- && count <= max.getIntegerValue(element.getParent(), annotation, stream);
+ boolean value = count >= min.getIntegerValue(context, stream)
+ && count <= max.getIntegerValue(context, stream);
return new EvaluatedCondition(this, value);
}
Modified: uima/ruta/trunk/ruta-core/src/main/java/org/apache/uima/ruta/condition/TypeSentiveCondition.java
URL: http://svn.apache.org/viewvc/uima/ruta/trunk/ruta-core/src/main/java/org/apache/uima/ruta/condition/TypeSentiveCondition.java?rev=1722834&r1=1722833&r2=1722834&view=diff
==============================================================================
--- uima/ruta/trunk/ruta-core/src/main/java/org/apache/uima/ruta/condition/TypeSentiveCondition.java (original)
+++ uima/ruta/trunk/ruta-core/src/main/java/org/apache/uima/ruta/condition/TypeSentiveCondition.java Mon Jan 4 10:33:48 2016
@@ -20,19 +20,19 @@
package org.apache.uima.ruta.condition;
import org.apache.uima.ruta.expression.list.TypeListExpression;
-import org.apache.uima.ruta.expression.type.TypeExpression;
+import org.apache.uima.ruta.expression.type.ITypeExpression;
public abstract class TypeSentiveCondition extends TerminalRutaCondition {
- protected final TypeExpression type;
+ protected final ITypeExpression type;
private final TypeListExpression list;
- public TypeExpression getType() {
+ public ITypeExpression getType() {
return type;
}
- public TypeSentiveCondition(TypeExpression type) {
+ public TypeSentiveCondition(ITypeExpression type) {
super();
this.type = type;
this.list = null;
Modified: uima/ruta/trunk/ruta-core/src/main/java/org/apache/uima/ruta/condition/VariableCondition.java
URL: http://svn.apache.org/viewvc/uima/ruta/trunk/ruta-core/src/main/java/org/apache/uima/ruta/condition/VariableCondition.java?rev=1722834&r1=1722833&r2=1722834&view=diff
==============================================================================
--- uima/ruta/trunk/ruta-core/src/main/java/org/apache/uima/ruta/condition/VariableCondition.java (original)
+++ uima/ruta/trunk/ruta-core/src/main/java/org/apache/uima/ruta/condition/VariableCondition.java Mon Jan 4 10:33:48 2016
@@ -19,10 +19,9 @@
package org.apache.uima.ruta.condition;
-import org.apache.uima.cas.text.AnnotationFS;
import org.apache.uima.ruta.RutaStream;
import org.apache.uima.ruta.rule.EvaluatedCondition;
-import org.apache.uima.ruta.rule.RuleElement;
+import org.apache.uima.ruta.rule.MatchContext;
import org.apache.uima.ruta.visitor.InferenceCrowd;
public class VariableCondition extends AbstractRutaCondition {
@@ -35,8 +34,7 @@ public class VariableCondition extends A
}
@Override
- public EvaluatedCondition eval(AnnotationFS annotation, RuleElement element, RutaStream stream,
- InferenceCrowd crowd) {
+ public EvaluatedCondition eval(MatchContext context, RutaStream stream, InferenceCrowd crowd) {
return null;
}
Modified: uima/ruta/trunk/ruta-core/src/main/java/org/apache/uima/ruta/condition/VoteCondition.java
URL: http://svn.apache.org/viewvc/uima/ruta/trunk/ruta-core/src/main/java/org/apache/uima/ruta/condition/VoteCondition.java?rev=1722834&r1=1722833&r2=1722834&view=diff
==============================================================================
--- uima/ruta/trunk/ruta-core/src/main/java/org/apache/uima/ruta/condition/VoteCondition.java (original)
+++ uima/ruta/trunk/ruta-core/src/main/java/org/apache/uima/ruta/condition/VoteCondition.java Mon Jan 4 10:33:48 2016
@@ -24,36 +24,34 @@ import java.util.List;
import org.apache.uima.cas.Type;
import org.apache.uima.cas.text.AnnotationFS;
import org.apache.uima.ruta.RutaStream;
-import org.apache.uima.ruta.expression.type.TypeExpression;
+import org.apache.uima.ruta.expression.type.ITypeExpression;
import org.apache.uima.ruta.rule.EvaluatedCondition;
-import org.apache.uima.ruta.rule.RuleElement;
+import org.apache.uima.ruta.rule.MatchContext;
import org.apache.uima.ruta.type.RutaBasic;
import org.apache.uima.ruta.visitor.InferenceCrowd;
public class VoteCondition extends TerminalRutaCondition {
- private final TypeExpression type1;
+ private final ITypeExpression type1;
- private final TypeExpression type2;
+ private final ITypeExpression type2;
- public VoteCondition(TypeExpression type1, TypeExpression type2) {
+ public VoteCondition(ITypeExpression type1, ITypeExpression type2) {
super();
this.type1 = type1;
this.type2 = type2;
}
@Override
- public EvaluatedCondition eval(AnnotationFS annotation, RuleElement element, RutaStream stream,
- InferenceCrowd crowd) {
+ public EvaluatedCondition eval(MatchContext context, RutaStream stream, InferenceCrowd crowd) {
+ AnnotationFS annotation = context.getAnnotation();
int count1 = 0;
int count2 = 0;
- int totalCount = 0;
if (annotation != null) {
List<RutaBasic> annotations = stream.getBasicsInWindow(annotation);
- Type t1 = type1.getType(element.getParent());
- Type t2 = type2.getType(element.getParent());
+ Type t1 = type1.getType(context, stream);
+ Type t2 = type2.getType(context, stream);
for (RutaBasic each : annotations) {
- totalCount++;
if (each.beginsWith(t1)) {
count1++;
}
@@ -65,11 +63,11 @@ public class VoteCondition extends Termi
return new EvaluatedCondition(this, count1 > count2);
}
- public TypeExpression getType1() {
+ public ITypeExpression getType1() {
return type1;
}
- public TypeExpression getType2() {
+ public ITypeExpression getType2() {
return type2;
}
}
Modified: uima/ruta/trunk/ruta-core/src/main/java/org/apache/uima/ruta/constraint/BasicTypeConstraint.java
URL: http://svn.apache.org/viewvc/uima/ruta/trunk/ruta-core/src/main/java/org/apache/uima/ruta/constraint/BasicTypeConstraint.java?rev=1722834&r1=1722833&r2=1722834&view=diff
==============================================================================
--- uima/ruta/trunk/ruta-core/src/main/java/org/apache/uima/ruta/constraint/BasicTypeConstraint.java (original)
+++ uima/ruta/trunk/ruta-core/src/main/java/org/apache/uima/ruta/constraint/BasicTypeConstraint.java Mon Jan 4 10:33:48 2016
@@ -31,7 +31,6 @@ import org.apache.uima.ruta.type.RutaBas
public class BasicTypeConstraint implements FSTypeConstraint {
private static final long serialVersionUID = 1115953538613617791L;
-
private final Collection<Type> types;
public BasicTypeConstraint(Collection<Type> types) {
@@ -56,13 +55,12 @@ public class BasicTypeConstraint impleme
public void add(String typeString) {
throw new NotImplementedException();
}
-
public boolean match(FeatureStructure fs) {
boolean result = false;
if (fs instanceof RutaBasic) {
RutaBasic tmb = (RutaBasic) fs;
- if(tmb.isEmpty()) {
+ if (tmb.isEmpty()) {
return true;
}
if (types != null) {
@@ -73,15 +71,13 @@ public class BasicTypeConstraint impleme
}
}
}
- }
+ }
return result;
}
@Override
public String toString() {
- return "(BASIC " + " with " + types + ")";
+ return "(BASIC " + " with " + types + ")";
}
-
-
}
Modified: uima/ruta/trunk/ruta-core/src/main/java/org/apache/uima/ruta/descriptor/RutaDescriptorBuilder.java
URL: http://svn.apache.org/viewvc/uima/ruta/trunk/ruta-core/src/main/java/org/apache/uima/ruta/descriptor/RutaDescriptorBuilder.java?rev=1722834&r1=1722833&r2=1722834&view=diff
==============================================================================
--- uima/ruta/trunk/ruta-core/src/main/java/org/apache/uima/ruta/descriptor/RutaDescriptorBuilder.java (original)
+++ uima/ruta/trunk/ruta-core/src/main/java/org/apache/uima/ruta/descriptor/RutaDescriptorBuilder.java Mon Jan 4 10:33:48 2016
@@ -320,11 +320,11 @@ public class RutaDescriptorBuilder {
URISyntaxException {
build(desc, typeSystemOutput, engineOutput, options, scriptPaths, enginePaths, null);
}
-
+
public void build(RutaDescriptorInformation desc, String typeSystemOutput, String engineOutput,
- RutaBuildOptions options, String[] scriptPaths, String[] enginePaths, String[] resourcePaths)
- throws SAXException, InvalidXMLException, IOException, ResourceInitializationException,
- URISyntaxException {
+ RutaBuildOptions options, String[] scriptPaths, String[] enginePaths,
+ String[] resourcePaths) throws SAXException, InvalidXMLException, IOException,
+ ResourceInitializationException, URISyntaxException {
TypeSystemDescription typeSystemDescription = createTypeSystemDescription(desc,
typeSystemOutput, options, enginePaths);
@@ -424,7 +424,7 @@ public class RutaDescriptorBuilder {
AnalysisEngineDescription analysisEngineDescription = UIMAFramework.getXMLParser()
.parseAnalysisEngineDescription(new XMLInputSource(defaultAnalysisEngine));
- if(import_impl != null) {
+ if (import_impl != null) {
aets.setImports(new Import[] { import_impl });
}
analysisEngineDescription.getAnalysisEngineMetaData().setTypeSystem(aets);
Modified: uima/ruta/trunk/ruta-core/src/main/java/org/apache/uima/ruta/descriptor/RutaDescriptorFactory.java
URL: http://svn.apache.org/viewvc/uima/ruta/trunk/ruta-core/src/main/java/org/apache/uima/ruta/descriptor/RutaDescriptorFactory.java?rev=1722834&r1=1722833&r2=1722834&view=diff
==============================================================================
--- uima/ruta/trunk/ruta-core/src/main/java/org/apache/uima/ruta/descriptor/RutaDescriptorFactory.java (original)
+++ uima/ruta/trunk/ruta-core/src/main/java/org/apache/uima/ruta/descriptor/RutaDescriptorFactory.java Mon Jan 4 10:33:48 2016
@@ -48,7 +48,7 @@ import org.apache.uima.util.InvalidXMLEx
public class RutaDescriptorFactory {
-// public static final String ANONYMOUS = "Anonymous";
+ // public static final String ANONYMOUS = "Anonymous";
private URL defaultTypeSystem;
@@ -176,7 +176,7 @@ public class RutaDescriptorFactory {
private ResourceManager getResourceManager(RutaBuildOptions options) {
ResourceManager rm = null;
- if(options.getClassLoader() != null) {
+ if (options.getClassLoader() != null) {
rm = new ResourceManager_impl(options.getClassLoader());
} else {
rm = UIMAFramework.newDefaultResourceManager();
@@ -191,7 +191,7 @@ public class RutaDescriptorFactory {
try {
Class<?> forName = null;
if (options.getClassLoader() != null) {
- forName = options.getClassLoader().loadClass(each);
+ forName = options.getClassLoader().loadClass(each);
} else {
forName = Class.forName(each);
}
Modified: uima/ruta/trunk/ruta-core/src/main/java/org/apache/uima/ruta/engine/HtmlAnnotator.java
URL: http://svn.apache.org/viewvc/uima/ruta/trunk/ruta-core/src/main/java/org/apache/uima/ruta/engine/HtmlAnnotator.java?rev=1722834&r1=1722833&r2=1722834&view=diff
==============================================================================
--- uima/ruta/trunk/ruta-core/src/main/java/org/apache/uima/ruta/engine/HtmlAnnotator.java (original)
+++ uima/ruta/trunk/ruta-core/src/main/java/org/apache/uima/ruta/engine/HtmlAnnotator.java Mon Jan 4 10:33:48 2016
@@ -37,8 +37,8 @@ import org.htmlparser.util.ParserExcepti
* This Analysis Engine provides support for HTML files by adding annotations for the HTML elements.
* Using the default values, the HTML Annotator creates annotations for each HTML element spanning
* the content of the element, whereas the most common elements are represented by own types. The
- * document <code>This text is <b>bold</b>.</code>, for example, would be annotated
- * with an annotation of the type <code>org.apache.uima.ruta.type.html.B</code> for the word
+ * document <code>This text is <b>bold</b>.</code>, for example, would be annotated with an
+ * annotation of the type <code>org.apache.uima.ruta.type.html.B</code> for the word
* <code>bold</code>. The HTML annotator can be configured in order to include the start and end
* elements in the created annotations. A descriptor file for this Analysis Engine is located in the
* folder <code>descriptor/utils</code> of a UIMA Ruta project.
Modified: uima/ruta/trunk/ruta-core/src/main/java/org/apache/uima/ruta/engine/HtmlConverter.java
URL: http://svn.apache.org/viewvc/uima/ruta/trunk/ruta-core/src/main/java/org/apache/uima/ruta/engine/HtmlConverter.java?rev=1722834&r1=1722833&r2=1722834&view=diff
==============================================================================
--- uima/ruta/trunk/ruta-core/src/main/java/org/apache/uima/ruta/engine/HtmlConverter.java (original)
+++ uima/ruta/trunk/ruta-core/src/main/java/org/apache/uima/ruta/engine/HtmlConverter.java Mon Jan 4 10:33:48 2016
@@ -59,8 +59,8 @@ import org.htmlparser.util.ParserExcepti
* it would be mapped to an annotation of length 0, it is not moved to the new view.
*
* The HTML Converter also supports heuristic and explicit conversion patterns which default to
- * html4 decoding, e.g., "{@literal }", "{@literal <}", etc. Concepts like tables or
- * lists are not supported.
+ * html4 decoding, e.g., "{@literal }", "{@literal <}", etc. Concepts like tables or lists
+ * are not supported.
*
* Note that in general it is suggested to run an html cleaner before any further processing to
* avoid problems with malformed html.
@@ -180,7 +180,7 @@ public class HtmlConverter extends JCasA
@ConfigurationParameter(name = PARAM_GAP_TEXT, mandatory = false, defaultValue = "")
private String gapText;
-
+
/**
* This boolean parameter sets the value of the parameter <code>gapText</code> to a single space.
*/
@@ -281,24 +281,25 @@ public class HtmlConverter extends JCasA
conversionReplacements[i] = rep;
}
}
-
+
gapText = (String) aContext.getConfigParameterValue(PARAM_GAP_TEXT);
gapText = gapText == null ? "" : gapText;
-
+
useSpaceGap = (Boolean) aContext.getConfigParameterValue(PARAM_USE_SPACE_GAP);
useSpaceGap = useSpaceGap == null ? false : useSpaceGap;
-
- if(useSpaceGap) {
+
+ if (useSpaceGap) {
gapText = " ";
}
-
+
gapInducingTags = (String[]) aContext.getConfigParameterValue(PARAM_GAP_INDUCING_TAGS);
gapInducingTags = gapInducingTags == null ? new String[0] : gapInducingTags;
-
+
expandOffsets = (Boolean) aContext.getConfigParameterValue(PARAM_EXPAND_OFFSETS);
expandOffsets = expandOffsets == null ? false : expandOffsets;
-
- newlineInducingTagRegExp = (String) aContext.getConfigParameterValue(PARAM_NEWLINE_INDUCING_TAG_REGEXP);
+
+ newlineInducingTagRegExp = (String) aContext
+ .getConfigParameterValue(PARAM_NEWLINE_INDUCING_TAG_REGEXP);
}
@Override
@@ -344,8 +345,8 @@ public class HtmlConverter extends JCasA
try {
Parser parser = new Parser(documentText);
NodeList list = parser.parse(null);
- HtmlConverterVisitor visitor = new HtmlConverterVisitor(newlineInducingTags, newlineInducingTagRegExp, gapInducingTags,
- gapText, skipWhitespaces, processAll);
+ HtmlConverterVisitor visitor = new HtmlConverterVisitor(newlineInducingTags,
+ newlineInducingTagRegExp, gapInducingTags, gapText, skipWhitespaces, processAll);
list.visitAllNodesWith(visitor);
visibleSpansSoFar = visitor.getTextSpans();
linebreaksFromHtmlTags = visitor.getLinebreaksFromHtmlTags();
Modified: uima/ruta/trunk/ruta-core/src/main/java/org/apache/uima/ruta/engine/PlainTextAnnotator.java
URL: http://svn.apache.org/viewvc/uima/ruta/trunk/ruta-core/src/main/java/org/apache/uima/ruta/engine/PlainTextAnnotator.java?rev=1722834&r1=1722833&r2=1722834&view=diff
==============================================================================
--- uima/ruta/trunk/ruta-core/src/main/java/org/apache/uima/ruta/engine/PlainTextAnnotator.java (original)
+++ uima/ruta/trunk/ruta-core/src/main/java/org/apache/uima/ruta/engine/PlainTextAnnotator.java Mon Jan 4 10:33:48 2016
@@ -36,7 +36,7 @@ public class PlainTextAnnotator extends
public static final String TYPE_LINE = "org.apache.uima.ruta.type.Line";
public static final String TYPE_WSLINE = "org.apache.uima.ruta.type.WSLine";
-
+
public static final String TYPE_EMPTYLINE = "org.apache.uima.ruta.type.EmptyLine";
public static final String TYPE_PARAGRAPH = "org.apache.uima.ruta.type.Paragraph";
@@ -60,7 +60,9 @@ public class PlainTextAnnotator extends
try {
while ((eachLine = br.readLine()) != null) {
boolean wsLine = StringUtils.isBlank(eachLine);
- if(!wsLine && StringUtils.isBlank(eachLine.trim().replaceAll("\u00A0|\u202F|\uFEFF|\u2007|\u180E", ""))) {
+ if (!wsLine
+ && StringUtils.isBlank(eachLine.trim().replaceAll(
+ "\u00A0|\u202F|\uFEFF|\u2007|\u180E", ""))) {
// HOTFIX for NBSPs
wsLine = true;
}
@@ -80,8 +82,8 @@ public class PlainTextAnnotator extends
if (wsLine && emptyLine) {
// do not create annotation with length 0
// instead append the line break to the annotation
- AnnotationFS newEmptyLineFS = cas.createAnnotation(emptyLineType, offsetTillNow, offsetTillNow
- + nlLength);
+ AnnotationFS newEmptyLineFS = cas.createAnnotation(emptyLineType, offsetTillNow,
+ offsetTillNow + nlLength);
cas.addFsToIndexes(newEmptyLineFS);
} else if (wsLine && !emptyLine) {
AnnotationFS newWSLineFS = cas.createAnnotation(wsLineType, offsetTillNow, offsetTillNow
Modified: uima/ruta/trunk/ruta-core/src/main/java/org/apache/uima/ruta/engine/Ruta.java
URL: http://svn.apache.org/viewvc/uima/ruta/trunk/ruta-core/src/main/java/org/apache/uima/ruta/engine/Ruta.java?rev=1722834&r1=1722833&r2=1722834&view=diff
==============================================================================
--- uima/ruta/trunk/ruta-core/src/main/java/org/apache/uima/ruta/engine/Ruta.java (original)
+++ uima/ruta/trunk/ruta-core/src/main/java/org/apache/uima/ruta/engine/Ruta.java Mon Jan 4 10:33:48 2016
@@ -59,8 +59,8 @@ public class Ruta {
File scriptFile = File.createTempFile("Ruta", RutaEngine.SCRIPT_FILE_EXTENSION);
scriptFile.deleteOnExit();
FileUtils.saveString2File(script, scriptFile);
- ae.setConfigParameterValue(RutaEngine.PARAM_SCRIPT_PATHS, new String[] { scriptFile.getParentFile()
- .getAbsolutePath() });
+ ae.setConfigParameterValue(RutaEngine.PARAM_SCRIPT_PATHS, new String[] { scriptFile
+ .getParentFile().getAbsolutePath() });
String name = scriptFile.getName().substring(0, scriptFile.getName().length() - 5);
ae.setConfigParameterValue(RutaEngine.PARAM_MAIN_SCRIPT, name);
if (parameters != null) {
@@ -135,8 +135,8 @@ public class Ruta {
.parseResourceSpecifier(in);
AnalysisEngineMetaData metaData = aed.getAnalysisEngineMetaData();
ConfigurationParameterSettings settings = metaData.getConfigurationParameterSettings();
- settings.setParameterValue(RutaEngine.PARAM_SCRIPT_PATHS, new String[] { scriptFile.getParentFile()
- .getAbsolutePath() });
+ settings.setParameterValue(RutaEngine.PARAM_SCRIPT_PATHS, new String[] { scriptFile
+ .getParentFile().getAbsolutePath() });
String name = scriptFile.getName().substring(0, scriptFile.getName().length() - 5);
settings.setParameterValue(RutaEngine.PARAM_MAIN_SCRIPT, name);
if (tsds != null) {
Modified: uima/ruta/trunk/ruta-core/src/main/java/org/apache/uima/ruta/engine/RutaTestUtils.java
URL: http://svn.apache.org/viewvc/uima/ruta/trunk/ruta-core/src/main/java/org/apache/uima/ruta/engine/RutaTestUtils.java?rev=1722834&r1=1722833&r2=1722834&view=diff
==============================================================================
--- uima/ruta/trunk/ruta-core/src/main/java/org/apache/uima/ruta/engine/RutaTestUtils.java (original)
+++ uima/ruta/trunk/ruta-core/src/main/java/org/apache/uima/ruta/engine/RutaTestUtils.java Mon Jan 4 10:33:48 2016
@@ -76,9 +76,9 @@ public class RutaTestUtils {
return process(ruleFileName, textFileName, amount, false, false, null, null, null, null);
}
- public static CAS process(String ruleFileName, String textFileName, Map<String, Object> parameters, int amount)
- throws URISyntaxException, IOException, InvalidXMLException,
- ResourceInitializationException, AnalysisEngineProcessException,
+ public static CAS process(String ruleFileName, String textFileName,
+ Map<String, Object> parameters, int amount) throws URISyntaxException, IOException,
+ InvalidXMLException, ResourceInitializationException, AnalysisEngineProcessException,
ResourceConfigurationException {
return process(ruleFileName, textFileName, parameters, amount, null, null, null, null);
}
@@ -112,14 +112,15 @@ public class RutaTestUtils {
parameters.put(RutaEngine.PARAM_DYNAMIC_ANCHORING, dynamicAnchoring);
parameters.put(RutaEngine.PARAM_SIMPLE_GREEDY_FOR_COMPOSED, simpleGreedyForComposed);
- return process(ruleFileName, textFileName, parameters, amount, complexTypes, features, resourceDirName, cas);
+ return process(ruleFileName, textFileName, parameters, amount, complexTypes, features,
+ resourceDirName, cas);
}
- public static CAS process(String ruleFileName, String textFileName, Map<String, Object> parameters,
- int amount,
- Map<String, String> complexTypes, Map<String, List<TestFeature>> features,
- String resourceDirName, CAS cas) throws URISyntaxException, IOException,
- InvalidXMLException, ResourceInitializationException, AnalysisEngineProcessException,
+ public static CAS process(String ruleFileName, String textFileName,
+ Map<String, Object> parameters, int amount, Map<String, String> complexTypes,
+ Map<String, List<TestFeature>> features, String resourceDirName, CAS cas)
+ throws URISyntaxException, IOException, InvalidXMLException,
+ ResourceInitializationException, AnalysisEngineProcessException,
ResourceConfigurationException {
URL ruleURL = RutaTestUtils.class.getClassLoader().getResource(ruleFileName);
File ruleFile = new File(ruleURL.toURI());
@@ -164,8 +165,8 @@ public class RutaTestUtils {
aed.getAnalysisEngineMetaData().setTypeSystem(mergeTypeSystems);
AnalysisEngine ae = UIMAFramework.produceAnalysisEngine(specifier);
- ae.setConfigParameterValue(RutaEngine.PARAM_SCRIPT_PATHS, new String[]{ruleFile.getParentFile()
- .getPath()});
+ ae.setConfigParameterValue(RutaEngine.PARAM_SCRIPT_PATHS, new String[] { ruleFile
+ .getParentFile().getPath() });
String name = ruleFile.getName();
if (name.endsWith(RutaEngine.SCRIPT_FILE_EXTENSION)) {
name = name.substring(0, name.length() - 5);
@@ -178,7 +179,8 @@ public class RutaTestUtils {
ae.setConfigParameterValue(RutaEngine.PARAM_MAIN_SCRIPT, name);
if (resourceFile != null) {
- ae.setConfigParameterValue(RutaEngine.PARAM_RESOURCE_PATHS, new String[]{resourceFile.getPath()});
+ ae.setConfigParameterValue(RutaEngine.PARAM_RESOURCE_PATHS,
+ new String[] { resourceFile.getPath() });
}
ae.reconfigure();
@@ -195,7 +197,7 @@ public class RutaTestUtils {
/**
* Helper to get the test type, e.g. org.apache.uima.T1, org.apache.uima.T2, ...
*
- * @param cas
+ * @param cas
* The CAS object containing the type system
* @param i
* typeId, converted to {@link #TYPE} + i
@@ -217,7 +219,8 @@ public class RutaTestUtils {
IOException, InvalidXMLException {
URL url = RutaEngine.class.getClassLoader().getResource("BasicEngine.xml");
if (url == null) {
- url = RutaTestUtils.class.getClassLoader().getResource("org/apache/uima/ruta/BasicEngine.xml");
+ url = RutaTestUtils.class.getClassLoader()
+ .getResource("org/apache/uima/ruta/BasicEngine.xml");
}
if (url == null) {
url = RutaTestUtils.class.getResource("BasicEngine.xml");
@@ -254,7 +257,6 @@ public class RutaTestUtils {
return cas;
}
-
/**
* Helper for common assertion in JUnit tests
*
@@ -263,18 +265,21 @@ public class RutaTestUtils {
* @param expectedCnt
* @param expecteds
*/
- public static void assertAnnotationsEquals(CAS cas, int typeId, int expectedCnt, String... expecteds) {
+ public static void assertAnnotationsEquals(CAS cas, int typeId, int expectedCnt,
+ String... expecteds) {
Type t = getTestType(cas, typeId);
AnnotationIndex<AnnotationFS> ai = cas.getAnnotationIndex(t);
if (ai.size() != expectedCnt) {
- throw new AssertionError("size of expected annotations ("+expectedCnt+") does not match with actual size ("+ai.size()+").");
+ throw new AssertionError("size of expected annotations (" + expectedCnt
+ + ") does not match with actual size (" + ai.size() + ").");
}
if (expecteds.length > 0) {
FSIterator<AnnotationFS> iterator = ai.iterator();
for (String expected : expecteds) {
- String actual =iterator.next().getCoveredText();
+ String actual = iterator.next().getCoveredText();
if (!actual.equals(expected)) {
- throw new AssertionError("expected text ("+expected+") does not match with actual ("+actual+").");
+ throw new AssertionError("expected text (" + expected + ") does not match with actual ("
+ + actual + ").");
}
}
}
@@ -292,8 +297,8 @@ public class RutaTestUtils {
CAS cas = null;
try {
- cas = RutaTestUtils.process(namespace + "/" + name + RutaEngine.SCRIPT_FILE_EXTENSION, namespace + "/" + name
- + ".txt", 50);
+ cas = RutaTestUtils.process(namespace + "/" + name + RutaEngine.SCRIPT_FILE_EXTENSION,
+ namespace + "/" + name + ".txt", 50);
} catch (Exception e) {
e.printStackTrace();
throw new RuntimeException(e);
Modified: uima/ruta/trunk/ruta-core/src/main/java/org/apache/uima/ruta/engine/ViewWriter.java
URL: http://svn.apache.org/viewvc/uima/ruta/trunk/ruta-core/src/main/java/org/apache/uima/ruta/engine/ViewWriter.java?rev=1722834&r1=1722833&r2=1722834&view=diff
==============================================================================
--- uima/ruta/trunk/ruta-core/src/main/java/org/apache/uima/ruta/engine/ViewWriter.java (original)
+++ uima/ruta/trunk/ruta-core/src/main/java/org/apache/uima/ruta/engine/ViewWriter.java Mon Jan 4 10:33:48 2016
@@ -60,7 +60,6 @@ public class ViewWriter extends JCasMult
@ConfigurationParameter(name = PARAM_OUTPUT, mandatory = false, defaultValue = "")
private String output;
-
/**
* The name of the view that should be stored in a file. The default value is "_InitialView".
*/
@@ -68,19 +67,15 @@ public class ViewWriter extends JCasMult
@ConfigurationParameter(name = PARAM_INPUT_VIEW, mandatory = false, defaultValue = "_InitialView")
private String inputView;
-
/**
- * The name, which should be used, to store the view in the file. The default value is "_InitialView".
+ * The name, which should be used, to store the view in the file. The default value is
+ * "_InitialView".
*/
public static final String PARAM_OUTPUT_VIEW = "outputView";
@ConfigurationParameter(name = PARAM_OUTPUT_VIEW, mandatory = false, defaultValue = "_InitialView")
private String outputView;
-
-
-
-
private CAS outView;
Modified: uima/ruta/trunk/ruta-core/src/main/java/org/apache/uima/ruta/expression/ExpressionFactory.java
URL: http://svn.apache.org/viewvc/uima/ruta/trunk/ruta-core/src/main/java/org/apache/uima/ruta/expression/ExpressionFactory.java?rev=1722834&r1=1722833&r2=1722834&view=diff
==============================================================================
--- uima/ruta/trunk/ruta-core/src/main/java/org/apache/uima/ruta/expression/ExpressionFactory.java (original)
+++ uima/ruta/trunk/ruta-core/src/main/java/org/apache/uima/ruta/expression/ExpressionFactory.java Mon Jan 4 10:33:48 2016
@@ -24,11 +24,16 @@ import java.util.List;
import org.antlr.runtime.Token;
import org.apache.uima.ruta.RutaBlock;
+import org.apache.uima.ruta.expression.annotation.AnnotationAddressExpression;
+import org.apache.uima.ruta.expression.annotation.AnnotationFeatureExpression;
+import org.apache.uima.ruta.expression.annotation.AnnotationLabelExpression;
+import org.apache.uima.ruta.expression.annotation.AnnotationVariableExpression;
+import org.apache.uima.ruta.expression.annotation.IAnnotationExpression;
import org.apache.uima.ruta.expression.bool.BooleanFeatureExpression;
import org.apache.uima.ruta.expression.bool.BooleanNumberExpression;
import org.apache.uima.ruta.expression.bool.BooleanTypeExpression;
+import org.apache.uima.ruta.expression.bool.BooleanVariableExpression;
import org.apache.uima.ruta.expression.bool.IBooleanExpression;
-import org.apache.uima.ruta.expression.bool.ReferenceBooleanExpression;
import org.apache.uima.ruta.expression.bool.SimpleBooleanExpression;
import org.apache.uima.ruta.expression.bool.SimpleBooleanFunction;
import org.apache.uima.ruta.expression.feature.FeatureExpression;
@@ -36,24 +41,24 @@ import org.apache.uima.ruta.expression.f
import org.apache.uima.ruta.expression.feature.GenericFeatureExpression;
import org.apache.uima.ruta.expression.feature.SimpleFeatureExpression;
import org.apache.uima.ruta.expression.list.BooleanListExpression;
+import org.apache.uima.ruta.expression.list.BooleanListVariableExpression;
import org.apache.uima.ruta.expression.list.ListExpression;
import org.apache.uima.ruta.expression.list.NumberListExpression;
-import org.apache.uima.ruta.expression.list.ReferenceBooleanListExpression;
-import org.apache.uima.ruta.expression.list.ReferenceNumberListExpression;
-import org.apache.uima.ruta.expression.list.ReferenceStringListExpression;
-import org.apache.uima.ruta.expression.list.ReferenceTypeListExpression;
+import org.apache.uima.ruta.expression.list.NumberListVariableExpression;
import org.apache.uima.ruta.expression.list.SimpleBooleanListExpression;
import org.apache.uima.ruta.expression.list.SimpleNumberListExpression;
import org.apache.uima.ruta.expression.list.SimpleStringListExpression;
import org.apache.uima.ruta.expression.list.SimpleTypeListExpression;
import org.apache.uima.ruta.expression.list.StringListExpression;
+import org.apache.uima.ruta.expression.list.StringListVariableExpression;
import org.apache.uima.ruta.expression.list.TypeListExpression;
+import org.apache.uima.ruta.expression.list.TypeListVariableExpression;
import org.apache.uima.ruta.expression.list.UntypedListExpression;
import org.apache.uima.ruta.expression.number.ComposedNumberExpression;
import org.apache.uima.ruta.expression.number.INumberExpression;
import org.apache.uima.ruta.expression.number.NegativeNumberExpression;
import org.apache.uima.ruta.expression.number.NumberFeatureExpression;
-import org.apache.uima.ruta.expression.number.ReferenceNumberExpression;
+import org.apache.uima.ruta.expression.number.NumberVariableExpression;
import org.apache.uima.ruta.expression.number.SimpleNumberExpression;
import org.apache.uima.ruta.expression.resource.ExternalWordListExpression;
import org.apache.uima.ruta.expression.resource.ExternalWordTableExpression;
@@ -66,12 +71,12 @@ import org.apache.uima.ruta.expression.r
import org.apache.uima.ruta.expression.string.AbstractStringExpression;
import org.apache.uima.ruta.expression.string.ComposedStringExpression;
import org.apache.uima.ruta.expression.string.IStringExpression;
-import org.apache.uima.ruta.expression.string.ReferenceStringExpression;
import org.apache.uima.ruta.expression.string.SimpleStringExpression;
import org.apache.uima.ruta.expression.string.StringFeatureExpression;
-import org.apache.uima.ruta.expression.type.ReferenceTypeExpression;
+import org.apache.uima.ruta.expression.string.StringVariableExpression;
+import org.apache.uima.ruta.expression.type.ITypeExpression;
import org.apache.uima.ruta.expression.type.SimpleTypeExpression;
-import org.apache.uima.ruta.expression.type.TypeExpression;
+import org.apache.uima.ruta.expression.type.TypeVariableExpression;
public class ExpressionFactory {
@@ -99,7 +104,7 @@ public class ExpressionFactory {
}
public static INumberExpression createReferenceNumberExpression(Token var, Token minus) {
- ReferenceNumberExpression simpleNumberExpression = new ReferenceNumberExpression(var.getText());
+ NumberVariableExpression simpleNumberExpression = new NumberVariableExpression(var.getText());
if (minus != null) {
return new NegativeNumberExpression(simpleNumberExpression);
} else {
@@ -107,8 +112,8 @@ public class ExpressionFactory {
}
}
- public static INumberExpression createComposedNumberExpression(List<INumberExpression> expressions,
- List<Token> opTokens) {
+ public static INumberExpression createComposedNumberExpression(
+ List<INumberExpression> expressions, List<Token> opTokens) {
List<String> ops = new ArrayList<String>();
for (Token token : opTokens) {
ops.add(token.getText());
@@ -124,7 +129,7 @@ public class ExpressionFactory {
exprList.add(expression);
return new ComposedNumberExpression(exprList, ops);
}
-
+
public static INumberExpression createComposedNumberExpression(INumberExpression expression1,
Token opToken, INumberExpression expression2) {
List<String> ops = new ArrayList<String>();
@@ -146,7 +151,7 @@ public class ExpressionFactory {
}
public static AbstractStringExpression createReferenceStringExpression(Token var) {
- return new ReferenceStringExpression(var.getText());
+ return new StringVariableExpression(var.getText());
}
public static IBooleanExpression createBooleanNumberExpression(INumberExpression e1, Token op,
@@ -159,20 +164,20 @@ public class ExpressionFactory {
}
public static IBooleanExpression createReferenceBooleanExpression(Token id) {
- return new ReferenceBooleanExpression(id.getText());
+ return new BooleanVariableExpression(id.getText());
}
- public static TypeExpression createSimpleTypeExpression(Token typeToken, RutaBlock parent) {
+ public static ITypeExpression createSimpleTypeExpression(Token typeToken, RutaBlock parent) {
String typeString = typeToken == null ? "uima.tcas.DocumentAnnotation" : typeToken.getText();
return new SimpleTypeExpression(typeString);
}
- public static TypeExpression createReferenceTypeExpression(Token varToken) {
+ public static ITypeExpression createReferenceTypeExpression(Token varToken) {
String varString = varToken == null ? "" : varToken.getText();
- return new ReferenceTypeExpression(varString);
+ return new TypeVariableExpression(varString);
}
- public static TypeExpression createSimpleTypeExpression(String typeString, RutaBlock parent) {
+ public static ITypeExpression createSimpleTypeExpression(String typeString, RutaBlock parent) {
return new SimpleTypeExpression(typeString);
}
@@ -197,33 +202,33 @@ public class ExpressionFactory {
return new LiteralWordTableExpression(path.getText());
}
- public static IBooleanExpression createBooleanTypeExpression(TypeExpression e1, Token op,
- TypeExpression e2) {
+ public static IBooleanExpression createBooleanTypeExpression(ITypeExpression e1, Token op,
+ ITypeExpression e2) {
return new BooleanTypeExpression(e1, op.getText(), e2);
}
public static BooleanListExpression createReferenceBooleanListExpression(Token var) {
- return new ReferenceBooleanListExpression(var.getText());
+ return new BooleanListVariableExpression(var.getText());
}
public static StringListExpression createReferenceStringListExpression(Token var) {
- return new ReferenceStringListExpression(var.getText());
+ return new StringListVariableExpression(var.getText());
}
public static TypeListExpression createReferenceTypeListExpression(Token var) {
- return new ReferenceTypeListExpression(var.getText());
+ return new TypeListVariableExpression(var.getText());
}
public static NumberListExpression createReferenceDoubleListExpression(Token var) {
- return new ReferenceNumberListExpression(var.getText());
+ return new NumberListVariableExpression(var.getText());
}
public static NumberListExpression createReferenceIntListExpression(Token var) {
- return new ReferenceNumberListExpression(var.getText());
+ return new NumberListVariableExpression(var.getText());
}
public static NumberListExpression createReferenceFloatListExpression(Token var) {
- return new ReferenceNumberListExpression(var.getText());
+ return new NumberListVariableExpression(var.getText());
}
public static BooleanListExpression createBooleanListExpression(List<IBooleanExpression> list) {
@@ -234,7 +239,7 @@ public class ExpressionFactory {
return new SimpleNumberListExpression(list);
}
- public static TypeListExpression createTypeListExpression(List<TypeExpression> list) {
+ public static TypeListExpression createTypeListExpression(List<ITypeExpression> list) {
return new SimpleTypeListExpression(list);
}
@@ -245,19 +250,19 @@ public class ExpressionFactory {
public static FeatureExpression createFeatureExpression(MatchReference mr, RutaBlock env) {
return new SimpleFeatureExpression(mr);
}
-
- public static FeatureMatchExpression createFeatureMatchExpression(MatchReference mr, RutaBlock env) {
- return new FeatureMatchExpression(mr, env);
- }
- public static MatchReference createMatchReference(Token refToken, Token opToken,
- IRutaExpression arg) {
- String match = refToken.getText();
- String op = null;
- if (opToken != null) {
+ public static FeatureMatchExpression createFeatureMatchExpression(MatchReference mr, Token opToken,
+ IRutaExpression arg, RutaBlock env) {
+ String op = "";
+ if(opToken != null) {
op = opToken.getText();
}
- return new MatchReference(match, op, arg);
+ return new FeatureMatchExpression(mr, op, arg, env);
+ }
+
+ public static MatchReference createMatchReference(Token refToken) {
+ String match = refToken.getText();
+ return new MatchReference(match);
}
public static INumberExpression createNumberFeatureExpression(FeatureExpression fe) {
@@ -284,7 +289,7 @@ public class ExpressionFactory {
List<IStringExpression> args) {
return new ExternalWordListExpression(name.getText(), args);
}
-
+
public static WordTableExpression createExternalWordTableExpression(Token name,
List<IStringExpression> args) {
return new ExternalWordTableExpression(name.getText(), args);
@@ -293,7 +298,31 @@ public class ExpressionFactory {
public static IRutaExpression createNullExpression() {
return new NullExpression();
}
-
+ public static IAnnotationExpression createAnnotationAddressExpression(Token address) {
+ return new AnnotationAddressExpression(address.getText());
+ }
+
+ public static IRutaExpression createAnnotationLabelExpression(Token label) {
+ return new AnnotationLabelExpression(label.getText());
+ }
+
+ public static IRutaExpression createAnnotationVariableExpression(Token var) {
+ return new AnnotationVariableExpression(var.getText());
+ }
+
+ public static IRutaExpression createAnnotationListVariableExpression(Token var) {
+ return null;
+ }
+
+ public static IAnnotationExpression createAnnotationFeatureExpression(
+ FeatureExpression featureExpression) {
+ return new AnnotationFeatureExpression(featureExpression);
+ }
+
+ public static IRutaExpression createGenericExpression(Token ref) {
+ MatchReference match = new MatchReference(ref.getText());
+ return new AnnotationTypeExpression(match);
+ }
}
Modified: uima/ruta/trunk/ruta-core/src/main/java/org/apache/uima/ruta/expression/MatchReference.java
URL: http://svn.apache.org/viewvc/uima/ruta/trunk/ruta-core/src/main/java/org/apache/uima/ruta/expression/MatchReference.java?rev=1722834&r1=1722833&r2=1722834&view=diff
==============================================================================
--- uima/ruta/trunk/ruta-core/src/main/java/org/apache/uima/ruta/expression/MatchReference.java (original)
+++ uima/ruta/trunk/ruta-core/src/main/java/org/apache/uima/ruta/expression/MatchReference.java Mon Jan 4 10:33:48 2016
@@ -24,47 +24,46 @@ import java.util.List;
import org.apache.uima.ruta.RutaBlock;
import org.apache.uima.ruta.RutaEnvironment;
-import org.apache.uima.ruta.RutaStatement;
import org.apache.uima.ruta.RutaStream;
+import org.apache.uima.ruta.expression.annotation.AnnotationLabelExpression;
+import org.apache.uima.ruta.expression.annotation.AnnotationVariableExpression;
+import org.apache.uima.ruta.expression.annotation.IAnnotationExpression;
import org.apache.uima.ruta.expression.feature.FeatureExpression;
-import org.apache.uima.ruta.expression.feature.FeatureMatchExpression;
import org.apache.uima.ruta.expression.feature.SimpleFeatureExpression;
-import org.apache.uima.ruta.expression.type.ReferenceTypeExpression;
+import org.apache.uima.ruta.expression.type.ITypeExpression;
import org.apache.uima.ruta.expression.type.SimpleTypeExpression;
-import org.apache.uima.ruta.expression.type.TypeExpression;
+import org.apache.uima.ruta.expression.type.TypeVariableExpression;
+import org.apache.uima.ruta.rule.MatchContext;
+import org.apache.uima.ruta.rule.RuleElement;
+import org.apache.uima.ruta.rule.RuleMatch;
public class MatchReference extends RutaExpression {
- private String match;
+ private String reference;
- private String op;
-
- private IRutaExpression arg;
-
- private TypeExpression typeExpression;
+ private ITypeExpression typeExpression;
+
+ private IAnnotationExpression annotationExpression;
private FeatureExpression featureExpression;
- public MatchReference(String match, String op, IRutaExpression arg) {
- super();
- this.match = match;
- this.op = op;
- this.arg = arg;
- }
-
- public MatchReference(TypeExpression expression) {
+ private boolean initialized = false;
+
+ public MatchReference(String reference) {
super();
- this.typeExpression = expression;
+ this.reference = reference;
}
- private void resolve(RutaBlock parent) {
- if (typeExpression != null) {
+ private void resolve(MatchContext context, RutaStream stream) {
+ if (initialized) {
return;
}
+ RutaBlock parent = context.getParent();
RutaEnvironment e = parent.getEnvironment();
- typeExpression = buildTypeExpression(match, e);
- if (typeExpression == null) {
- String[] elements = match.split("[.]");
+
+ boolean success = buildTypeOrAnnotationExpression(reference, e, context, stream);
+ if (!success) {
+ String[] elements = reference.split("[.]");
StringBuilder sb = new StringBuilder();
List<String> tail = null;
int counter = 0;
@@ -74,75 +73,65 @@ public class MatchReference extends Ruta
}
sb.append(eachPart);
String head = sb.toString();
- typeExpression = buildTypeExpression(head, e);
- if (typeExpression != null) {
+ success = buildTypeOrAnnotationExpression(head, e, context, stream);
+ if (success) {
tail = Arrays.asList(elements).subList(counter + 1, elements.length);
break;
}
counter++;
}
if (tail != null) {
- if (op == null) {
featureExpression = new SimpleFeatureExpression(typeExpression, tail);
- } else {
- SimpleFeatureExpression expr = new SimpleFeatureExpression(typeExpression, tail);
- featureExpression = new FeatureMatchExpression(expr, op, arg, parent);
- }
}
}
- if(typeExpression == null || typeExpression.getType(parent) == null) {
- throw new IllegalArgumentException("Not able to resolve type of expression: "+ match);
+ initialized = true;
+ if (typeExpression == null && annotationExpression == null) {
+ throw new IllegalArgumentException("Not able to resolve annotation/type expression: " + reference);
}
}
-
- private TypeExpression buildTypeExpression(String candidate, RutaEnvironment e) {
+
+ private boolean buildTypeOrAnnotationExpression(String candidate, RutaEnvironment e, MatchContext context, RutaStream stream) {
if (e.isVariableOfType(candidate, "TYPE")) {
- return new ReferenceTypeExpression(candidate);
+ typeExpression = new TypeVariableExpression(candidate);
+ return true;
+ } else if (e.isVariableOfType(candidate, "ANNOTATION")) {
+ annotationExpression = new AnnotationVariableExpression(candidate);
+ return true;
} else if (e.getType(candidate) != null) {
- return new SimpleTypeExpression(candidate);
+ typeExpression = new SimpleTypeExpression(candidate);
+ return true;
+ } else if (context.getRuleMatch() != null) {
+ RuleMatch ruleMatch = context.getRuleMatch();
+ RuleElement ruleElementWithLabel = ruleMatch.getRule().getRuleElementWithLabel(candidate);
+ if(ruleElementWithLabel != null) {
+ annotationExpression = new AnnotationLabelExpression(candidate);
+ return true;
+ }
}
- return null;
+ return false;
}
- public TypeExpression getTypeExpression(RutaBlock parent) {
- resolve(parent);
+ public ITypeExpression getTypeExpression(MatchContext context, RutaStream stream) {
+ resolve(context, stream);
return typeExpression;
}
-
- public FeatureExpression getFeatureExpression(RutaBlock parent) {
- resolve(parent);
- return featureExpression;
+
+ public IAnnotationExpression getAnnotationExpression(MatchContext context, RutaStream stream) {
+ resolve(context, stream);
+ return annotationExpression;
}
- public String getOp() {
- return op;
- }
-
- public IRutaExpression getArg() {
- return arg;
- }
-
- public RutaExpression getRawTypeExpression() {
- return typeExpression;
- }
-
- public RutaExpression getRawFeatureExpression() {
+ public FeatureExpression getFeatureExpression(MatchContext context, RutaStream stream) {
+ resolve(context, stream);
return featureExpression;
}
public String toString() {
- String tail = "";
- if (op != null) {
- tail += op;
- }
- if (arg != null) {
- tail += arg.toString();
- }
- return match + tail;
+ return reference;
}
public String getMatch() {
- return match;
+ return reference;
}
}