Author: pkluegl
Date: Wed Oct 21 16:18:05 2015
New Revision: 1709876

URL: http://svn.apache.org/viewvc?rev=1709876&view=rev
Log:
UIMA-4560
- check on optional rule element on failed wildcard lookahead

Modified:
    
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/WildCard2Test.java

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=1709876&r1=1709875&r2=1709876&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 Oct 21 16:18:05 2015
@@ -297,10 +297,34 @@ public class WildCardRuleElement extends
       RuleElementContainer c = getContainer();
       if (c instanceof ComposedRuleElement) {
         ComposedRuleElement cre = (ComposedRuleElement) c;
-        cre.fallbackContinue(after, true, annotation, ruleMatch, ruleApply, 
containerMatch,
-                sideStepOrigin, entryPoint, stream, crowd);
+
+        if (nextElement.getQuantifier().isOptional(parent, stream)) {
+          // optional did not match -> match complete window/document
+          // TODO refactor
+
+          AnnotationFS coveredByWildCard = getCoveredByWildCard(after, 
annotation, null, stream);
+          doMatch(coveredByWildCard, ruleMatch, containerMatch, annotation == 
null, stream, crowd);
+          if (ruleMatch.matched()) {
+            ComposedRuleElementMatch nextContainerMatch = 
getContainerMatchOfNextElement(
+                    containerMatch, nextDepth);
+            if (coveredByWildCard == null) {
+              result = nextElement.startMatch(ruleMatch, ruleApply, 
nextContainerMatch,
+                      nextElement, stream, crowd);
+            } else {
+              // TODO match and containermatch should be on the correct level!
+              result = nextElement.continueMatch(after, coveredByWildCard, 
ruleMatch, ruleApply,
+                      nextContainerMatch, sideStepOrigin, nextElement, stream, 
crowd);
+            }
+          } else {
+            result = cre.fallbackContinue(after, true, annotation, ruleMatch, 
ruleApply,
+                    containerMatch, sideStepOrigin, entryPoint, stream, crowd);
+          }
+        } else {
+
+          result = cre.fallbackContinue(after, true, annotation, ruleMatch, 
ruleApply,
+                  containerMatch, sideStepOrigin, entryPoint, stream, crowd);
+        }
       }
-      result.add(ruleMatch);
       return result;
     }
     if (iterator.isValid() && !stream.isVisible(iterator.get())) {
@@ -390,7 +414,7 @@ public class WildCardRuleElement extends
         result = cas.getAnnotationIndex(type).iterator(pointer);
         if (!result.isValid()) {
           if (after) {
-            //result.moveToFirst();
+            // result.moveToFirst();
           } else {
             // HOTFIX caused by type priorities
             result.moveToLast();
@@ -433,7 +457,7 @@ public class WildCardRuleElement extends
         result.moveTo(pointer);
         if (!result.isValid()) {
           if (after) {
-//            result.moveToFirst();
+            // result.moveToFirst();
           } else {
             // TODO due to type priorities: RutaBasic is last -> moveTo will 
not work
             result.moveToLast();

Modified: 
uima/ruta/trunk/ruta-core/src/test/java/org/apache/uima/ruta/WildCard2Test.java
URL: 
http://svn.apache.org/viewvc/uima/ruta/trunk/ruta-core/src/test/java/org/apache/uima/ruta/WildCard2Test.java?rev=1709876&r1=1709875&r2=1709876&view=diff
==============================================================================
--- 
uima/ruta/trunk/ruta-core/src/test/java/org/apache/uima/ruta/WildCard2Test.java 
(original)
+++ 
uima/ruta/trunk/ruta-core/src/test/java/org/apache/uima/ruta/WildCard2Test.java 
Wed Oct 21 16:18:05 2015
@@ -59,4 +59,24 @@ public class WildCard2Test {
 
     cas.release();
   }
+  
+  
+  @Test
+  public void testOptional() {
+    String document = "Cw 1 2 3";
+    String script = "(CW #){-> T1} SW?;";
+
+    CAS cas = null;
+    try {
+      cas = RutaTestUtils.getCAS(document);
+      Ruta.apply(cas, script);
+    } catch (Exception e) {
+      e.printStackTrace();
+    }
+
+    RutaTestUtils.assertAnnotationsEquals(cas, 1, 1, "Cw 1 2 3");
+
+    cas.release();
+  }
+  
 }


Reply via email to