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:35:54 UTC

[uima-uimaj] branch bugfix/UIMA-6286-select-following-finds-zero-width-annotation-at-reference-end-position created (now 89c53d1)

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

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


      at 89c53d1  [UIMA-6286] select following finds zero-width annotation at reference end position

This branch includes the following new commits:

     new 89c53d1  [UIMA-6286] select following finds zero-width annotation at reference end position

The 1 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.



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

Posted by re...@apache.org.
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-uimaj.git

commit 89c53d192727f0efc5d646e8147851cfc49364bd
Author: Richard Eckart de Castilho <re...@apache.org>
AuthorDate: Tue Oct 27 11:35:40 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
---
 .../org/apache/uima/cas/impl/SelectFSs_impl.java   | 15 +++++++--
 .../org/apache/uima/cas/impl/SelectFsTest.java     | 37 +++++++++++++++++++++-
 2 files changed, 49 insertions(+), 3 deletions(-)

diff --git a/uimaj-core/src/main/java/org/apache/uima/cas/impl/SelectFSs_impl.java b/uimaj-core/src/main/java/org/apache/uima/cas/impl/SelectFSs_impl.java
index 13f90e6..7880a05 100644
--- a/uimaj-core/src/main/java/org/apache/uima/cas/impl/SelectFSs_impl.java
+++ b/uimaj-core/src/main/java/org/apache/uima/cas/impl/SelectFSs_impl.java
@@ -772,7 +772,7 @@ public class SelectFSs_impl <T extends FeatureStructure> implements SelectFSs<T>
     if (boundsUse == BoundsUse.notBounded) {
       if (!isSortedIndex) {
         // set index or bag index
-        it = (LowLevelIterator<T>) idx.iterator();       
+        it = (LowLevelIterator<T>) idx.iterator();
       } else {
         // index is sorted but no bounds are being used.  Varieties:
         //   - AnnotationIndex:
@@ -781,7 +781,7 @@ public class SelectFSs_impl <T extends FeatureStructure> implements SelectFSs<T>
         //     - typePriority / ignore typePriority
         //     - orderNotNecessary / orderNeeded
         //   - preceding: need to skip over annotations whose end is > positioning-begin
-
+        //   - following: need to skip over zero-width annotations at positioning-end
         it = isAnnotationIndex 
                ? (LowLevelIterator<T>) ai.iterator( ! isNonOverlapping, IS_NOT_STRICT, isUnordered, ! isTypePriority)
                : idx.iterator(isUnordered, ! isTypePriority);
@@ -791,6 +791,17 @@ public class SelectFSs_impl <T extends FeatureStructure> implements SelectFSs<T>
               // true if ok, false to skip
               ((Annotation) fs).getEnd() <= ((Annotation) startingFs).getBegin());
         }
+        
+        if (isFollowing) {
+          // filter the iterator to skip zero-width annotations at positioning-end because these
+          // are considered to be covered and not following
+          int startingFsEnd = ((Annotation) startingFs).getEnd();
+          it = new FilteredIterator<>(it, fs -> {
+            // true if ok, false to skip
+            int begin = ((Annotation) fs).getBegin();
+            return begin != ((Annotation) fs).getEnd() || begin != startingFsEnd;
+          });
+        }
       }
     } else {
       if (isEmptyBoundingFs) {
diff --git a/uimaj-core/src/test/java/org/apache/uima/cas/impl/SelectFsTest.java b/uimaj-core/src/test/java/org/apache/uima/cas/impl/SelectFsTest.java
index bd4f587..a4b21b9 100644
--- a/uimaj-core/src/test/java/org/apache/uima/cas/impl/SelectFsTest.java
+++ b/uimaj-core/src/test/java/org/apache/uima/cas/impl/SelectFsTest.java
@@ -43,11 +43,15 @@ import org.apache.uima.util.CasCreationUtils;
 import org.apache.uima.util.XMLInputSource;
 import org.junit.Before;
 import org.junit.BeforeClass;
+import org.junit.FixMethodOrder;
 import org.junit.Test;
+import org.junit.runners.MethodSorters;
 
 import x.y.z.Sentence;
 import x.y.z.Token;
 
+// Sorting only to keep the list in Eclipse ordered so it is easier spot if related tests fail
+@FixMethodOrder(MethodSorters.NAME_ASCENDING)
 public class SelectFsTest  {
 
   private static TypeSystemDescription typeSystemDescription;
@@ -175,7 +179,7 @@ public class SelectFsTest  {
   }
   
   @Test
-  public void testempty() {
+  public void thatIsEmptyWorks() {
     cas.reset();
     JCas jcas = cas.getJCas();
     cas.setDocumentText("t1 t2 t3 t4");
@@ -386,6 +390,37 @@ public class SelectFsTest  {
   }
 
   @Test
+  public void thatSelectFollowingDoesNotFindZeroWidthAnnotationAtEnd()
+  {
+    Annotation a1 = cas.createAnnotation(cas.getAnnotationType(), 10, 20);
+    Annotation a2 = cas.createAnnotation(cas.getAnnotationType(), 20, 20);
+    
+    asList(a1, a2).forEach(cas::addFsToIndexes);
+    
+    List<Annotation> selection = cas.select(Annotation.class)
+        .following(a1)
+        .asList();
+    
+    assertThat(selection)
+            .isEmpty();
+  }
+
+  @Test
+  public void thatSelectPrecedingDoesNotFindZeroWidthAnnotationAtStart()
+  {
+    Annotation a1 = cas.createAnnotation(cas.getAnnotationType(), 10, 20);
+    Annotation a2 = cas.createAnnotation(cas.getAnnotationType(), 10, 10);
+    
+    asList(a1, a2).forEach(cas::addFsToIndexes);
+    
+    List<Annotation> selection = cas.select(Annotation.class)
+        .preceding(a1)
+        .asList();
+    
+    assertThat(selection)
+            .isEmpty();
+  }
+  @Test
   public void thatSelectFollowingReturnsAdjacentAnnotation()
   {
     Annotation a1 = cas.createAnnotation(cas.getAnnotationType(), 10, 20);