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 2018/12/05 08:42:43 UTC

[uima-uimafit] branch feature/UIMA-5929-Add-exists-method-to-CasUtil-3_0_x created (now 048164c)

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

rec pushed a change to branch feature/UIMA-5929-Add-exists-method-to-CasUtil-3_0_x
in repository https://gitbox.apache.org/repos/asf/uima-uimafit.git.


      at 048164c  No Jira - excluding issuesFixed folder from git

This branch includes the following new commits:

     new 9b2481d  [UIMA-5929] Add exists() method to CasUtil
     new 048164c  No Jira - excluding issuesFixed folder from git

The 2 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-uimafit] 02/02: No Jira - excluding issuesFixed folder from git

Posted by re...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

rec pushed a commit to branch feature/UIMA-5929-Add-exists-method-to-CasUtil-3_0_x
in repository https://gitbox.apache.org/repos/asf/uima-uimafit.git

commit 048164c82e4b7f66fb58136cf79665281f32a0b0
Author: Richard Eckart de Castilho <re...@apache.org>
AuthorDate: Wed Dec 5 09:37:30 2018 +0100

    No Jira - excluding issuesFixed folder from git
---
 .gitignore | 1 +
 1 file changed, 1 insertion(+)

diff --git a/.gitignore b/.gitignore
index 19c577d..d4318d8 100644
--- a/.gitignore
+++ b/.gitignore
@@ -3,3 +3,4 @@
 .settings/
 target/
 api-change-report/
+issuesFixed


[uima-uimafit] 01/02: [UIMA-5929] Add exists() method to CasUtil

Posted by re...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

rec pushed a commit to branch feature/UIMA-5929-Add-exists-method-to-CasUtil-3_0_x
in repository https://gitbox.apache.org/repos/asf/uima-uimafit.git

commit 9b2481d4296f302e685f20f4a4942c586952ec8c
Author: Richard Eckart de Castilho <re...@apache.org>
AuthorDate: Wed Dec 5 09:36:43 2018 +0100

    [UIMA-5929] Add exists() method to CasUtil
    
    - Added CasUtil.exists() method
    - Added corresponding unit test
---
 .../main/java/org/apache/uima/fit/util/CasUtil.java   | 16 ++++++++++++++++
 .../java/org/apache/uima/fit/util/CasUtilTest.java    | 19 +++++++++++++++++++
 2 files changed, 35 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 8e93f3d..ea7520e 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
@@ -46,6 +46,7 @@ import org.apache.uima.cas.TypeSystem;
 import org.apache.uima.cas.impl.Subiterator;
 import org.apache.uima.cas.text.AnnotationFS;
 import org.apache.uima.cas.text.AnnotationIndex;
+import org.apache.uima.jcas.cas.TOP;
 import org.apache.uima.jcas.tcas.Annotation;
 
 /**
@@ -1185,6 +1186,21 @@ public final class CasUtil {
   }
 
   /**
+   * Test if a CAS contains an annotation of the given type.
+   * 
+   * @param <T>
+   *          the annotation type.
+   * @param aCas
+   *          a CAS.
+   * @param aType
+   *          a annotation type.
+   * @return {@code true} if there is at least one annotation of the given type in the CAS.
+   */
+  public static <T extends TOP> boolean exists(CAS aCas, Type aType) {
+    return CasUtil.iterator(aCas, aType).hasNext();
+  }
+  
+  /**
    * Convenience method to get the specified view or a default view if the requested view does not
    * exist. The default can also be {@code null}.
    * 
diff --git a/uimafit-core/src/test/java/org/apache/uima/fit/util/CasUtilTest.java b/uimafit-core/src/test/java/org/apache/uima/fit/util/CasUtilTest.java
index f1a1595..67d0ae7 100644
--- a/uimafit-core/src/test/java/org/apache/uima/fit/util/CasUtilTest.java
+++ b/uimafit-core/src/test/java/org/apache/uima/fit/util/CasUtilTest.java
@@ -19,6 +19,7 @@
 package org.apache.uima.fit.util;
 
 import static java.util.Arrays.asList;
+import static org.apache.uima.fit.factory.TypeSystemDescriptionFactory.createTypeSystemDescription;
 import static org.apache.uima.fit.util.CasUtil.getAnnotationType;
 import static org.apache.uima.fit.util.CasUtil.getType;
 import static org.apache.uima.fit.util.CasUtil.iterator;
@@ -27,12 +28,16 @@ import static org.apache.uima.fit.util.CasUtil.select;
 import static org.apache.uima.fit.util.CasUtil.selectByIndex;
 import static org.apache.uima.fit.util.CasUtil.selectFS;
 import static org.apache.uima.fit.util.CasUtil.toText;
+import static org.apache.uima.fit.util.CasUtil.exists;
 import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
 import static org.junit.Assert.assertNull;
+import static org.junit.Assert.assertTrue;
 
 import java.util.Collection;
 import java.util.Iterator;
 
+import org.apache.uima.UIMAException;
 import org.apache.uima.cas.ArrayFS;
 import org.apache.uima.cas.CAS;
 import org.apache.uima.cas.FeatureStructure;
@@ -42,6 +47,7 @@ import org.apache.uima.fit.ComponentTestBase;
 import org.apache.uima.fit.type.Token;
 import org.apache.uima.jcas.cas.TOP;
 import org.apache.uima.jcas.tcas.Annotation;
+import org.apache.uima.util.CasCreationUtils;
 import org.junit.Test;
 
 /**
@@ -186,4 +192,17 @@ public class CasUtilTest extends ComponentTestBase {
     assertEquals(asList("Rot", "wood", "cheeses", "dew?"),
             toText((Iterable<AnnotationFS>) (Iterable) selectFS(cas, getType(cas, Token.class))));
   }
+  
+  @Test
+  public void testExists() throws UIMAException {
+    CAS cas = CasCreationUtils.createCas(createTypeSystemDescription(), null, null);
+
+    Type tokenType = CasUtil.getAnnotationType(cas, Token.class);
+    
+    assertFalse(exists(cas, tokenType));
+
+    cas.addFsToIndexes(cas.createAnnotation(tokenType, 0, 1));
+
+    assertTrue(exists(cas, tokenType));
+  }
 }