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/12/06 13:30:12 UTC
svn commit: r1772891 - in
/uima/ruta/trunk/ruta-core/src/main/java/org/apache/uima/ruta:
block/ForEachBlock.java rule/RuleElementCaretaker.java
rule/RutaAnnotationMatcher.java rule/RutaTypeMatcher.java
Author: pkluegl
Date: Tue Dec 6 13:30:12 2016
New Revision: 1772891
URL: http://svn.apache.org/viewvc?rev=1772891&view=rev
Log:
UIMA-5169
- fixed getAnchorRuleElement
- avoid some TreeSets
Modified:
uima/ruta/trunk/ruta-core/src/main/java/org/apache/uima/ruta/block/ForEachBlock.java
uima/ruta/trunk/ruta-core/src/main/java/org/apache/uima/ruta/rule/RuleElementCaretaker.java
uima/ruta/trunk/ruta-core/src/main/java/org/apache/uima/ruta/rule/RutaAnnotationMatcher.java
uima/ruta/trunk/ruta-core/src/main/java/org/apache/uima/ruta/rule/RutaTypeMatcher.java
Modified: uima/ruta/trunk/ruta-core/src/main/java/org/apache/uima/ruta/block/ForEachBlock.java
URL: http://svn.apache.org/viewvc/uima/ruta/trunk/ruta-core/src/main/java/org/apache/uima/ruta/block/ForEachBlock.java?rev=1772891&r1=1772890&r2=1772891&view=diff
==============================================================================
--- uima/ruta/trunk/ruta-core/src/main/java/org/apache/uima/ruta/block/ForEachBlock.java (original)
+++ uima/ruta/trunk/ruta-core/src/main/java/org/apache/uima/ruta/block/ForEachBlock.java Tue Dec 6 13:30:12 2016
@@ -48,9 +48,9 @@ public class ForEachBlock extends RutaBl
private boolean anchorsSet = false;
private IBooleanExpression direction;
-
- public ForEachBlock(String varName, IBooleanExpression direction, RutaRule rule, List<RutaStatement> elements, RutaBlock parent,
- String defaultNamespace) {
+
+ public ForEachBlock(String varName, IBooleanExpression direction, RutaRule rule,
+ List<RutaStatement> elements, RutaBlock parent, String defaultNamespace) {
super(varName, rule, elements, parent, defaultNamespace,
parent != null ? parent.getContext() : null);
this.direction = direction;
@@ -64,13 +64,13 @@ public class ForEachBlock extends RutaBl
setRuleElementAnchor();
boolean leftToRight = true;
- if(direction != null) {
+ if (direction != null) {
leftToRight = direction.getBooleanValue(new MatchContext(getParent()), stream);
}
-
+
RuleApply apply = rule.apply(stream, crowd, true);
List<AbstractRuleMatch<? extends AbstractRule>> list = apply.getList();
- if(!leftToRight) {
+ if (!leftToRight) {
Collections.reverse(list);
}
for (AbstractRuleMatch<? extends AbstractRule> eachMatch : list) {
@@ -125,7 +125,7 @@ public class ForEachBlock extends RutaBl
&& matcher.getExpression() instanceof AnnotationVariableExpression) {
AnnotationVariableExpression expr = (AnnotationVariableExpression) matcher.getExpression();
boolean equals = StringUtils.equals(name, expr.getVar());
- if(equals) {
+ if (equals) {
ruleElement.setStartAnchor(equals);
}
return equals;
@@ -134,7 +134,7 @@ public class ForEachBlock extends RutaBl
List<RuleElement> ruleElements = ((ComposedRuleElement) ruleElement).getRuleElements();
for (RuleElement eachInnerRuleElement : ruleElements) {
boolean set = setRuleElementAnchorRecursively(eachInnerRuleElement);
- if(set) {
+ if (set) {
return set;
}
}
Modified: uima/ruta/trunk/ruta-core/src/main/java/org/apache/uima/ruta/rule/RuleElementCaretaker.java
URL: http://svn.apache.org/viewvc/uima/ruta/trunk/ruta-core/src/main/java/org/apache/uima/ruta/rule/RuleElementCaretaker.java?rev=1772891&r1=1772890&r2=1772891&view=diff
==============================================================================
--- uima/ruta/trunk/ruta-core/src/main/java/org/apache/uima/ruta/rule/RuleElementCaretaker.java (original)
+++ uima/ruta/trunk/ruta-core/src/main/java/org/apache/uima/ruta/rule/RuleElementCaretaker.java Tue Dec 6 13:30:12 2016
@@ -69,6 +69,12 @@ public class RuleElementCaretaker implem
for (RuleElement ruleElement : ruleElements) {
if (ruleElement.isStartAnchor()) {
return ruleElement;
+ }
+ if(ruleElement instanceof ComposedRuleElement) {
+ RuleElement anchoringRuleElement = ((ComposedRuleElement) ruleElement).getAnchoringRuleElement(stream);
+ if(anchoringRuleElement.isStartAnchor()) {
+ return ruleElement;
+ }
}
}
Modified: uima/ruta/trunk/ruta-core/src/main/java/org/apache/uima/ruta/rule/RutaAnnotationMatcher.java
URL: http://svn.apache.org/viewvc/uima/ruta/trunk/ruta-core/src/main/java/org/apache/uima/ruta/rule/RutaAnnotationMatcher.java?rev=1772891&r1=1772890&r2=1772891&view=diff
==============================================================================
--- uima/ruta/trunk/ruta-core/src/main/java/org/apache/uima/ruta/rule/RutaAnnotationMatcher.java (original)
+++ uima/ruta/trunk/ruta-core/src/main/java/org/apache/uima/ruta/rule/RutaAnnotationMatcher.java Tue Dec 6 13:30:12 2016
@@ -23,7 +23,6 @@ import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.List;
-import java.util.TreeSet;
import org.apache.uima.cas.Type;
import org.apache.uima.cas.text.AnnotationFS;
@@ -36,8 +35,6 @@ import org.apache.uima.ruta.type.RutaBas
public class RutaAnnotationMatcher implements RutaMatcher {
- protected AnnotationComparator comparator;
-
private IAnnotationExpression annotationExpression;
private IAnnotationListExpression annotationListExpression;
@@ -45,13 +42,11 @@ public class RutaAnnotationMatcher imple
public RutaAnnotationMatcher(IAnnotationExpression expression) {
super();
this.annotationExpression = expression;
- this.comparator = new AnnotationComparator();
}
public RutaAnnotationMatcher(IAnnotationListExpression expression) {
super();
this.annotationListExpression = expression;
- this.comparator = new AnnotationComparator();
}
@Override
@@ -59,12 +54,11 @@ public class RutaAnnotationMatcher imple
// TODO what about the matching direction?
MatchContext context = new MatchContext(parent);
if (annotationExpression != null) {
- Collection<AnnotationFS> annotations = new TreeSet<AnnotationFS>(comparator);
AnnotationFS annotation = annotationExpression.getAnnotation(context, stream);
- if (annotation != null) {
- annotations.add(annotation);
+ if (annotation == null) {
+ return Collections.emptyList();
}
- return annotations;
+ return Collections.singletonList(annotation);
} else if (annotationListExpression != null) {
return annotationListExpression.getAnnotationList(context, stream);
}
Modified: uima/ruta/trunk/ruta-core/src/main/java/org/apache/uima/ruta/rule/RutaTypeMatcher.java
URL: http://svn.apache.org/viewvc/uima/ruta/trunk/ruta-core/src/main/java/org/apache/uima/ruta/rule/RutaTypeMatcher.java?rev=1772891&r1=1772890&r2=1772891&view=diff
==============================================================================
--- uima/ruta/trunk/ruta-core/src/main/java/org/apache/uima/ruta/rule/RutaTypeMatcher.java (original)
+++ uima/ruta/trunk/ruta-core/src/main/java/org/apache/uima/ruta/rule/RutaTypeMatcher.java Tue Dec 6 13:30:12 2016
@@ -23,7 +23,6 @@ import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.List;
-import java.util.TreeSet;
import org.apache.uima.cas.Type;
import org.apache.uima.cas.text.AnnotationFS;
@@ -42,24 +41,20 @@ public class RutaTypeMatcher implements
private FeatureExpression featureExpression;
- protected AnnotationComparator comparator;
-
public RutaTypeMatcher(FeatureExpression expression) {
super();
this.featureExpression = expression;
- this.comparator = new AnnotationComparator();
}
public RutaTypeMatcher(ITypeExpression expression) {
super();
this.typeExpression = expression;
- this.comparator = new AnnotationComparator();
}
@Override
public Collection<? extends AnnotationFS> getMatchingAnnotations(RutaBlock parent, RutaStream stream) {
// TODO what about the matching direction?
- Collection<AnnotationFS> annotations = new TreeSet<AnnotationFS>(comparator);
+ Collection<AnnotationFS> annotations = new ArrayList<>();
List<Type> types = getTypes(parent, stream);
for (Type type : types) {
if (type == null) {
@@ -121,7 +116,7 @@ public class RutaTypeMatcher implements
}
}
List<Type> reTypes = getTypes(parent, stream);
- Collection<AnnotationFS> anchors = new TreeSet<AnnotationFS>(comparator);
+ Collection<AnnotationFS> anchors = new ArrayList<>();
for (Type eachMatchType : reTypes) {
Collection<AnnotationFS> beginAnchors = nextBasic.getBeginAnchors(eachMatchType);
if (beginAnchors != null) {
@@ -169,7 +164,7 @@ public class RutaTypeMatcher implements
}
}
List<Type> reTypes = getTypes(parent, stream);
- Collection<AnnotationFS> anchors = new TreeSet<AnnotationFS>(comparator);
+ Collection<AnnotationFS> anchors = new ArrayList<>();
for (Type eachMatchType : reTypes) {
Collection<AnnotationFS> endAnchors = nextBasic.getEndAnchors(eachMatchType);
if (endAnchors != null) {