Author: pkluegl
Date: Tue Aug 18 17:12:40 2015
New Revision: 1696461

URL: http://svn.apache.org/r1696461
Log:
UIMA-4559
- added test
- adapted some rule inference checks for failed composed rule elements and wild 
cards

Modified:
    uima/ruta/trunk/ruta-core/src/main/java/org/apache/uima/ruta/RutaStream.java
    
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/RutaRuleElement.java
    
uima/ruta/trunk/ruta-core/src/main/java/org/apache/uima/ruta/rule/WildCardRuleElement.java
    
uima/ruta/trunk/ruta-core/src/test/java/org/apache/uima/ruta/ComposedRuleElementWithQuantifierTest.java

Modified: 
uima/ruta/trunk/ruta-core/src/main/java/org/apache/uima/ruta/RutaStream.java
URL: 
http://svn.apache.org/viewvc/uima/ruta/trunk/ruta-core/src/main/java/org/apache/uima/ruta/RutaStream.java?rev=1696461&r1=1696460&r2=1696461&view=diff
==============================================================================
--- 
uima/ruta/trunk/ruta-core/src/main/java/org/apache/uima/ruta/RutaStream.java 
(original)
+++ 
uima/ruta/trunk/ruta-core/src/main/java/org/apache/uima/ruta/RutaStream.java 
Tue Aug 18 17:12:40 2015
@@ -402,7 +402,7 @@ public class RutaStream extends FSIterat
     try {
       currentIt.moveTo(fs);
     } catch (Exception e) {
-      e.printStackTrace();
+//      e.printStackTrace();
     }
   }
 
