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 2019/11/12 16:31:58 UTC

svn commit: r1869706 - in /uima/ruta/trunk/ruta-core/src: main/java/org/apache/uima/ruta/rule/WildCardRuleElement.java test/java/org/apache/uima/ruta/rule/WildCard2Test.java

Author: pkluegl
Date: Tue Nov 12 16:31:58 2019
New Revision: 1869706

URL: http://svn.apache.org/viewvc?rev=1869706&view=rev
Log:
UIMA-6041: doMatch() also for parent elements according to depth to next element

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/rule/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=1869706&r1=1869705&r2=1869706&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 12 16:31:58 2019
@@ -145,6 +145,8 @@ public class WildCardRuleElement extends
       AnnotationFS coveredByWildCard = getCoveredByWildCard(after, annotation, nextOne, stream);
       doMatch(after, coveredByWildCard, extendedMatch, extendedContainerMatch, annotation == null,
               stream, crowd);
+      doMatchPotentialParentElements(after, annotation, nextDepth, extendedMatch,
+              extendedContainerMatch, coveredByWildCard, stream, crowd);
       if (extendedMatch.matched()) {
         ComposedRuleElementMatch nextContainerMatch = getContainerMatchOfNextElement(
                 extendedContainerMatch, nextDepth);
@@ -369,7 +371,8 @@ public class WildCardRuleElement extends
       doMatch(after, coveredByWildCard, extendedMatch, extendedContainerMatch, annotation == null,
               stream, crowd);
 
-      // TODO: UIMA-6041: also doMatch for container conditions for (A #){XYZ} B;
+      doMatchPotentialParentElements(after, annotation, nextDepth, extendedMatch,
+              extendedContainerMatch, coveredByWildCard, stream, crowd);
 
       if (extendedMatch.matched()) {
         ComposedRuleElementMatch nextContainerMatch = getContainerMatchOfNextElement(
@@ -399,6 +402,22 @@ public class WildCardRuleElement extends
     return result;
   }
 
+  private void doMatchPotentialParentElements(boolean after, AnnotationFS annotation, int nextDepth,
+          RuleMatch extendedMatch, ComposedRuleElementMatch extendedContainerMatch,
+          AnnotationFS coveredByWildCard, RutaStream stream, InferenceCrowd crowd) {
+    RuleElement element = this;
+    for (int i = nextDepth; i > 0; i--) {
+      // UIMA-6041: also doMatch for container conditions like (A #){XYZ} B;
+      RuleElementContainer c = element.getContainer();
+      if (c instanceof ComposedRuleElement) {
+        ComposedRuleElement cre = (ComposedRuleElement) c;
+        cre.doMatch(after, coveredByWildCard, extendedMatch,
+                extendedContainerMatch.getContainerMatch(), annotation == null, stream, crowd);
+        element = cre;
+      }
+    }
+  }
+
   private AnnotationFS getNextAnchor(boolean after, AnnotationFS annotation,
           RuleElement nextElement, RuleMatch ruleMatch, ComposedRuleElementMatch containerMatch,
           RuleElement sideStepOrigin, RutaStream stream, InferenceCrowd crowd) {
@@ -616,6 +635,8 @@ public class WildCardRuleElement extends
       AnnotationFS coveredByWildCard = getCoveredByWildCard(after, annotation, anchor, stream);
       doMatch(after, coveredByWildCard, extendedMatch, extendedContainerMatch, annotation == null,
               stream, crowd);
+      doMatchPotentialParentElements(after, annotation, nextDepth, extendedMatch,
+              extendedContainerMatch, coveredByWildCard, stream, crowd);
       if (extendedMatch.matched()) {
         ComposedRuleElementMatch nextContainerMatch = getContainerMatchOfNextElement(
                 extendedContainerMatch, nextDepth);

Modified: uima/ruta/trunk/ruta-core/src/test/java/org/apache/uima/ruta/rule/WildCard2Test.java
URL: http://svn.apache.org/viewvc/uima/ruta/trunk/ruta-core/src/test/java/org/apache/uima/ruta/rule/WildCard2Test.java?rev=1869706&r1=1869705&r2=1869706&view=diff
==============================================================================
--- uima/ruta/trunk/ruta-core/src/test/java/org/apache/uima/ruta/rule/WildCard2Test.java (original)
+++ uima/ruta/trunk/ruta-core/src/test/java/org/apache/uima/ruta/rule/WildCard2Test.java Tue Nov 12 16:31:58 2019
@@ -29,7 +29,6 @@ import org.apache.uima.ruta.engine.Ruta;
 import org.apache.uima.ruta.engine.RutaTestUtils;
 import org.apache.uima.ruta.engine.RutaTestUtils.TestFeature;
 import org.junit.Assert;
-import org.junit.Ignore;
 import org.junit.Test;
 
 public class WildCard2Test {
@@ -196,15 +195,26 @@ public class WildCard2Test {
   }
 
   @Test
-  @Ignore
   public void testConditionAtComposedWithWildcard() throws Exception {
-    String document = "1 a b c 2 d e f 3";
+    String document = "1 A a , 2 D d . 3";
     String script = "(NUM #){CONTAINS(CAP)->T1} NUM;";
+    script += "((NUM #){CONTAINS(COMMA)}){CONTAINS(PERIOD)-> T2} NUM;";
+    script += "((NUM #){CONTAINS(SW)}){CONTAINS(PERIOD)-> T3} NUM;";
+    script += "(NUM #){CONTAINS(CAP)->T4} (NUM);";
+    script += "((NUM #){CONTAINS(CAP)->T5}) ((NUM));";
+    script += "((NUM #){CONTAINS(CAP)->T6}) \"2\";";
+    script += "((NUM #){CONTAINS(CAP)->T7}) \"3\";";
 
     CAS cas = RutaTestUtils.getCAS(document);
     Ruta.apply(cas, script);
 
     RutaTestUtils.assertAnnotationsEquals(cas, 1, 0);
+    RutaTestUtils.assertAnnotationsEquals(cas, 2, 0);
+    RutaTestUtils.assertAnnotationsEquals(cas, 3, 1, "2 D d .");
+    RutaTestUtils.assertAnnotationsEquals(cas, 4, 0);
+    RutaTestUtils.assertAnnotationsEquals(cas, 5, 0);
+    RutaTestUtils.assertAnnotationsEquals(cas, 6, 0);
+    RutaTestUtils.assertAnnotationsEquals(cas, 7, 0);
   }
 
   @Test