Author: pkluegl
Date: Tue Sep 17 11:14:33 2013
New Revision: 1523985

URL: http://svn.apache.org/r1523985
Log:
UIMA-3258
- fixed and added test

Added:
    
uima/sandbox/ruta/trunk/ruta-core/src/test/java/org/apache/uima/ruta/QuantifierTest7.java
   (with props)
Modified:
    
uima/sandbox/ruta/trunk/ruta-core/src/main/java/org/apache/uima/ruta/rule/AbstractRuleElement.java
    
uima/sandbox/ruta/trunk/ruta-core/src/main/java/org/apache/uima/ruta/rule/ConjunctRulesRuleElement.java
    
uima/sandbox/ruta/trunk/ruta-core/src/main/java/org/apache/uima/ruta/rule/RuleMatch.java
    
uima/sandbox/ruta/trunk/ruta-core/src/main/java/org/apache/uima/ruta/rule/RutaRuleElement.java

Modified: 
uima/sandbox/ruta/trunk/ruta-core/src/main/java/org/apache/uima/ruta/rule/AbstractRuleElement.java
URL: 
http://svn.apache.org/viewvc/uima/sandbox/ruta/trunk/ruta-core/src/main/java/org/apache/uima/ruta/rule/AbstractRuleElement.java?rev=1523985&r1=1523984&r2=1523985&view=diff
==============================================================================
--- 
uima/sandbox/ruta/trunk/ruta-core/src/main/java/org/apache/uima/ruta/rule/AbstractRuleElement.java
 (original)
+++ 
uima/sandbox/ruta/trunk/ruta-core/src/main/java/org/apache/uima/ruta/rule/AbstractRuleElement.java
 Tue Sep 17 11:14:33 2013
@@ -24,7 +24,6 @@ import java.util.Collections;
 import java.util.List;
 
 import org.apache.uima.cas.text.AnnotationFS;
-import org.apache.uima.ruta.BlockApply;
 import org.apache.uima.ruta.RutaBlock;
 import org.apache.uima.ruta.RutaElement;
 import org.apache.uima.ruta.RutaStatement;
@@ -117,14 +116,6 @@ public abstract class AbstractRuleElemen
     return result;
   }
 
