You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@uima.apache.org by re...@apache.org on 2020/10/27 10:50:09 UTC

[uima-uimafit] 01/01: [UIMA-6286] select following finds zero-width annotation at reference end position

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

rec pushed a commit to branch bugfix/UIMA-6286-select-following-finds-zero-width-annotation-at-reference-end-position
in repository https://gitbox.apache.org/repos/asf/uima-uimafit.git

commit 48a72b3fb5ce637c6e943ea854c5e6965898f32c
Author: Richard Eckart de Castilho <re...@apache.org>
AuthorDate: Tue Oct 27 11:47:34 2020 +0100

    [UIMA-6286] select following finds zero-width annotation at reference end position
    
    - When selecting following annotations, skip over zero-width annotations that are the the end position of the reference interval
    - Added unit test checking behavior for zero-width annotations at start/end of reference when selecting following and preceding
---
 .../java/org/apache/uima/fit/util/CasUtil.java     |  9 +++++++
 .../org/apache/uima/fit/util/JCasUtilTest.java     | 29 ++++++++++++++++++++++
 2 files changed, 38 insertions(+)

diff --git a/uimafit-core/src/main/java/org/apache/uima/fit/util/CasUtil.java b/uimafit-core/src/main/java/org/apache/uima/fit/util/CasUtil.java
index 187fe00..3e96190 100644
--- a/uimafit-core/src/main/java/org/apache/uima/fit/util/CasUtil.java
+++ b/uimafit-core/src/main/java/org/apache/uima/fit/util/CasUtil.java
@@ -1254,8 +1254,17 @@ public final class CasUtil {
     }
 
     // add annotations from the iterator into the result list
+    int refEnd = annotation.getEnd();
     List<AnnotationFS> followingAnnotations = new ArrayList<AnnotationFS>();
     for (int i = 0; i < count && itr.isValid(); i++, itr.moveToNext()) {
+      AnnotationFS fs = itr.get();
+      int begin = fs.getBegin();
+      int end = fs.getEnd();
+      if (begin == end && refEnd == begin) {
+        // Skip zero-width annotation at the end of the reference annotation. These are considered
+        // to be "coveredBy" instead of following
+        continue;
+      }
       followingAnnotations.add(itr.get());
     }
     return followingAnnotations;
diff --git a/uimafit-core/src/test/java/org/apache/uima/fit/util/JCasUtilTest.java b/uimafit-core/src/test/java/org/apache/uima/fit/util/JCasUtilTest.java
index 12290b6..1932ecd 100644
--- a/uimafit-core/src/test/java/org/apache/uima/fit/util/JCasUtilTest.java
+++ b/uimafit-core/src/test/java/org/apache/uima/fit/util/JCasUtilTest.java
@@ -21,6 +21,7 @@
  */
 package org.apache.uima.fit.util;
 
+import static java.lang.Integer.MAX_VALUE;
 import static java.util.Arrays.asList;
 import static java.util.stream.Collectors.toList;
 import static org.apache.uima.fit.factory.TypeSystemDescriptionFactory.createTypeSystemDescription;
@@ -931,6 +932,34 @@ public class JCasUtilTest extends ComponentTestBase {
   }
 
   @Test
+  public void thatSelectFollowingDoesNotFindZeroWidthAnnotationAtEnd()
+  {
+    Annotation a1 = new Annotation(jCas, 10, 20);
+    Annotation a2 = new Annotation(jCas, 20, 20);
+    
+    asList(a1, a2).forEach(a -> a.addToIndexes());
+    
+    List<Annotation> selection = selectFollowing(Annotation.class, a1, MAX_VALUE);
+    
+    assertThat(selection)
+            .isEmpty();
+  }
+
+  @Test
+  public void thatSelectPrecedingDoesNotFindZeroWidthAnnotationAtStart()
+  {
+    Annotation a1 = new Annotation(jCas, 10, 20);
+    Annotation a2 = new Annotation(jCas, 10, 10);
+    
+    asList(a1, a2).forEach(a -> a.addToIndexes());
+    
+    List<Annotation> selection = selectPreceding(Annotation.class, a1, MAX_VALUE);
+    
+    assertThat(selection)
+            .isEmpty();
+  }
+    
+  @Test
   public void testExists() throws UIMAException {
     JCas jcas = CasCreationUtils.createCas(createTypeSystemDescription(), null, null).getJCas();