Author: pkluegl
Date: Tue Nov  5 15:32:43 2019
New Revision: 1869411

URL: http://svn.apache.org/viewvc?rev=1869411&view=rev
Log:
UIMA-6041: refactoring doMath() toward single rule API for later usage in 
wildcard

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/RuleElement.java
    
uima/ruta/trunk/ruta-core/src/main/java/org/apache/uima/ruta/rule/RutaOptionalRuleElement.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

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=1869411&r1=1869410&r2=1869411&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
 Tue Nov  5 15:32:43 2019
@@ -87,10 +87,10 @@ public class ComposedRuleElement extends
         List<RuleMatch> startRuleMatches = each.startMatch(extendedMatch, 
null, composedMatch, this,
                 stream, crowd);
         for (RuleMatch startRuleMatch : startRuleMatches) {
-          
+
           ComposedRuleElementMatch startElementMatch = 
(ComposedRuleElementMatch) startRuleMatch
                   .getLastMatch(this, true);
-          
+
           ruleMatches.put(startRuleMatch, startElementMatch);
         }
       }
@@ -108,12 +108,13 @@ public class ComposedRuleElement extends
         RutaRuleElement sideStepOrigin = null;
 
         anchoringRuleElement = updateAnchorForDisjunctMatch(eachComposedMatch, 
stream);
-        
+
         if (anchoringRuleElement instanceof RutaRuleElement && 
hasAncestor(false)) {
           sideStepOrigin = (RutaRuleElement) anchoringRuleElement;
         }
         List<RuleMatch> fallbackContinue = fallbackContinue(true, failed, 
lastAnnotation,
-                eachRuleMatch, ruleApply, eachComposedMatch, sideStepOrigin, 
entryPoint, stream, crowd);
+                eachRuleMatch, ruleApply, eachComposedMatch, sideStepOrigin, 
entryPoint, stream,
+                crowd);
         result.addAll(fallbackContinue);
       }
     } else if (conjunct) {
@@ -171,11 +172,12 @@ public class ComposedRuleElement extends
     return result;
   }
 