@@ -467,7 +467,7 @@ public class RutaStream extends FSIterat
     try {
       return cas.getJCas();
     } catch (CASException e) {
-      e.printStackTrace();
+//      e.printStackTrace();
     }
     return null;
   }

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=1696461&r1=1696460&r2=1696461&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 Aug 18 17:12:40 2015
@@ -450,8 +450,13 @@ public class ComposedRuleElement extends
             // hotfix for UIMA-3820
             result.add(ruleMatch);
           } else {
-            result = fallback(after, failed, annotation, ruleMatch, ruleApply,
+            // TODO: do we need to backtrack the annotation?
+            result = fallback(after, !removedFailedMatches, annotation, 
ruleMatch, ruleApply,
                     parentContainerMatch, sideStepOrigin, entryPoint, stream, 
crowd);
+            // was:
+            // [Peter]: really failed, even if the failed match was removed?
+            // result = fallback(after, failed, annotation, ruleMatch, 
ruleApply,
+            // parentContainerMatch, sideStepOrigin, entryPoint, stream, 
crowd);
           }
         }
       } else {

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=1696461&r1=1696460&r2=1696461&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 Aug 18 17:12:40 2015
@@ -271,17 +271,21 @@ public class RutaRuleElement extends Abs
                 containerMatch, sideStepOrigin, entryPoint, stream, crowd);
       } else if (getContainer() instanceof ComposedRuleElement) {
         ComposedRuleElement cre = (ComposedRuleElement) getContainer();
-        if (cre.getQuantifier().isOptional(parent, stream)) {
-          result = continueMatchSomewhereElse(after, true, annotation, 
ruleMatch, ruleApply,
-                  containerMatch, sideStepOrigin, entryPoint, stream, crowd);
-        } else {
-          RuleElementMatch failedMatch = new RuleElementMatch(this, 
containerMatch);
-          failedMatch.setBaseConditionMatched(false);
-          containerMatch.addInnerMatch(this, failedMatch, stream);
-          ComposedRuleElement composed = (ComposedRuleElement) getContainer();
-          result = composed.fallbackContinue(after, true, annotation, 
ruleMatch, ruleApply,
-                  containerMatch, sideStepOrigin, entryPoint, stream, crowd);
-        }
+        result = cre.fallbackContinue(after, true, annotation, ruleMatch, 
ruleApply, containerMatch, sideStepOrigin, entryPoint, stream, crowd);
+        // was:
+        // [Peter] why only check the parent? the grandparent could be 
optional!
+        // should we add the second part again for the explanation component?
+        // if (cre.getQuantifier().isOptional(parent, stream)) {
+        // result = continueMatchSomewhereElse(after, true, annotation, 
ruleMatch, ruleApply,
+        // containerMatch, sideStepOrigin, entryPoint, stream, crowd);
+        // } else {
+        // RuleElementMatch failedMatch = new RuleElementMatch(this, 
containerMatch);
+        // failedMatch.setBaseConditionMatched(false);
+        // containerMatch.addInnerMatch(this, failedMatch, stream);
+        // ComposedRuleElement composed = (ComposedRuleElement) getContainer();
+        // result = composed.fallbackContinue(after, true, annotation, 
ruleMatch, ruleApply,
+        // containerMatch, sideStepOrigin, entryPoint, stream, crowd);
+        // }
       }
     } else {
       List<RuleElementMatch> evaluateMatches = 
quantifier.evaluateMatches(matchInfo, parent,

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=1696461&r1=1696460&r2=1696461&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 Aug 18 17:12:40 2015
@@ -90,7 +90,8 @@ public class WildCardRuleElement extends
       AnnotationFS afs = getCoveredByWildCard(after, annotation, null, stream);
       doMatch(afs, ruleMatch, containerMatch, annotation == null, stream, 
crowd);
       ComposedRuleElement composed = (ComposedRuleElement) getContainer();
-      result = composed.fallbackContinue(after, ruleMatch.matched(), afs, 
ruleMatch, ruleApply,
+      // [Peter] was ruleMatch.matched(), but it did not fail when matches?!
+      result = composed.fallbackContinue(after, !ruleMatch.matched(), afs, 
ruleMatch, ruleApply,
               containerMatch, sideStepOrigin, entryPoint, stream, crowd);
     } else if (nextElement instanceof RutaRuleElement) {
       RutaRuleElement re = (RutaRuleElement) nextElement;

Modified: 
uima/ruta/trunk/ruta-core/src/test/java/org/apache/uima/ruta/ComposedRuleElementWithQuantifierTest.java
URL: 
http://svn.apache.org/viewvc/uima/ruta/trunk/ruta-core/src/test/java/org/apache/uima/ruta/ComposedRuleElementWithQuantifierTest.java?rev=1696461&r1=1696460&r2=1696461&view=diff
==============================================================================
--- 
uima/ruta/trunk/ruta-core/src/test/java/org/apache/uima/ruta/ComposedRuleElementWithQuantifierTest.java
 (original)
+++ 
uima/ruta/trunk/ruta-core/src/test/java/org/apache/uima/ruta/ComposedRuleElementWithQuantifierTest.java
 Tue Aug 18 17:12:40 2015
@@ -44,4 +44,34 @@ public class ComposedRuleElementWithQuan
 
     cas.release();
   }
+  
+  @Test
+  public void testStackedWithWildCard() {
+    String document = "some text\n 1 HEADLINE\n some text";
+    String script = "";
+    
+    script +="\"1 HEADLINE\"-> T1;\n";
+    script +="DOUBLE n;\n";
+    script +="BLOCK(eachTag) T1{} {\n";
+    script +="((NUM{STARTSWITH(T1)} (PERIOD NUM)?){PARSE(n)} (W #){-> T2})\n";
+    script +=" {-> T3};\n";
+    script +="}\n";
+    
+    CAS cas = null;
+    try {
+      cas = RutaTestUtils.getCAS(document);
+      Ruta.apply(cas, script);
+    } catch (Exception e) {
+      e.printStackTrace();
+    }
+
+    RutaTestUtils.assertAnnotationsEquals(cas, 2, 1, "HEADLINE");
+    RutaTestUtils.assertAnnotationsEquals(cas, 3, 1, "1 HEADLINE");
+
+    cas.release();
+    
+  }
+  
+  
+  
 }


Reply via email to