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 2020/08/17 15:50:12 UTC

[uima-ruta] branch UIMA-6256-SPLIT-creates-invalid-annotations updated: UIMA-6256: fixed SPLIT logic

This is an automated email from the ASF dual-hosted git repository.

pkluegl pushed a commit to branch UIMA-6256-SPLIT-creates-invalid-annotations
in repository https://gitbox.apache.org/repos/asf/uima-ruta.git


The following commit(s) were added to refs/heads/UIMA-6256-SPLIT-creates-invalid-annotations by this push:
     new 6a82b11  UIMA-6256: fixed SPLIT logic
6a82b11 is described below

commit 6a82b119337e4dc51998474c3a17cf7de03411d4
Author: Peter Klügl <pe...@averbis.com>
AuthorDate: Mon Aug 17 17:49:45 2020 +0200

    UIMA-6256: fixed SPLIT logic
---
 .../org/apache/uima/ruta/action/SplitAction.java   | 30 +++++++++++-----------
 .../org/apache/uima/ruta/action/SplitTest.java     |  6 -----
 2 files changed, 15 insertions(+), 21 deletions(-)

diff --git a/ruta-core/src/main/java/org/apache/uima/ruta/action/SplitAction.java b/ruta-core/src/main/java/org/apache/uima/ruta/action/SplitAction.java
index 41aa3ed..e8faa34 100644
--- a/ruta-core/src/main/java/org/apache/uima/ruta/action/SplitAction.java
+++ b/ruta-core/src/main/java/org/apache/uima/ruta/action/SplitAction.java
@@ -108,25 +108,25 @@ public class SplitAction extends AbstractRutaAction {
     cas.removeFsFromIndexes(annotation);
 
     int overallEnd = annotation.getEnd();
-    Annotation first = annotation;
+    Annotation current = annotation;
 
     for (AnnotationFS each : annotationsInWindow) {
-      int firstEnd = addToEnd ? each.getEnd() : each.getBegin();
-      first.setEnd(firstEnd);
-      boolean valid = trimInvisible(first, stream);
+      int currentEnd = addToEnd ? each.getEnd() : each.getBegin();
+      current.setEnd(currentEnd);
+      boolean valid = trimInvisible(current, stream);
       if (valid) {
-        stream.addAnnotation(first, true, true, match);
+        stream.addAnnotation(current, true, true, match);
       }
 
-      Annotation second = (Annotation) cc.copyFs(first);
-      int secondBegin = addToBegin ? each.getBegin() : each.getEnd();
-      second.setBegin(secondBegin);
-      second.setEnd(overallEnd);
-      valid = trimInvisible(second, stream);
-      if (valid) {
-        stream.addAnnotation(second, true, true, match);
-      }
-      first = second;
+      Annotation next = (Annotation) cc.copyFs(current);
+      int nextBegin = addToBegin ? each.getBegin() : each.getEnd();
+      next.setBegin(nextBegin);
+      next.setEnd(overallEnd);
+
+      current = next;
+    }
+    if (trimInvisible(current, stream)) {
+      stream.addAnnotation(current, true, true, match);
     }
 
   }
@@ -171,7 +171,6 @@ public class SplitAction extends AbstractRutaAction {
   }
 
   private boolean trimInvisible(Annotation annotation, RutaStream stream) {
-    List<RutaBasic> basics = new ArrayList<>(stream.getAllBasicsInWindow(annotation));
 
     int min = annotation.getEnd();
     int max = annotation.getBegin();
@@ -179,6 +178,7 @@ public class SplitAction extends AbstractRutaAction {
     if (min <= max) {
       return false;
     }
+    List<RutaBasic> basics = new ArrayList<>(stream.getAllBasicsInWindow(annotation));
 
     for (RutaBasic each : basics) {
       if (stream.isVisible(each)) {
diff --git a/ruta-core/src/test/java/org/apache/uima/ruta/action/SplitTest.java b/ruta-core/src/test/java/org/apache/uima/ruta/action/SplitTest.java
index 22fac40..3173f56 100644
--- a/ruta-core/src/test/java/org/apache/uima/ruta/action/SplitTest.java
+++ b/ruta-core/src/test/java/org/apache/uima/ruta/action/SplitTest.java
@@ -37,7 +37,6 @@ import org.apache.uima.cas.text.AnnotationIndex;
 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.Ignore;
 import org.junit.Test;
 
 public class SplitTest {
@@ -330,7 +329,6 @@ public class SplitTest {
   }
 
   @Test
-  @Ignore
   public void testMultiSplit() throws Exception {
     String document = "CAP-------------";
     String script = "Document{-> T1};";
@@ -339,10 +337,6 @@ public class SplitTest {
 
     CAS cas = RutaTestUtils.getCAS(document);
     Ruta.apply(cas, script);
-//    Collection<AnnotationFS> select = CasUtil.select(cas, RutaTestUtils.getTestType(cas, 1));
-//    for (AnnotationFS annotationFS : select) {
-//      System.out.println(annotationFS.getCoveredText());
-//    }
     RutaTestUtils.assertAnnotationsEquals(cas, 1, 1, "CAP");
   }
 }