-  private RuleElement updateAnchorForDisjunctMatch(ComposedRuleElementMatch 
eachComposedMatch, RutaStream stream) {
-    
+  private RuleElement updateAnchorForDisjunctMatch(ComposedRuleElementMatch 
eachComposedMatch,
+          RutaStream stream) {
+
     Map<RuleElement, List<RuleElementMatch>> innerMatches = 
eachComposedMatch.getInnerMatches();
     RuleElement anchoringRuleElement = getAnchoringRuleElement(stream);
-    
+
     for (Entry<RuleElement, List<RuleElementMatch>> match : 
innerMatches.entrySet()) {
       if (match.getValue() != null) {
         List<RuleElementMatch> matchRuleElements = match.getValue();
@@ -441,7 +443,7 @@ public class ComposedRuleElement extends
           InferenceCrowd crowd) {
     List<RuleMatch> result = new ArrayList<RuleMatch>();
     RuleElementContainer container = getContainer();
-    doMatch(after, containerMatch, ruleMatch, stream, crowd);
+    doMatch(after, annotation, ruleMatch, containerMatch, isStartAnchor(), 
stream, crowd);
     if (this.equals(entryPoint) && ruleApply == null) {
       result.add(ruleMatch);
     } else if (container == null) {
@@ -566,21 +568,24 @@ public class ComposedRuleElement extends
     }
   }
 
-  private void doMatch(boolean after, ComposedRuleElementMatch match, 
RuleMatch ruleMatch,
-          RutaStream stream, InferenceCrowd crowd) {
-    List<AnnotationFS> textsMatched = match.getTextsMatched();
+  @Override
+  public void doMatch(boolean after, AnnotationFS annotation, RuleMatch 
ruleMatch,
+          ComposedRuleElementMatch containerMatch, boolean ruleAnchor, 
RutaStream stream,
+          InferenceCrowd crowd) {
+
+    List<AnnotationFS> textsMatched = containerMatch.getTextsMatched();
     if (textsMatched == null || textsMatched.isEmpty()) {
       getParent().getEnvironment().addMatchToVariable(ruleMatch, this,
               new MatchContext(getParent()), stream);
-      match.evaluateInnerMatches(true, stream);
+      containerMatch.evaluateInnerMatches(true, stream);
       return;
     }
     int begin = textsMatched.get(0).getBegin();
     int end = textsMatched.get(textsMatched.size() - 1).getEnd();
-    AnnotationFS annotation = 
stream.getCas().createAnnotation(stream.getCas().getAnnotationType(),
-            begin, end);
+    AnnotationFS implicitAnnotation = stream.getCas()
+            .createAnnotation(stream.getCas().getAnnotationType(), begin, end);
 
-    MatchContext context = new MatchContext(annotation, this, ruleMatch, 
after);
+    MatchContext context = new MatchContext(implicitAnnotation, this, 
ruleMatch, after);
     RutaEnvironment environment = context.getParent().getEnvironment();
     environment.addMatchToVariable(ruleMatch, this, context, stream);
 
@@ -595,11 +600,11 @@ public class ComposedRuleElement extends
         break;
       }
     }
-    match.setConditionInfo(evaluatedConditions);
-    match.evaluateInnerMatches(true, stream);
-    if (match.matched()) {
+    containerMatch.setConditionInfo(evaluatedConditions);
+    containerMatch.evaluateInnerMatches(true, stream);
+    if (containerMatch.matched()) {
       boolean inlinedRulesMatched = matchInnerRules(ruleMatch, stream, crowd);
-      match.setInlinedRulesMatched(inlinedRulesMatched);
+      containerMatch.setInlinedRulesMatched(inlinedRulesMatched);
     } else {
       // update label for failed match after evaluating conditions
       environment.removeVariableValue(getLabel(), context);

Modified: 
uima/ruta/trunk/ruta-core/src/main/java/org/apache/uima/ruta/rule/RuleElement.java
URL: 
http://svn.apache.org/viewvc/uima/ruta/trunk/ruta-core/src/main/java/org/apache/uima/ruta/rule/RuleElement.java?rev=1869411&r1=1869410&r2=1869411&view=diff
==============================================================================
--- 
uima/ruta/trunk/ruta-core/src/main/java/org/apache/uima/ruta/rule/RuleElement.java
 (original)
+++ 
uima/ruta/trunk/ruta-core/src/main/java/org/apache/uima/ruta/rule/RuleElement.java
 Tue Nov  5 15:32:43 2019
@@ -49,6 +49,10 @@ public interface RuleElement {
           RutaRuleElement sideStepOrigin, RuleElement entryPoint, RutaStream 
stream,
           InferenceCrowd crowd);
 
+  void doMatch(boolean after, AnnotationFS annotation, RuleMatch ruleMatch,
+          ComposedRuleElementMatch containerMatch, boolean ruleAnchor, 
RutaStream stream,
+          InferenceCrowd crowd);
+
   List<RuleElementMatch> evaluateMatches(List<RuleElementMatch> matches, 
MatchContext context,
           RutaStream stream);
 
@@ -85,9 +89,9 @@ public interface RuleElement {
   void setLabel(String label);
 
   String getLabel();
-  
+
   List<List<RutaStatement>> getInlinedConditionRuleBlocks();
-  
+
   List<List<RutaStatement>> getInlinedActionRuleBlocks();
 
 }

Modified: 
uima/ruta/trunk/ruta-core/src/main/java/org/apache/uima/ruta/rule/RutaOptionalRuleElement.java
URL: 
http://svn.apache.org/viewvc/uima/ruta/trunk/ruta-core/src/main/java/org/apache/uima/ruta/rule/RutaOptionalRuleElement.java?rev=1869411&r1=1869410&r2=1869411&view=diff
==============================================================================
--- 
uima/ruta/trunk/ruta-core/src/main/java/org/apache/uima/ruta/rule/RutaOptionalRuleElement.java
 (original)
+++ 
uima/ruta/trunk/ruta-core/src/main/java/org/apache/uima/ruta/rule/RutaOptionalRuleElement.java
 Tue Nov  5 15:32:43 2019
@@ -57,7 +57,7 @@ public class RutaOptionalRuleElement ext
   }
 
   @Override
-  protected void doMatch(boolean after, AnnotationFS annotation, RuleMatch 
ruleMatch,
+  public void doMatch(boolean after, AnnotationFS annotation, RuleMatch 
ruleMatch,
           ComposedRuleElementMatch containerMatch, boolean ruleAnchor, 
RutaStream stream,
           InferenceCrowd crowd) {
     RuleElementMatch result = new RuleElementMatch(this, containerMatch);

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=1869411&r1=1869410&r2=1869411&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
 Tue Nov  5 15:32:43 2019
@@ -372,7 +372,8 @@ public class RutaRuleElement extends Abs
     return result;
   }
 
-  protected void doMatch(boolean after, AnnotationFS annotation, RuleMatch 
ruleMatch,
+  @Override
+  public void doMatch(boolean after, AnnotationFS annotation, RuleMatch 
ruleMatch,
           ComposedRuleElementMatch containerMatch, boolean ruleAnchor, 
RutaStream stream,
           InferenceCrowd crowd) {
     RuleElementMatch result = new RuleElementMatch(this, containerMatch);

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=1869411&r1=1869410&r2=1869411&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
 Tue Nov  5 15:32:43 2019
@@ -101,7 +101,7 @@ public class WildCardRuleElement extends
     // what is the next stuff that should match?
     if (nextElement == null) {
       AnnotationFS afs = getCoveredByWildCard(after, annotation, null, stream);
-      doMatch(afs, ruleMatch, containerMatch, annotation == null, stream, 
crowd);
+      doMatch(after, afs, ruleMatch, containerMatch, annotation == null, 
stream, crowd);
       ComposedRuleElement composed = (ComposedRuleElement) getContainer();
       // [Peter] was ruleMatch.matched(), but it did not fail when matches?!
       result = composed.fallbackContinue(after, !ruleMatch.matched(), afs, 
ruleMatch, ruleApply,
@@ -144,8 +144,8 @@ public class WildCardRuleElement extends
       ComposedRuleElementMatch extendedContainerMatch = containerMatch.copy();
       RuleMatch extendedMatch = ruleMatch.copy(extendedContainerMatch, after);
       AnnotationFS coveredByWildCard = getCoveredByWildCard(after, annotation, 
nextOne, stream);
-      doMatch(coveredByWildCard, extendedMatch, extendedContainerMatch, 
annotation == null, stream,
-              crowd);
+      doMatch(after, coveredByWildCard, extendedMatch, extendedContainerMatch, 
annotation == null,
+              stream, crowd);
       if (extendedMatch.matched()) {
         ComposedRuleElementMatch nextContainerMatch = 
getContainerMatchOfNextElement(
                 extendedContainerMatch, nextDepth);
@@ -325,7 +325,8 @@ public class WildCardRuleElement extends
 
           AnnotationFS coveredByWildCard = getCoveredByWildCard(after, 
annotation, nextAnchor,
                   stream);
-          doMatch(coveredByWildCard, ruleMatch, containerMatch, annotation == 
null, stream, crowd);
+          doMatch(after, coveredByWildCard, ruleMatch, containerMatch, 
annotation == null, stream,
+                  crowd);
           if (ruleMatch.matched()) {
             ComposedRuleElementMatch nextContainerMatch = 
getContainerMatchOfNextElement(
                     containerMatch, nextDepth);
@@ -366,8 +367,11 @@ public class WildCardRuleElement extends
       RuleMatch extendedMatch = ruleMatch.copy(extendedContainerMatch, after);
 
       AnnotationFS coveredByWildCard = getCoveredByWildCard(after, annotation, 
nextOne, stream);
-      doMatch(coveredByWildCard, extendedMatch, extendedContainerMatch, 
annotation == null, stream,
-              crowd);
+      doMatch(after, coveredByWildCard, extendedMatch, extendedContainerMatch, 
annotation == null,
+              stream, crowd);
+
+      // TODO: UIMA-6041: also doMatch for container conditions for (A #){XYZ} 
B;
+
       if (extendedMatch.matched()) {
         ComposedRuleElementMatch nextContainerMatch = 
getContainerMatchOfNextElement(
                 extendedContainerMatch, nextDepth);
@@ -611,8 +615,8 @@ public class WildCardRuleElement extends
       ComposedRuleElementMatch extendedContainerMatch = containerMatch.copy();
       RuleMatch extendedMatch = ruleMatch.copy(extendedContainerMatch, after);
       AnnotationFS coveredByWildCard = getCoveredByWildCard(after, annotation, 
anchor, stream);
-      doMatch(coveredByWildCard, extendedMatch, extendedContainerMatch, 
annotation == null, stream,
-              crowd);
+      doMatch(after, coveredByWildCard, extendedMatch, extendedContainerMatch, 
annotation == null,
+              stream, crowd);
       if (extendedMatch.matched()) {
         ComposedRuleElementMatch nextContainerMatch = 
getContainerMatchOfNextElement(
                 extendedContainerMatch, nextDepth);
@@ -712,9 +716,11 @@ public class WildCardRuleElement extends
     return afs;
   }
 
-  private void doMatch(AnnotationFS annotation, RuleMatch ruleMatch,
+  @Override
+  public void doMatch(boolean after, AnnotationFS annotation, RuleMatch 
ruleMatch,
           ComposedRuleElementMatch containerMatch, boolean ruleAnchor, 
RutaStream stream,
           InferenceCrowd crowd) {
+
     RuleElementMatch result = new RuleElementMatch(this, containerMatch);
     result.setRuleAnchor(ruleAnchor);
     List<EvaluatedCondition> evaluatedConditions = new 
ArrayList<EvaluatedCondition>(


Reply via email to