-  private RuleApply getDummyRuleApply(RuleMatch ruleMatch) {
-    List<RuleElement> list = new ArrayList<RuleElement>(1);
-    list.add(this);
-    RutaRule dummyRule = new RutaRule(list, parent, -1);
-    RuleApply result = new RuleApply(dummyRule, true);
-    return result;
-  }
-
   protected List<ScriptApply> processInlinedConditionRules(RuleMatch 
ruleMatch, RutaStream stream,
           InferenceCrowd crowd) {
     if (!inlineMode && inlinedRules != null && !inlinedRules.isEmpty()) {

Modified: 
uima/sandbox/ruta/trunk/ruta-core/src/main/java/org/apache/uima/ruta/rule/ConjunctRulesRuleElement.java
URL: 
http://svn.apache.org/viewvc/uima/sandbox/ruta/trunk/ruta-core/src/main/java/org/apache/uima/ruta/rule/ConjunctRulesRuleElement.java?rev=1523985&r1=1523984&r2=1523985&view=diff
==============================================================================
--- 
uima/sandbox/ruta/trunk/ruta-core/src/main/java/org/apache/uima/ruta/rule/ConjunctRulesRuleElement.java
 (original)
+++ 
uima/sandbox/ruta/trunk/ruta-core/src/main/java/org/apache/uima/ruta/rule/ConjunctRulesRuleElement.java
 Tue Sep 17 11:14:33 2013
@@ -21,9 +21,7 @@ package org.apache.uima.ruta.rule;
 
 import java.util.ArrayList;
 import java.util.Collection;
-import java.util.HashMap;
 import java.util.List;
-import java.util.Map;
 
 import org.apache.uima.cas.text.AnnotationFS;
 import org.apache.uima.ruta.RutaBlock;

Modified: 
uima/sandbox/ruta/trunk/ruta-core/src/main/java/org/apache/uima/ruta/rule/RuleMatch.java
URL: 
http://svn.apache.org/viewvc/uima/sandbox/ruta/trunk/ruta-core/src/main/java/org/apache/uima/ruta/rule/RuleMatch.java?rev=1523985&r1=1523984&r2=1523985&view=diff
==============================================================================
--- 
uima/sandbox/ruta/trunk/ruta-core/src/main/java/org/apache/uima/ruta/rule/RuleMatch.java
 (original)
+++ 
uima/sandbox/ruta/trunk/ruta-core/src/main/java/org/apache/uima/ruta/rule/RuleMatch.java
 Tue Sep 17 11:14:33 2013
@@ -31,7 +31,6 @@ import org.apache.uima.cas.CAS;
 import org.apache.uima.cas.text.AnnotationFS;
 import org.apache.uima.ruta.RutaElement;
 import org.apache.uima.ruta.ScriptApply;
-import org.apache.uima.ruta.action.AbstractRutaAction;
 import org.apache.uima.ruta.engine.RutaEngine;
 
 public class RuleMatch extends AbstractRuleMatch<RutaRule> {

Modified: 
uima/sandbox/ruta/trunk/ruta-core/src/main/java/org/apache/uima/ruta/rule/RutaRuleElement.java
URL: 
http://svn.apache.org/viewvc/uima/sandbox/ruta/trunk/ruta-core/src/main/java/org/apache/uima/ruta/rule/RutaRuleElement.java?rev=1523985&r1=1523984&r2=1523985&view=diff
==============================================================================
--- 
uima/sandbox/ruta/trunk/ruta-core/src/main/java/org/apache/uima/ruta/rule/RutaRuleElement.java
 (original)
+++ 
uima/sandbox/ruta/trunk/ruta-core/src/main/java/org/apache/uima/ruta/rule/RutaRuleElement.java
 Tue Sep 17 11:14:33 2013
@@ -72,19 +72,19 @@ public class RutaRuleElement extends Abs
         RutaRuleElement sideStepOrigin = hasAncestor(false) ? this : null;
         if (quantifier.continueMatch(true, eachAnchor, this, extendedMatch, 
extendedContainerMatch,
                 stream, crowd)) {
-          List<RuleMatch> continueOwnMatch = continueOwnMatch(true, 
eachAnchor, extendedMatch, ruleApply,
-                  extendedContainerMatch, sideStepOrigin, null, stream, crowd);
+          List<RuleMatch> continueOwnMatch = continueOwnMatch(true, 
eachAnchor, extendedMatch,
+                  ruleApply, extendedContainerMatch, sideStepOrigin, null, 
stream, crowd);
           result.addAll(continueOwnMatch);
         } else {
           if (after != null) {
             sideStepOrigin = hasAncestor(false) ? this : null;
-            List<RuleMatch> continueMatch = after.continueMatch(true, 
eachAnchor, extendedMatch, ruleApply,
-                    extendedContainerMatch, sideStepOrigin, entryPoint, 
stream, crowd);
+            List<RuleMatch> continueMatch = after.continueMatch(true, 
eachAnchor, extendedMatch,
+                    ruleApply, extendedContainerMatch, sideStepOrigin, 
entryPoint, stream, crowd);
             result.addAll(continueMatch);
           } else if ((stream.isDynamicAnchoring() || isStartAnchor()) && 
before != null) {
             sideStepOrigin = hasAncestor(true) ? this : null;
-            List<RuleMatch> continueMatch = before.continueMatch(false, 
eachAnchor, extendedMatch, ruleApply,
-                    extendedContainerMatch, sideStepOrigin, entryPoint, 
stream, crowd);
+            List<RuleMatch> continueMatch = before.continueMatch(false, 
eachAnchor, extendedMatch,
+                    ruleApply, extendedContainerMatch, sideStepOrigin, 
entryPoint, stream, crowd);
             result.addAll(continueMatch);
           }
 
@@ -92,9 +92,10 @@ public class RutaRuleElement extends Abs
             if (getContainer() instanceof ComposedRuleElement) {
               sideStepOrigin = hasAncestor(false) ? this : null;
               ComposedRuleElement composed = (ComposedRuleElement) 
getContainer();
-              List<RuleMatch> fallbackContinue = 
composed.fallbackContinue(true, false, eachAnchor, extendedMatch, ruleApply,
-                      extendedContainerMatch, sideStepOrigin, entryPoint, 
stream, crowd);
-result.addAll(fallbackContinue);
+              List<RuleMatch> fallbackContinue = 
composed.fallbackContinue(true, false, eachAnchor,
+                      extendedMatch, ruleApply, extendedContainerMatch, 
sideStepOrigin, entryPoint,
+                      stream, crowd);
+              result.addAll(fallbackContinue);
             } else if (getContainer() instanceof RuleElementIsolator) {
               // TODO move and refactor this:
               doneMatching(extendedMatch, ruleApply, stream, crowd);
@@ -104,8 +105,9 @@ result.addAll(fallbackContinue);
       } else {
         if (getContainer() instanceof ComposedRuleElement) {
           ComposedRuleElement composed = (ComposedRuleElement) getContainer();
-          List<RuleMatch> fallbackContinue = composed.fallbackContinue(true, 
true, eachAnchor, extendedMatch, ruleApply,
-                  extendedContainerMatch, null, entryPoint, stream, crowd);
+          List<RuleMatch> fallbackContinue = composed
+                  .fallbackContinue(true, true, eachAnchor, extendedMatch, 
ruleApply,
+                          extendedContainerMatch, null, entryPoint, stream, 
crowd);
           result.addAll(fallbackContinue);
         }
       }
@@ -142,9 +144,8 @@ result.addAll(fallbackContinue);
           eachAnchor = nextAnnotations.iterator().next();
           doMatch(eachAnchor, extendedMatch, extendedContainerMatch, false, 
stream, crowd);
           if (this.equals(entryPoint)) {
-             result.add(extendedMatch);
-          } else 
-          if (extendedMatch.matched()) {
+            result.add(extendedMatch);
+          } else if (extendedMatch.matched()) {
             if (quantifier.continueMatch(after, eachAnchor, this, 
extendedMatch,
                     extendedContainerMatch, stream, crowd)) {
               // continue in while loop
@@ -207,27 +208,41 @@ result.addAll(fallbackContinue);
         if (useAlternatives) {
           extendedContainerMatch = containerMatch.copy();
           extendedMatch = ruleMatch.copy(extendedContainerMatch);
-        } 
+        }
         doMatch(eachAnchor, extendedMatch, extendedContainerMatch, false, 
stream, crowd);
 
         if (this.equals(entryPoint) && ruleApply == null) {
           result.add(extendedMatch);
-        } else 
-        if (extendedMatch.matched()) {
+        } else if (extendedMatch.matched()) {
           if (quantifier.continueMatch(after, annotation, this, extendedMatch,
                   extendedContainerMatch, stream, crowd)) {
-             List<RuleMatch> continueOwnMatch = continueOwnMatch(after, 
eachAnchor, extendedMatch, ruleApply,
-                    extendedContainerMatch, sideStepOrigin, entryPoint, 
stream, crowd);
-             result.addAll(continueOwnMatch);
+            List<RuleMatch> continueOwnMatch = continueOwnMatch(after, 
eachAnchor, extendedMatch,
+                    ruleApply, extendedContainerMatch, sideStepOrigin, 
entryPoint, stream, crowd);
+            result.addAll(continueOwnMatch);
           } else {
-             List<RuleMatch> continueMatchSomewhereElse = 
continueMatchSomewhereElse(after, false, eachAnchor, extendedMatch, ruleApply,
-                    extendedContainerMatch, sideStepOrigin, entryPoint, 
stream, crowd);
-             result.addAll(continueMatchSomewhereElse);
+            List<RuleMatch> continueMatchSomewhereElse = 
continueMatchSomewhereElse(after, false,
+                    eachAnchor, extendedMatch, ruleApply, 
extendedContainerMatch, sideStepOrigin,
+                    entryPoint, stream, crowd);
+            result.addAll(continueMatchSomewhereElse);
           }
         } else {
-           List<RuleMatch> stepbackMatch = stepbackMatch(after, annotation, 
extendedMatch, ruleApply,
-                  extendedContainerMatch, sideStepOrigin, stream, crowd, 
entryPoint);
-           result.addAll(stepbackMatch);
+          // was:
+          // List<RuleMatch> stepbackMatch = stepbackMatch(after, annotation, 
extendedMatch,
+          // ruleApply,
+          // extendedContainerMatch, sideStepOrigin, stream, crowd, 
entryPoint);
+          if (getContainer() instanceof ComposedRuleElement) {
+            ComposedRuleElement composed = (ComposedRuleElement) 
getContainer();
+            List<RuleMatch> fallbackContinue = 
composed.fallbackContinue(after, true, eachAnchor,
+                    extendedMatch, ruleApply, extendedContainerMatch, 
sideStepOrigin, entryPoint,
+                    stream, crowd);
+            result.addAll(fallbackContinue);
+          } else {
+            // should never happen...
+            List<RuleMatch> stepbackMatch = stepbackMatch(after, annotation, 
ruleMatch, ruleApply,
+                    containerMatch, sideStepOrigin, stream, crowd, entryPoint);
+            result.addAll(stepbackMatch);
+          }
+
         }
       }
     } else {
@@ -348,15 +363,13 @@ result.addAll(fallbackContinue);
     ruleMatch.setMatched(ruleMatch.matched() && result.matched());
   }
 
-  
-
   @Override
   public String toString() {
     String simpleName = getQuantifier().getClass().getSimpleName();
     return matcher.toString() + " " + (simpleName.equals("NormalQuantifier") ? 
"" : simpleName)
-//            + (conditions.isEmpty() ? "" : "(" + conditions.toString() + ")" 
+ "\\n")
-//            + (actions.isEmpty() ? "" : "{" + actions.toString() + "}")
-            ;
+    // + (conditions.isEmpty() ? "" : "(" + conditions.toString() + ")" + 
"\\n")
+    // + (actions.isEmpty() ? "" : "{" + actions.toString() + "}")
+    ;
   }
 
   public RutaMatcher getMatcher() {

Added: 
uima/sandbox/ruta/trunk/ruta-core/src/test/java/org/apache/uima/ruta/QuantifierTest7.java
URL: 
http://svn.apache.org/viewvc/uima/sandbox/ruta/trunk/ruta-core/src/test/java/org/apache/uima/ruta/QuantifierTest7.java?rev=1523985&view=auto
==============================================================================
--- 
uima/sandbox/ruta/trunk/ruta-core/src/test/java/org/apache/uima/ruta/QuantifierTest7.java
 (added)
+++ 
uima/sandbox/ruta/trunk/ruta-core/src/test/java/org/apache/uima/ruta/QuantifierTest7.java
 Tue Sep 17 11:14:33 2013
@@ -0,0 +1,64 @@
+/*
+ * 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.junit.Test;
+
+public class QuantifierTest7 {
+  @Test
+  public void test() {
+    String document = "n 1 2 3, H 1 2 3, i 1 2 3, i 1 2 3, i 1 2 3, n 1 2 3, n 
1 2 3";
+    String script = "\"H\" -> T1;\n";
+    script += "\"i\" -> T2;\n";
+    script += "COMMA {-> T3};\n";
+    script += "COMMA #{-> T5} COMMA;\n";
+    script += "T5 { CONTAINS(T1)} (T5 { CONTAINS(T2) } T3?)* { -> MARK(T4, 1, 
2) };\n";
+    
+    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, 4);
+    ai = cas.getAnnotationIndex(t);
+    assertEquals(1, ai.size());
+    iterator = ai.iterator();
+    assertEquals("H 1 2 3, i 1 2 3, i 1 2 3, i 1 2 3,", 
iterator.next().getCoveredText());
+    
+    if(cas != null) {
+      cas.release();
+    }
+  }
+}

Propchange: 
uima/sandbox/ruta/trunk/ruta-core/src/test/java/org/apache/uima/ruta/QuantifierTest7.java
------------------------------------------------------------------------------
    svn:eol-style = native


Reply via email to