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 2015/06/16 18:11:12 UTC

svn commit: r1685863 - in /uima/ruta/trunk/ruta-core/src: main/java/org/apache/uima/ruta/RutaStream.java test/java/org/apache/uima/ruta/ZeroLengthAnnotationTest.java

Author: pkluegl
Date: Tue Jun 16 16:11:11 2015
New Revision: 1685863

URL: http://svn.apache.org/r1685863
Log:
UIMA-4457
- zero/negative length annotations are invisible
- added test

Added:
    uima/ruta/trunk/ruta-core/src/test/java/org/apache/uima/ruta/ZeroLengthAnnotationTest.java   (with props)
Modified:
    uima/ruta/trunk/ruta-core/src/main/java/org/apache/uima/ruta/RutaStream.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=1685863&r1=1685862&r2=1685863&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 Jun 16 16:11:11 2015
@@ -178,11 +178,13 @@ public class RutaStream extends FSIterat
             break;
           }
           Integer second = anchors.first();
+          if(first < second) {
           RutaBasic newTMB = new RutaBasic(getJCas(), first, second);
           newTMB.setLowMemoryProfile(lowMemoryProfile);
           beginAnchors.put(first, newTMB);
           endAnchors.put(second, newTMB);
           cas.addFsToIndexes(newTMB);
+          }
         }
       }
       for (AnnotationFS a : allAnnotations) {
@@ -298,6 +300,9 @@ public class RutaStream extends FSIterat
         toSplit = ceiling;
       }
       int newEnd = toSplit.getEnd();
+      if(newEnd == anchor) {
+        return false;
+      }
       cas.removeFsFromIndexes(toSplit);
       toSplit.setEnd(anchor);
       RutaBasic newRB = new RutaBasic(getJCas(), anchor, newEnd);
@@ -792,6 +797,10 @@ public class RutaStream extends FSIterat
     if (annotationFS == null) {
       return false;
     }
+    if(annotationFS.getBegin() >= annotationFS.getEnd()) {
+      return false;
+    }
+    
     AnnotationFS windowAnnotation = filter.getWindowAnnotation();
     if (!ignoreWindow && windowAnnotation != null
             && (annotationFS.getBegin() < windowAnnotation.getBegin() || annotationFS.getEnd() > windowAnnotation

Added: uima/ruta/trunk/ruta-core/src/test/java/org/apache/uima/ruta/ZeroLengthAnnotationTest.java
URL: http://svn.apache.org/viewvc/uima/ruta/trunk/ruta-core/src/test/java/org/apache/uima/ruta/ZeroLengthAnnotationTest.java?rev=1685863&view=auto
==============================================================================
--- uima/ruta/trunk/ruta-core/src/test/java/org/apache/uima/ruta/ZeroLengthAnnotationTest.java (added)
+++ uima/ruta/trunk/ruta-core/src/test/java/org/apache/uima/ruta/ZeroLengthAnnotationTest.java Tue Jun 16 16:11:11 2015
@@ -0,0 +1,85 @@
+/*
+ * 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 org.apache.uima.cas.CAS;
+import org.apache.uima.cas.Type;
+import org.apache.uima.cas.text.AnnotationFS;
+import org.apache.uima.ruta.engine.Ruta;
+import org.apache.uima.ruta.engine.RutaTestUtils;
+import org.junit.Test;
+
+public class ZeroLengthAnnotationTest {
+
+  
+  @Test
+  public void testMatchType() {
+    String document = "Some text.";
+    String script = "";
+    script += "W W{-> T1};";
+    CAS cas = null;
+    try {
+      cas = RutaTestUtils.getCAS(document);
+      Type type = cas.getTypeSystem().getType("org.apache.uima.ruta.type.W");
+      // call for seeding
+      Ruta.apply(cas, "");
+      addZeroLengthAnnotations(cas, type);
+      Ruta.apply(cas, script);
+    } catch (Exception e) {
+      e.printStackTrace();
+    }
+
+    RutaTestUtils.assertAnnotationsEquals(cas, 1, 1, "text");
+
+    cas.release();
+  }
+
+  @Test
+  public void testOtherType() {
+    String document = "Some text.";
+    String script = "";
+    script += "W W{-> T1};";
+    CAS cas = null;
+    try {
+      cas = RutaTestUtils.getCAS(document);
+      Type type = cas.getTypeSystem().getType("org.apache.uima.ruta.type.TruePositive");
+      addZeroLengthAnnotations(cas, type);
+      
+      Ruta.apply(cas, script);
+    } catch (Exception e) {
+      e.printStackTrace();
+    }
+
+    RutaTestUtils.assertAnnotationsEquals(cas, 1, 1, "text");
+
+    cas.release();
+  }
+  
+  private void addZeroLengthAnnotations(CAS cas, Type type) {
+    AnnotationFS a0 = cas.createAnnotation(type, 0, 0);
+    AnnotationFS a5 = cas.createAnnotation(type, 5, 5);
+    AnnotationFS a10 = cas.createAnnotation(type, 10, 10);
+    cas.addFsToIndexes(a0);
+    cas.addFsToIndexes(a0);
+    cas.addFsToIndexes(a5);
+    cas.addFsToIndexes(a10);
+  }
+  
+}

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