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 2014/05/21 12:32:42 UTC
svn commit: r1596532 - in /uima/ruta/trunk/ruta-core/src:
main/java/org/apache/uima/ruta/rule/
main/java/org/apache/uima/ruta/rule/quantifier/
test/java/org/apache/uima/ruta/
Author: pkluegl
Date: Wed May 21 10:32:42 2014
New Revision: 1596532
URL: http://svn.apache.org/r1596532
Log:
UIMA-3820
- fixed several bugs for inner mark in greedy iteration
- added hotfix for failed match in greedy iteration in a wildcard lookahead -> should not revolve to successful match, but should end the lookahead
- added tests, one still fails (right to left matching)
Added:
uima/ruta/trunk/ruta-core/src/test/java/org/apache/uima/ruta/MarkInGreedyComposedTest.java (with props)
Modified:
uima/ruta/trunk/ruta-core/src/main/java/org/apache/uima/ruta/rule/ComposedRuleElement.java
uima/ruta/trunk/ruta-core/src/main/java/org/apache/uima/ruta/rule/ComposedRuleElementMatch.java
uima/ruta/trunk/ruta-core/src/main/java/org/apache/uima/ruta/rule/RuleMatch.java
uima/ruta/trunk/ruta-core/src/main/java/org/apache/uima/ruta/rule/RutaRuleElement.java
uima/ruta/trunk/ruta-core/src/main/java/org/apache/uima/ruta/rule/WildCardRuleElement.java
uima/ruta/trunk/ruta-core/src/main/java/org/apache/uima/ruta/rule/quantifier/MinMaxReluctant.java
uima/ruta/trunk/ruta-core/src/main/java/org/apache/uima/ruta/rule/quantifier/PlusReluctant.java
uima/ruta/trunk/ruta-core/src/main/java/org/apache/uima/ruta/rule/quantifier/QuestionReluctant.java
uima/ruta/trunk/ruta-core/src/main/java/org/apache/uima/ruta/rule/quantifier/StarReluctant.java
Modified: uima/ruta/trunk/ruta-core/src/main/java/org/apache/uima/ruta/rule/ComposedRuleElement.java
URL: http://svn.apache.org/viewvc/uima/ruta/trunk/ruta-core/src/main/java/org/apache/uima/ruta/rule/ComposedRuleElement.java?rev=1596532&r1=1596531&r2=1596532&view=diff
==============================================================================
--- uima/ruta/trunk/ruta-core/src/main/java/org/apache/uima/ruta/rule/ComposedRuleElement.java (original)
+++ uima/ruta/trunk/ruta-core/src/main/java/org/apache/uima/ruta/rule/ComposedRuleElement.java Wed May 21 10:32:42 2014
@@ -77,7 +77,7 @@ public class ComposedRuleElement extends
Map<RuleMatch, ComposedRuleElementMatch> ruleMatches = new HashMap<RuleMatch, ComposedRuleElementMatch>();
for (RuleElement each : elements) {
ComposedRuleElementMatch extendedContainerMatch = containerMatch.copy();
- RuleMatch extendedMatch = ruleMatch.copy(extendedContainerMatch);
+ RuleMatch extendedMatch = ruleMatch.copy(extendedContainerMatch, true);
ComposedRuleElementMatch composedMatch = createComposedMatch(extendedMatch,
extendedContainerMatch, stream);
List<RuleMatch> startRuleMatches = each.startMatch(extendedMatch, null, composedMatch,
@@ -185,7 +185,7 @@ public class ComposedRuleElement extends
Map<RuleMatch, ComposedRuleElementMatch> ruleMatches = new HashMap<RuleMatch, ComposedRuleElementMatch>();
for (RuleElement each : elements) {
ComposedRuleElementMatch extendedContainerMatch = containerMatch.copy();
- RuleMatch extendedMatch = ruleMatch.copy(extendedContainerMatch);
+ RuleMatch extendedMatch = ruleMatch.copy(extendedContainerMatch, after);
ComposedRuleElementMatch composedMatch = createComposedMatch(extendedMatch,
extendedContainerMatch, stream);
List<RuleMatch> continueRuleMatches = each.continueMatch(after, annotation, extendedMatch,
@@ -218,7 +218,7 @@ public class ComposedRuleElement extends
Map<RuleMatch, ComposedRuleElementMatch> ruleMatches = new HashMap<RuleMatch, ComposedRuleElementMatch>();
for (RuleElement each : elements) {
ComposedRuleElementMatch extendedContainerMatch = containerMatch.copy();
- RuleMatch extendedMatch = ruleMatch.copy(extendedContainerMatch);
+ RuleMatch extendedMatch = ruleMatch.copy(extendedContainerMatch, after);
ComposedRuleElementMatch composedMatch = createComposedMatch(extendedMatch,
extendedContainerMatch, stream);
List<RuleMatch> continueRuleMatches = each.continueMatch(after, annotation, extendedMatch,
@@ -412,8 +412,13 @@ public class ComposedRuleElement extends
parentContainerMatch, sideStepOrigin, entryPoint, stream, crowd);
}
} else {
- result = fallback(after, failed, annotation, ruleMatch, ruleApply, parentContainerMatch,
- sideStepOrigin, entryPoint, stream, crowd);
+ if (this.equals(entryPoint)) {
+ // hotfix for UIMA-3820
+ result.add(ruleMatch);
+ } else {
+ result = fallback(after, failed, annotation, ruleMatch, ruleApply, parentContainerMatch,
+ sideStepOrigin, entryPoint, stream, crowd);
+ }
}
} else {
if (continueMatch) {
Modified: uima/ruta/trunk/ruta-core/src/main/java/org/apache/uima/ruta/rule/ComposedRuleElementMatch.java
URL: http://svn.apache.org/viewvc/uima/ruta/trunk/ruta-core/src/main/java/org/apache/uima/ruta/rule/ComposedRuleElementMatch.java?rev=1596532&r1=1596531&r2=1596532&view=diff
==============================================================================
--- uima/ruta/trunk/ruta-core/src/main/java/org/apache/uima/ruta/rule/ComposedRuleElementMatch.java (original)
+++ uima/ruta/trunk/ruta-core/src/main/java/org/apache/uima/ruta/rule/ComposedRuleElementMatch.java Wed May 21 10:32:42 2014
@@ -52,11 +52,11 @@ public class ComposedRuleElementMatch ex
protected void enforceUpdate() {
textsMatchedUpdated = false;
ComposedRuleElementMatch cm = getContainerMatch();
- if(cm != null) {
+ if (cm != null) {
cm.enforceUpdate();
}
}
-
+
private void setInnerMatches(Map<RuleElement, List<RuleElementMatch>> innerMatches) {
this.innerMatches = innerMatches;
enforceUpdate();
@@ -131,7 +131,8 @@ public class ComposedRuleElementMatch ex
return copy;
}
- public ComposedRuleElementMatch copy(ComposedRuleElementMatch extendedContainerMatch) {
+ public ComposedRuleElementMatch copy(ComposedRuleElementMatch extendedContainerMatch,
+ boolean after) {
ComposedRuleElementMatch copy = new ComposedRuleElementMatch((ComposedRuleElement) ruleElement,
containerMatch);
copy.setBaseConditionMatched(baseConditionMatched);
@@ -164,10 +165,62 @@ public class ComposedRuleElementMatch ex
for (RuleElementMatch each : value) {
each.setContainerMatch(copy);
if (each instanceof ComposedRuleElementMatch) {
- newValue.add(((ComposedRuleElementMatch) each).copy(extendedContainerMatch));
+ newValue.add(((ComposedRuleElementMatch) each).copy(extendedContainerMatch, after));
+ } else {
+ newValue.add(each.copy());
+ }
+ }
+ newMap.put(entry.getKey(), newValue);
+ } else {
+ newMap.put(entry.getKey(), null);
+ }
+ }
+ }
+ copy.setInnerMatches(newMap);
+ return copy;
+ }
+
+ public ComposedRuleElementMatch copy2(ComposedRuleElementMatch extendedContainerMatch,
+ boolean after) {
+ ComposedRuleElementMatch copy = new ComposedRuleElementMatch((ComposedRuleElement) ruleElement,
+ containerMatch);
+ copy.setBaseConditionMatched(baseConditionMatched);
+ copy.setConditions(conditions);
+ copy.setConditionsMatched(conditionsMatched);
+ copy.setTextsMatched(textsMatched);
+ Map<RuleElement, List<RuleElementMatch>> newMap = new TreeMap<RuleElement, List<RuleElementMatch>>(
+ new RuleElementComparator((ComposedRuleElement) ruleElement));
+ for (Entry<RuleElement, List<RuleElementMatch>> entry : innerMatches.entrySet()) {
+ RuleElement key = entry.getKey();
+ List<RuleElementMatch> value = entry.getValue();
+ if (key.equals(extendedContainerMatch.getRuleElement())) {
+ extendedContainerMatch.setContainerMatch(copy);
+ if (value != null) {
+ List<RuleElementMatch> newValue = new ArrayList<RuleElementMatch>();
+ newValue.addAll(value);
+ newValue.set(newValue.size() - 1, extendedContainerMatch);
+ newMap.put(extendedContainerMatch.getRuleElement(), newValue);
+ }
+ } else {
+ if (value != null && !value.isEmpty()) {
+ List<RuleElementMatch> newValue = new ArrayList<RuleElementMatch>();
+ int counter = 0;
+ for (RuleElementMatch each : value) {
+ each.setContainerMatch(copy);
+ // really need to copy all?
+ boolean isCurrentOne = false;
+ if (after && counter == value.size() - 1) {
+ isCurrentOne = true;
+ }
+ if (!after && counter == 0) {
+ isCurrentOne = true;
+ }
+ if (each instanceof ComposedRuleElementMatch && isCurrentOne) {
+ newValue.add(((ComposedRuleElementMatch) each).copy2(extendedContainerMatch, after));
} else {
newValue.add(each.copy());
}
+ counter++;
}
newMap.put(entry.getKey(), newValue);
} else {
Modified: uima/ruta/trunk/ruta-core/src/main/java/org/apache/uima/ruta/rule/RuleMatch.java
URL: http://svn.apache.org/viewvc/uima/ruta/trunk/ruta-core/src/main/java/org/apache/uima/ruta/rule/RuleMatch.java?rev=1596532&r1=1596531&r2=1596532&view=diff
==============================================================================
--- uima/ruta/trunk/ruta-core/src/main/java/org/apache/uima/ruta/rule/RuleMatch.java (original)
+++ uima/ruta/trunk/ruta-core/src/main/java/org/apache/uima/ruta/rule/RuleMatch.java Wed May 21 10:32:42 2014
@@ -57,8 +57,6 @@ public class RuleMatch extends AbstractR
public RuleMatch(RutaRule rule) {
super(rule);
- // map = new TreeMap<RuleElement, List<RuleElementMatch>>(
- // new RuleElementComparator(rule.getRoot()));
delegateApply = new HashMap<RutaElement, ScriptApply>(0);
}
@@ -252,13 +250,13 @@ public class RuleMatch extends AbstractR
this.matched = matched;
}
- public RuleMatch copy(ComposedRuleElementMatch extendedContainerMatch) {
+ public RuleMatch copy(ComposedRuleElementMatch extendedContainerMatch, boolean after) {
RuleMatch copy = new RuleMatch(rule);
copy.setMatched(matched);
if (extendedContainerMatch.getContainerMatch() == null) {
copy.setRootMatch(extendedContainerMatch);
} else {
- copy.setRootMatch(rootMatch.copy(extendedContainerMatch));
+ copy.setRootMatch(rootMatch.copy2(extendedContainerMatch, after));
}
Map<RutaElement, ScriptApply> newDelegateApply = new HashMap<RutaElement, ScriptApply>(
Modified: uima/ruta/trunk/ruta-core/src/main/java/org/apache/uima/ruta/rule/RutaRuleElement.java
URL: http://svn.apache.org/viewvc/uima/ruta/trunk/ruta-core/src/main/java/org/apache/uima/ruta/rule/RutaRuleElement.java?rev=1596532&r1=1596531&r2=1596532&view=diff
==============================================================================
--- uima/ruta/trunk/ruta-core/src/main/java/org/apache/uima/ruta/rule/RutaRuleElement.java (original)
+++ uima/ruta/trunk/ruta-core/src/main/java/org/apache/uima/ruta/rule/RutaRuleElement.java Wed May 21 10:32:42 2014
@@ -66,7 +66,7 @@ public class RutaRuleElement extends Abs
RuleMatch extendedMatch = ruleMatch;
if (useAlternatives) {
extendedContainerMatch = containerMatch.copy();
- extendedMatch = ruleMatch.copy(extendedContainerMatch);
+ extendedMatch = ruleMatch.copy(extendedContainerMatch, true);
}
doMatch(eachAnchor, extendedMatch, extendedContainerMatch, true, stream, crowd);
if (this.equals(entryPoint) && ruleApply == null) {
@@ -234,7 +234,7 @@ public class RutaRuleElement extends Abs
RuleMatch extendedMatch = ruleMatch;
if (useAlternatives) {
extendedContainerMatch = containerMatch.copy();
- extendedMatch = ruleMatch.copy(extendedContainerMatch);
+ extendedMatch = ruleMatch.copy(extendedContainerMatch, after);
}
doMatch(eachAnchor, extendedMatch, extendedContainerMatch, false, stream, crowd);
@@ -253,9 +253,14 @@ public class RutaRuleElement extends Abs
result.addAll(continueMatchSomewhereElse);
}
} else {
- List<RuleMatch> stepbackMatch = stepbackMatch(after, annotation, ruleMatch, ruleApply,
- containerMatch, sideStepOrigin, stream, crowd, entryPoint);
- result.addAll(stepbackMatch);
+ if (this.equals(entryPoint)) {
+ // hotfix for UIMA-3820
+ result.add(extendedMatch);
+ } else {
+ List<RuleMatch> stepbackMatch = stepbackMatch(after, annotation, ruleMatch, ruleApply,
+ containerMatch, sideStepOrigin, stream, crowd, entryPoint);
+ result.addAll(stepbackMatch);
+ }
}
}
} else {
@@ -376,7 +381,7 @@ public class RutaRuleElement extends Abs
if (featureExpression != null) {
base = matcher.match(annotation, stream, getParent());
}
- }
+ }
List<AnnotationFS> textsMatched = new ArrayList<AnnotationFS>(1);
if (base) {
for (AbstractRutaCondition condition : conditions) {
Modified: uima/ruta/trunk/ruta-core/src/main/java/org/apache/uima/ruta/rule/WildCardRuleElement.java
URL: http://svn.apache.org/viewvc/uima/ruta/trunk/ruta-core/src/main/java/org/apache/uima/ruta/rule/WildCardRuleElement.java?rev=1596532&r1=1596531&r2=1596532&view=diff
==============================================================================
--- uima/ruta/trunk/ruta-core/src/main/java/org/apache/uima/ruta/rule/WildCardRuleElement.java (original)
+++ uima/ruta/trunk/ruta-core/src/main/java/org/apache/uima/ruta/rule/WildCardRuleElement.java Wed May 21 10:32:42 2014
@@ -26,9 +26,7 @@ import java.util.List;
import org.apache.uima.cas.CAS;
import org.apache.uima.cas.CASException;
-import org.apache.uima.cas.ConstraintFactory;
import org.apache.uima.cas.FSIterator;
-import org.apache.uima.cas.FSTypeConstraint;
import org.apache.uima.cas.Type;
import org.apache.uima.cas.text.AnnotationFS;
import org.apache.uima.jcas.JCas;
@@ -99,11 +97,11 @@ public class WildCardRuleElement extends
RutaMatcher matcher = re.getMatcher();
if (matcher instanceof RutaTypeMatcher) {
result = tryWithNextType(after, annotation, nextElement, null, ruleMatch, ruleApply,
- containerMatch, nextDepth, sideStepOrigin, stream, crowd);
+ containerMatch, nextDepth, sideStepOrigin, entryPoint, stream, crowd);
} else if (matcher instanceof RutaLiteralMatcher) {
result = tryWithNextLiteral(after, annotation, re, ruleMatch, ruleApply, containerMatch,
nextDepth, sideStepOrigin, stream, crowd);
- }
+ }
} else if (nextElement instanceof ComposedRuleElement) {
ComposedRuleElement cre = ((ComposedRuleElement) nextElement);
@@ -113,7 +111,7 @@ public class WildCardRuleElement extends
// another wildcard? seriously? then just assume its an "Annotation" type
CAS cas = stream.getCas();
result = tryWithNextType(after, annotation, nextElement, cas.getAnnotationType(), ruleMatch,
- ruleApply, containerMatch, nextDepth, sideStepOrigin, stream, crowd);
+ ruleApply, containerMatch, nextDepth, sideStepOrigin, entryPoint, stream, crowd);
}
return result;
}
@@ -126,9 +124,12 @@ public class WildCardRuleElement extends
AnnotationFS nextOne = annotation;
boolean doneHere = false;
while (!doneHere && (nextOne = getNextPositionForComposed(cre, after, nextOne, stream)) != null) {
- RutaBasic endAnchor = stream.getEndAnchor(nextOne.getBegin());
+// RutaBasic endAnchor = stream.getEndAnchor(nextOne.getBegin());
+// RutaBasic anchor = stream.getAnchor(!after, nextOne);
+ int pointer = after ? nextOne.getBegin() : nextOne.getEnd();
+ RutaBasic anchor = stream.getAnchor(!after, pointer);
ComposedRuleElementMatch extendedContainerMatch = containerMatch.copy();
- RuleMatch extendedMatch = ruleMatch.copy(extendedContainerMatch);
+ RuleMatch extendedMatch = ruleMatch.copy(extendedContainerMatch, after);
AnnotationFS coveredByWildCard = getCoveredByWildCard(after, annotation, nextOne, stream);
doMatch(coveredByWildCard, extendedMatch, extendedContainerMatch, annotation == null, stream,
@@ -138,10 +139,10 @@ public class WildCardRuleElement extends
extendedContainerMatch, nextDepth);
// Hotfix for UIMA-3002
int applied = ruleApply.getApplied();
- if (endAnchor == null) {
+ if (anchor == null) {
result = cre.startMatch(extendedMatch, ruleApply, nextContainerMatch, cre, stream, crowd);
} else {
- result = cre.continueMatch(after, endAnchor, extendedMatch, ruleApply,
+ result = cre.continueMatch(after, anchor, extendedMatch, ruleApply,
nextContainerMatch, sideStepOrigin, cre, stream, crowd);
}
List<RuleElementMatch> nextList = nextContainerMatch.getInnerMatches().get(cre);
@@ -193,26 +194,33 @@ public class WildCardRuleElement extends
} else {
return stream.getAnchor(after, annotation.getBegin());
}
- } else if(conjunct != null && !conjunct){
+ } else if (conjunct != null && !conjunct) {
// disjunctive
List<RuleElement> ruleElements = cre.getRuleElements();
List<AnnotationFS> nextPostions = new ArrayList<AnnotationFS>();
for (RuleElement ruleElement : ruleElements) {
- if(ruleElement instanceof ComposedRuleElement) {
- AnnotationFS nextPositionForComposed = getNextPositionForComposed((ComposedRuleElement) ruleElement, after, annotation, stream);
- if(nextPositionForComposed != null) {
+ if (ruleElement instanceof ComposedRuleElement) {
+ AnnotationFS nextPositionForComposed = getNextPositionForComposed(
+ (ComposedRuleElement) ruleElement, after, annotation, stream);
+ if (nextPositionForComposed != null) {
nextPostions.add(nextPositionForComposed);
}
- } else if(ruleElement instanceof RutaRuleElement) {
- AnnotationFS nextPositionForAtomic = getNextPositionForAtomic(after, annotation, stream, ruleElement, result);
- if(nextPositionForAtomic != null) {
+ } else if (ruleElement instanceof RutaRuleElement) {
+ AnnotationFS nextPositionForAtomic = getNextPositionForAtomic(after, annotation, stream,
+ ruleElement, result);
+ if (nextPositionForAtomic != null) {
nextPostions.add(nextPositionForAtomic);
}
}
}
- if(!nextPostions.isEmpty()) {
+ if (!nextPostions.isEmpty()) {
+
Collections.sort(nextPostions, new AnnotationComparator());
- result = nextPostions.get(0);
+ if (after) {
+ result = nextPostions.get(0);
+ } else {
+ result = nextPostions.get(nextPostions.size() - 1);
+ }
}
} else {
result = getNextPositionForAtomic(after, annotation, stream, element, result);
@@ -230,6 +238,16 @@ public class WildCardRuleElement extends
// moveOn(after, iterator);
if (iterator.isValid()) {
result = iterator.get();
+ if (annotation != null && (after && result.getEnd() == annotation.getEnd())
+ || (!after && result.getBegin() == annotation.getBegin())) {
+ moveOn(after, iterator);
+ if (iterator.isValid()) {
+ result = iterator.get();
+ } else {
+ result = null;
+ }
+ }
+
}
} else if (matcher instanceof RutaLiteralMatcher) {
RutaLiteralMatcher lm = (RutaLiteralMatcher) matcher;
@@ -270,17 +288,30 @@ public class WildCardRuleElement extends
private List<RuleMatch> tryWithNextType(boolean after, AnnotationFS annotation,
RuleElement nextElement, Type defaultType, RuleMatch ruleMatch, RuleApply ruleApply,
ComposedRuleElementMatch containerMatch, int nextDepth, RutaRuleElement sideStepOrigin,
- RutaStream stream, InferenceCrowd crowd) {
+ RuleElement entryPoint, RutaStream stream, InferenceCrowd crowd) {
List<RuleMatch> result = new ArrayList<RuleMatch>();
FSIterator<AnnotationFS> iterator = getIterator(after, annotation, nextElement, defaultType,
stream);
+ // already matched something maybe, but now at the end of the document
+ if (!iterator.isValid()) {
+ RuleElementContainer c = getContainer();
+ if (c instanceof ComposedRuleElement) {
+ ComposedRuleElement cre = (ComposedRuleElement) c;
+ cre.fallbackContinue(after, true, annotation, ruleMatch, ruleApply, containerMatch,
+ sideStepOrigin, entryPoint, stream, crowd);
+ }
+ result.add(ruleMatch);
+ return result;
+ }
+
boolean doneHere = false;
while (!doneHere && iterator.isValid() && stream.isVisible(iterator.get())) {
AnnotationFS nextOne = iterator.get();
- int pointer = after? nextOne.getBegin() : nextOne.getEnd();
+ int pointer = after ? nextOne.getBegin() : nextOne.getEnd();
RutaBasic anchor = stream.getAnchor(!after, pointer);
+
ComposedRuleElementMatch extendedContainerMatch = containerMatch.copy();
- RuleMatch extendedMatch = ruleMatch.copy(extendedContainerMatch);
+ RuleMatch extendedMatch = ruleMatch.copy(extendedContainerMatch, after);
AnnotationFS coveredByWildCard = getCoveredByWildCard(after, annotation, nextOne, stream);
doMatch(coveredByWildCard, extendedMatch, extendedContainerMatch, annotation == null, stream,
@@ -413,7 +444,7 @@ public class WildCardRuleElement extends
RutaBasic anchor = stream.getAnchor(after, indexOf + delta);
RutaBasic endAnchor = stream.getAnchor(!after, indexOf + delta);
ComposedRuleElementMatch extendedContainerMatch = containerMatch.copy();
- RuleMatch extendedMatch = ruleMatch.copy(extendedContainerMatch);
+ RuleMatch extendedMatch = ruleMatch.copy(extendedContainerMatch, after);
AnnotationFS coveredByWildCard = getCoveredByWildCard(after, annotation, anchor, stream);
doMatch(coveredByWildCard, extendedMatch, extendedContainerMatch, annotation == null, stream,
crowd);
@@ -531,8 +562,6 @@ public class WildCardRuleElement extends
}
result.setMatchInfo(base, textsMatched, evaluatedConditions, stream);
ruleMatch.setMatched(ruleMatch.matched() && result.matched());
- List<RuleElementMatch> rems = new ArrayList<RuleElementMatch>();
- rems.add(result);
}
public List<RuleMatch> continueOwnMatch(boolean after, AnnotationFS annotation,
Modified: uima/ruta/trunk/ruta-core/src/main/java/org/apache/uima/ruta/rule/quantifier/MinMaxReluctant.java
URL: http://svn.apache.org/viewvc/uima/ruta/trunk/ruta-core/src/main/java/org/apache/uima/ruta/rule/quantifier/MinMaxReluctant.java?rev=1596532&r1=1596531&r2=1596532&view=diff
==============================================================================
--- uima/ruta/trunk/ruta-core/src/main/java/org/apache/uima/ruta/rule/quantifier/MinMaxReluctant.java (original)
+++ uima/ruta/trunk/ruta-core/src/main/java/org/apache/uima/ruta/rule/quantifier/MinMaxReluctant.java Wed May 21 10:32:42 2014
@@ -113,7 +113,7 @@ public class MinMaxReluctant implements
return false;
}
ComposedRuleElementMatch extendedContainerMatch = containerMatch.copy();
- RuleMatch extendedMatch = ruleMatch.copy(extendedContainerMatch);
+ RuleMatch extendedMatch = ruleMatch.copy(extendedContainerMatch, after);
nextElement.continueMatch(after, annotation, extendedMatch, null, extendedContainerMatch, null,
nextElement, stream, crowd);
List<RuleElementMatch> nextList = extendedContainerMatch.getInnerMatches().get(nextElement);
Modified: uima/ruta/trunk/ruta-core/src/main/java/org/apache/uima/ruta/rule/quantifier/PlusReluctant.java
URL: http://svn.apache.org/viewvc/uima/ruta/trunk/ruta-core/src/main/java/org/apache/uima/ruta/rule/quantifier/PlusReluctant.java?rev=1596532&r1=1596531&r2=1596532&view=diff
==============================================================================
--- uima/ruta/trunk/ruta-core/src/main/java/org/apache/uima/ruta/rule/quantifier/PlusReluctant.java (original)
+++ uima/ruta/trunk/ruta-core/src/main/java/org/apache/uima/ruta/rule/quantifier/PlusReluctant.java Wed May 21 10:32:42 2014
@@ -72,7 +72,7 @@ public class PlusReluctant implements Ru
return false;
}
ComposedRuleElementMatch extendedContainerMatch = containerMatch.copy();
- RuleMatch extendedMatch = ruleMatch.copy(extendedContainerMatch);
+ RuleMatch extendedMatch = ruleMatch.copy(extendedContainerMatch, after);
nextElement.continueMatch(after, annotation, extendedMatch, null, extendedContainerMatch, null,
nextElement, stream, crowd);
List<RuleElementMatch> nextList = extendedContainerMatch.getInnerMatches().get(nextElement);
Modified: uima/ruta/trunk/ruta-core/src/main/java/org/apache/uima/ruta/rule/quantifier/QuestionReluctant.java
URL: http://svn.apache.org/viewvc/uima/ruta/trunk/ruta-core/src/main/java/org/apache/uima/ruta/rule/quantifier/QuestionReluctant.java?rev=1596532&r1=1596531&r2=1596532&view=diff
==============================================================================
--- uima/ruta/trunk/ruta-core/src/main/java/org/apache/uima/ruta/rule/quantifier/QuestionReluctant.java (original)
+++ uima/ruta/trunk/ruta-core/src/main/java/org/apache/uima/ruta/rule/quantifier/QuestionReluctant.java Wed May 21 10:32:42 2014
@@ -66,7 +66,7 @@ public class QuestionReluctant implement
return false;
}
ComposedRuleElementMatch extendedContainerMatch = containerMatch.copy();
- RuleMatch extendedMatch = ruleMatch.copy(extendedContainerMatch);
+ RuleMatch extendedMatch = ruleMatch.copy(extendedContainerMatch, after);
nextElement.continueMatch(after, annotation, extendedMatch, null, extendedContainerMatch, null,
nextElement, stream, crowd);
List<RuleElementMatch> nextList = extendedContainerMatch.getInnerMatches().get(nextElement);
Modified: uima/ruta/trunk/ruta-core/src/main/java/org/apache/uima/ruta/rule/quantifier/StarReluctant.java
URL: http://svn.apache.org/viewvc/uima/ruta/trunk/ruta-core/src/main/java/org/apache/uima/ruta/rule/quantifier/StarReluctant.java?rev=1596532&r1=1596531&r2=1596532&view=diff
==============================================================================
--- uima/ruta/trunk/ruta-core/src/main/java/org/apache/uima/ruta/rule/quantifier/StarReluctant.java (original)
+++ uima/ruta/trunk/ruta-core/src/main/java/org/apache/uima/ruta/rule/quantifier/StarReluctant.java Wed May 21 10:32:42 2014
@@ -49,7 +49,7 @@ public class StarReluctant implements Ru
return false;
}
ComposedRuleElementMatch extendedContainerMatch = containerMatch.copy();
- RuleMatch extendedMatch = ruleMatch.copy(extendedContainerMatch);
+ RuleMatch extendedMatch = ruleMatch.copy(extendedContainerMatch, after);
nextElement.continueMatch(after, annotation, extendedMatch, null, extendedContainerMatch, null,
nextElement, stream, crowd);
List<RuleElementMatch> nextList = extendedContainerMatch.getInnerMatches().get(nextElement);
Added: uima/ruta/trunk/ruta-core/src/test/java/org/apache/uima/ruta/MarkInGreedyComposedTest.java
URL: http://svn.apache.org/viewvc/uima/ruta/trunk/ruta-core/src/test/java/org/apache/uima/ruta/MarkInGreedyComposedTest.java?rev=1596532&view=auto
==============================================================================
--- uima/ruta/trunk/ruta-core/src/test/java/org/apache/uima/ruta/MarkInGreedyComposedTest.java (added)
+++ uima/ruta/trunk/ruta-core/src/test/java/org/apache/uima/ruta/MarkInGreedyComposedTest.java Wed May 21 10:32:42 2014
@@ -0,0 +1,201 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.uima.ruta;
+
+import static org.junit.Assert.assertEquals;
+
+import org.apache.uima.cas.CAS;
+import org.apache.uima.cas.FSIterator;
+import org.apache.uima.cas.Type;
+import org.apache.uima.cas.text.AnnotationFS;
+import org.apache.uima.cas.text.AnnotationIndex;
+import org.apache.uima.ruta.engine.Ruta;
+import org.apache.uima.ruta.engine.RutaTestUtils;
+import org.junit.Test;
+
+public class MarkInGreedyComposedTest {
+
+
+ @Test
+ public void testWildCardFollowedByComposedReversed() {
+ String document = "1 x f B e d B x c A b a A 1";
+ String script = "";
+ script += "( ( (SW{REGEXP(\"x\")} SW ) #) {-> T1} )+ @NUM;";
+ CAS cas = null;
+ try {
+ cas = RutaTestUtils.getCAS(document);
+ Ruta.apply(cas, script);
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+
+ Type t = null;
+ AnnotationIndex<AnnotationFS> ai = null;
+ FSIterator<AnnotationFS> iterator = null;
+
+ t = RutaTestUtils.getTestType(cas, 1);
+ ai = cas.getAnnotationIndex(t);
+ iterator = ai.iterator();
+// for (AnnotationFS a : ai) {
+// System.out.println(a.getCoveredText());
+// }
+ assertEquals(2, ai.size());
+ assertEquals("x f B e d B", iterator.next().getCoveredText());
+ assertEquals("x c A b a A", iterator.next().getCoveredText());
+
+ if (cas != null) {
+ cas.release();
+ }
+ }
+
+ @Test
+ public void testWildCardFollowedByComposed() {
+ String document = "A c b A c x A c b A c x";
+ String script = "";
+ script += "( ( # (SW SW{REGEXP(\"x\")}) ) {-> T1} )+;";
+ CAS cas = null;
+ try {
+ cas = RutaTestUtils.getCAS(document);
+ Ruta.apply(cas, script);
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+
+ Type t = null;
+ AnnotationIndex<AnnotationFS> ai = null;
+ FSIterator<AnnotationFS> iterator = null;
+
+ t = RutaTestUtils.getTestType(cas, 1);
+ ai = cas.getAnnotationIndex(t);
+ iterator = ai.iterator();
+ assertEquals(2, ai.size());
+ assertEquals("A c b A c x", iterator.next().getCoveredText());
+ assertEquals("A c b A c x", iterator.next().getCoveredText());
+
+ if (cas != null) {
+ cas.release();
+ }
+ }
+
+
+
+
+
+ @Test
+ public void testWildCardFollowedByCondition() {
+ String document = "A A b A c X X b X c";
+ String script = "";
+ script += "((# SW{REGEXP(\"c\")}){-> T1})+; ";
+ script += "((# SW{REGEXP(\"c\")}){-> MARKONCE(T2)})+; ";
+ CAS cas = null;
+ try {
+ cas = RutaTestUtils.getCAS(document);
+ Ruta.apply(cas, script);
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+
+ Type t = null;
+ AnnotationIndex<AnnotationFS> ai = null;
+ FSIterator<AnnotationFS> iterator = null;
+
+ t = RutaTestUtils.getTestType(cas, 1);
+ ai = cas.getAnnotationIndex(t);
+ iterator = ai.iterator();
+ assertEquals(2, ai.size());
+ assertEquals("A A b A c", iterator.next().getCoveredText());
+ assertEquals("X X b X c", iterator.next().getCoveredText());
+
+ t = RutaTestUtils.getTestType(cas, 2);
+ ai = cas.getAnnotationIndex(t);
+ iterator = ai.iterator();
+ assertEquals(2, ai.size());
+ assertEquals("A A b A c", iterator.next().getCoveredText());
+ assertEquals("X X b X c", iterator.next().getCoveredText());
+
+ if (cas != null) {
+ cas.release();
+ }
+
+ }
+
+ @Test
+ public void testWithWildCard() {
+ String document = "1 . 2 .";
+ String script = "";
+ script += "((# PERIOD){-> T1})+; ";
+ CAS cas = null;
+ try {
+ cas = RutaTestUtils.getCAS(document);
+ Ruta.apply(cas, script);
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+
+ Type t = null;
+ AnnotationIndex<AnnotationFS> ai = null;
+ FSIterator<AnnotationFS> iterator = null;
+
+ t = RutaTestUtils.getTestType(cas, 1);
+ ai = cas.getAnnotationIndex(t);
+ iterator = ai.iterator();
+ assertEquals(2, ai.size());
+ assertEquals("1 .", iterator.next().getCoveredText());
+ assertEquals("2 .", iterator.next().getCoveredText());
+
+ if (cas != null) {
+ cas.release();
+ }
+
+ }
+
+ @Test
+ public void test() {
+ String document = "1 . 2 .";
+ String script = "";
+ script += "((NUM PERIOD){-> MARKONCE(T1)})+; ";
+ CAS cas = null;
+ try {
+ cas = RutaTestUtils.getCAS(document);
+ Ruta.apply(cas, script);
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+
+ Type t = null;
+ AnnotationIndex<AnnotationFS> ai = null;
+ FSIterator<AnnotationFS> iterator = null;
+
+ t = RutaTestUtils.getTestType(cas, 1);
+ ai = cas.getAnnotationIndex(t);
+ iterator = ai.iterator();
+ assertEquals(2, ai.size());
+ assertEquals("1 .", iterator.next().getCoveredText());
+ assertEquals("2 .", iterator.next().getCoveredText());
+
+ if (cas != null) {
+ cas.release();
+ }
+
+ }
+
+
+
+}
Propchange: uima/ruta/trunk/ruta-core/src/test/java/org/apache/uima/ruta/MarkInGreedyComposedTest.java
------------------------------------------------------------------------------
svn:eol-style = native