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 2013/11/06 12:56:59 UTC

svn commit: r1539320 - in /uima/sandbox/ruta/trunk/ruta-core/src: main/java/org/apache/uima/ruta/rule/ComposedRuleElement.java main/java/org/apache/uima/ruta/rule/RuleElementCaretaker.java test/java/org/apache/uima/ruta/ManualAnchoringTest.java

Author: pkluegl
Date: Wed Nov  6 11:56:59 2013
New Revision: 1539320

URL: http://svn.apache.org/r1539320
Log:
UIMA-3408
- fixed backtracked annotation in reverse matching direction
- fixed retrieval of inner rule element in reverse matching direction
- added test

Added:
    uima/sandbox/ruta/trunk/ruta-core/src/test/java/org/apache/uima/ruta/ManualAnchoringTest.java   (with props)
Modified:
    uima/sandbox/ruta/trunk/ruta-core/src/main/java/org/apache/uima/ruta/rule/ComposedRuleElement.java
    uima/sandbox/ruta/trunk/ruta-core/src/main/java/org/apache/uima/ruta/rule/RuleElementCaretaker.java

Modified: uima/sandbox/ruta/trunk/ruta-core/src/main/java/org/apache/uima/ruta/rule/ComposedRuleElement.java
URL: http://svn.apache.org/viewvc/uima/sandbox/ruta/trunk/ruta-core/src/main/java/org/apache/uima/ruta/rule/ComposedRuleElement.java?rev=1539320&r1=1539319&r2=1539320&view=diff
==============================================================================
--- uima/sandbox/ruta/trunk/ruta-core/src/main/java/org/apache/uima/ruta/rule/ComposedRuleElement.java (original)
+++ uima/sandbox/ruta/trunk/ruta-core/src/main/java/org/apache/uima/ruta/rule/ComposedRuleElement.java Wed Nov  6 11:56:59 2013
@@ -395,7 +395,8 @@ public class ComposedRuleElement extends
           result = continueOwnMatch(after, annotation, ruleMatch, ruleApply, parentContainerMatch,
                   sideStepOrigin, null, stream, crowd);
         } else if (nextElement != null) {
-          AnnotationFS backtrackedAnnotation = getBacktrackedAnnotation(evaluateMatches, annotation);
+          AnnotationFS backtrackedAnnotation = getBacktrackedAnnotation(after, evaluateMatches,
+                  annotation);
           if (backtrackedAnnotation != null) {
             result = nextElement.continueMatch(after, backtrackedAnnotation, ruleMatch, ruleApply,
                     parentContainerMatch, sideStepOrigin, null, stream, crowd);
@@ -423,22 +424,30 @@ public class ComposedRuleElement extends
     return result;
   }
 
-  private AnnotationFS getBacktrackedAnnotation(List<RuleElementMatch> evaluateMatches,
-          AnnotationFS annotation) {
+  private AnnotationFS getBacktrackedAnnotation(boolean after,
+          List<RuleElementMatch> evaluateMatches, AnnotationFS annotation) {
     if (evaluateMatches == null) {
       return null;
     }
     if (evaluateMatches.isEmpty()) {
       return annotation;
     }
-    // TODO both directions!
-    List<AnnotationFS> textsMatched = evaluateMatches.get(evaluateMatches.size() - 1)
-            .getTextsMatched();
-    if (textsMatched.isEmpty()) {
-      return null;
+    if (after) {
+      List<AnnotationFS> textsMatched = evaluateMatches.get(evaluateMatches.size() - 1)
+              .getTextsMatched();
+      if (textsMatched.isEmpty()) {
+        return null;
+      }
+      AnnotationFS backtrackedAnnotation = textsMatched.get(textsMatched.size() - 1);
+      return backtrackedAnnotation;
+    } else {
+      List<AnnotationFS> textsMatched = evaluateMatches.get(0).getTextsMatched();
+      if (textsMatched.isEmpty()) {
+        return null;
+      }
+      AnnotationFS backtrackedAnnotation = textsMatched.get(0);
+      return backtrackedAnnotation;
     }
-    AnnotationFS backtrackedAnnotation = textsMatched.get(textsMatched.size() - 1);
-    return backtrackedAnnotation;
   }
 
   private List<RuleMatch> fallback(boolean after, boolean failed, AnnotationFS annotation,

Modified: uima/sandbox/ruta/trunk/ruta-core/src/main/java/org/apache/uima/ruta/rule/RuleElementCaretaker.java
URL: http://svn.apache.org/viewvc/uima/sandbox/ruta/trunk/ruta-core/src/main/java/org/apache/uima/ruta/rule/RuleElementCaretaker.java?rev=1539320&r1=1539319&r2=1539320&view=diff
==============================================================================
--- uima/sandbox/ruta/trunk/ruta-core/src/main/java/org/apache/uima/ruta/rule/RuleElementCaretaker.java (original)
+++ uima/sandbox/ruta/trunk/ruta-core/src/main/java/org/apache/uima/ruta/rule/RuleElementCaretaker.java Wed Nov  6 11:56:59 2013
@@ -47,6 +47,8 @@ public class RuleElementCaretaker implem
     if (indexOf > 0) {
       RuleElement ruleElement = container.getRuleElements().get(indexOf - 1);
       return ruleElement;
+    } else if(indexOf == -1) {
+      return container.getRuleElements().get(container.getRuleElements().size() - 1);
     }
     return null;
   }

Added: uima/sandbox/ruta/trunk/ruta-core/src/test/java/org/apache/uima/ruta/ManualAnchoringTest.java
URL: http://svn.apache.org/viewvc/uima/sandbox/ruta/trunk/ruta-core/src/test/java/org/apache/uima/ruta/ManualAnchoringTest.java?rev=1539320&view=auto
==============================================================================
--- uima/sandbox/ruta/trunk/ruta-core/src/test/java/org/apache/uima/ruta/ManualAnchoringTest.java (added)
+++ uima/sandbox/ruta/trunk/ruta-core/src/test/java/org/apache/uima/ruta/ManualAnchoringTest.java Wed Nov  6 11:56:59 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 ManualAnchoringTest {
+
+  @Test
+  public void test() {
+    String document = "A, B and C.";
+    String script = "";
+    script += "CW{-> T1};\n";
+    script += "\"and\"{-> T2};\n";
+    script += "T1 (COMMA T1)* @T2 T1 {->MARK(T3,1,4)};\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, 3);
+    ai = cas.getAnnotationIndex(t);
+    iterator = ai.iterator();
+    assertEquals(1, ai.size());
+    assertEquals("A, B and C", iterator.next().getCoveredText());
+    
+    if (cas != null) {
+      cas.release();
+    }
+
+  }
+}

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