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 2013/04/26 23:17:35 UTC

svn commit: r1476406 - in /uima/sandbox/uimafit/trunk/uimafit/src/main/java/org/apache/uima/fit/util: CasUtil.java JCasUtil.java

Author: rec
Date: Fri Apr 26 21:17:35 2013
New Revision: 1476406

URL: http://svn.apache.org/r1476406
Log:
[UIMA-2846] Add more select* methods that do not take a CAS argument 
- Added more convenience methods without the CAS argument.
- Using getView() instead of getCas() in the methods without CAS argument.

Modified:
    uima/sandbox/uimafit/trunk/uimafit/src/main/java/org/apache/uima/fit/util/CasUtil.java
    uima/sandbox/uimafit/trunk/uimafit/src/main/java/org/apache/uima/fit/util/JCasUtil.java

Modified: uima/sandbox/uimafit/trunk/uimafit/src/main/java/org/apache/uima/fit/util/CasUtil.java
URL: http://svn.apache.org/viewvc/uima/sandbox/uimafit/trunk/uimafit/src/main/java/org/apache/uima/fit/util/CasUtil.java?rev=1476406&r1=1476405&r2=1476406&view=diff
==============================================================================
--- uima/sandbox/uimafit/trunk/uimafit/src/main/java/org/apache/uima/fit/util/CasUtil.java (original)
+++ uima/sandbox/uimafit/trunk/uimafit/src/main/java/org/apache/uima/fit/util/CasUtil.java Fri Apr 26 21:17:35 2013
@@ -554,6 +554,47 @@ public class CasUtil {
    * <p>
    * <b>Note:</b> this is <b>REALLY SLOW!</b> You don't want to use this. Instead, consider using
    * {@link #indexCovering(CAS, Type, Type)} or a {@link ContainmentIndex}.
+   * @param type
+   *          a UIMA type.
+   * @param coveredAnnotation
+   *          the covered annotation.
+   * 
+   * @return a return value.
+   */
+  public static List<AnnotationFS> selectCovering(Type type, AnnotationFS coveredAnnotation) {
+
+    return selectCovering(coveredAnnotation.getView(), type, coveredAnnotation.getBegin(),
+            coveredAnnotation.getEnd());
+  }
+
+  /**
+   * Get a list of annotations of the given annotation type constraint by a certain annotation.
+   * Iterates over all annotations to find the covering annotations.
+   * 
+   * <p>
+   * <b>Note:</b> this is <b>REALLY SLOW!</b> You don't want to use this. Instead, consider using
+   * {@link #indexCovering(CAS, Type, Type)} or a {@link ContainmentIndex}.
+   * 
+   * @param cas
+   *          a CAS.
+   * @param type
+   *          a UIMA type.
+   * @param coveredAnnotation
+   *          the covered annotation.
+   * @return a return value.
+   */
+  public static List<AnnotationFS> selectCovering(CAS cas, Type type, AnnotationFS coveredAnnotation) {
+
+    return selectCovering(cas, type, coveredAnnotation.getBegin(), coveredAnnotation.getEnd());
+  }
+  
+  /**
+   * Get a list of annotations of the given annotation type constraint by a certain annotation.
+   * Iterates over all annotations to find the covering annotations.
+   * 
+   * <p>
+   * <b>Note:</b> this is <b>REALLY SLOW!</b> You don't want to use this. Instead, consider using
+   * {@link #indexCovering(CAS, Type, Type)} or a {@link ContainmentIndex}.
    * 
    * @param cas
    *          a CAS.

Modified: uima/sandbox/uimafit/trunk/uimafit/src/main/java/org/apache/uima/fit/util/JCasUtil.java
URL: http://svn.apache.org/viewvc/uima/sandbox/uimafit/trunk/uimafit/src/main/java/org/apache/uima/fit/util/JCasUtil.java?rev=1476406&r1=1476405&r2=1476406&view=diff
==============================================================================
--- uima/sandbox/uimafit/trunk/uimafit/src/main/java/org/apache/uima/fit/util/JCasUtil.java (original)
+++ uima/sandbox/uimafit/trunk/uimafit/src/main/java/org/apache/uima/fit/util/JCasUtil.java Fri Apr 26 21:17:35 2013
@@ -314,8 +314,8 @@ public class JCasUtil {
    */
   public static <T extends AnnotationFS> List<T> selectCovered(Class<T> type,
           AnnotationFS coveringAnnotation) {
-    CAS cas = coveringAnnotation.getCAS();
-    return cast(CasUtil.selectCovered(cas, CasUtil.getType(cas, type), coveringAnnotation));
+    return cast(CasUtil.selectCovered(CasUtil.getType(coveringAnnotation.getCAS(), type),
+            coveringAnnotation));
   }
 
   /**
@@ -376,6 +376,53 @@ public class JCasUtil {
    * 
    * @param <T>
    *          the JCas type.
+   * @param type
+   *          a UIMA type.
+   * @param coveredAnnotation
+   *          the covered annotation.
+   * @return a return value.
+   */
+  public static <T extends Annotation> List<T> selectCovering(Class<T> type,
+          AnnotationFS coveredAnnotation) {
+
+    return cast(CasUtil.selectCovering(CasUtil.getType(coveredAnnotation.getCAS(), type),
+            coveredAnnotation));
+  }
+  
+  /**
+   * Get a list of annotations of the given annotation type constraint by a certain annotation.
+   * Iterates over all annotations to find the covering annotations.
+   * 
+   * <p>
+   * <b>Note:</b> this is <b>REALLY SLOW!</b> You don't want to use this. Instead, consider using
+   * {@link #indexCovering(JCas, Class, Class)} or a {@link ContainmentIndex}.
+   * 
+   * @param <T>
+   *          the JCas type.
+   * @param jCas
+   *          a CAS.
+   * @param type
+   *          a UIMA type.
+   * @param coveredAnnotation
+   *          the covered annotation.
+   * @return a return value.
+   */
+  public static <T extends Annotation> List<T> selectCovering(JCas jCas, Class<T> type,
+          AnnotationFS coveredAnnotation) {
+
+    return cast(CasUtil.selectCovering(jCas.getCas(), getType(jCas, type), coveredAnnotation));
+  }
+  
+  /**
+   * Get a list of annotations of the given annotation type constraint by a certain annotation.
+   * Iterates over all annotations to find the covering annotations.
+   * 
+   * <p>
+   * <b>Note:</b> this is <b>REALLY SLOW!</b> You don't want to use this. Instead, consider using
+   * {@link #indexCovering(JCas, Class, Class)} or a {@link ContainmentIndex}.
+   * 
+   * @param <T>
+   *          the JCas type.
    * @param jCas
    *          a CAS.
    * @param type
@@ -559,6 +606,25 @@ public class JCasUtil {
    * 
    * @param <T>
    *          the JCas type.
+   * @param aType
+   *          a type.
+   * @param annotation
+   *          anchor annotation
+   * @param count
+   *          number of annotations to collect
+   * @return List of aType annotations preceding anchor annotation
+   */
+  public static <T extends Annotation> List<T> selectPreceding(Class<T> aType,
+          AnnotationFS annotation, int count) {
+    Type t = CasUtil.getType(annotation.getCAS(), aType);
+    return cast(CasUtil.selectPreceding(annotation.getView(), t, annotation, count));
+  }
+
+  /**
+   * Returns the n annotations preceding the given annotation
+   * 
+   * @param <T>
+   *          the JCas type.
    * @param aJCas
    *          a JCas.
    * @param aType
@@ -580,6 +646,25 @@ public class JCasUtil {
    * 
    * @param <T>
    *          the JCas type.
+   * @param aType
+   *          a type.
+   * @param annotation
+   *          anchor annotation
+   * @param count
+   *          number of annotations to collect
+   * @return List of aType annotations following anchor annotation
+   */
+  public static <T extends Annotation> List<T> selectFollowing(Class<T> aType,
+          AnnotationFS annotation, int count) {
+    Type t = CasUtil.getType(annotation.getCAS(), aType);
+    return cast(CasUtil.selectFollowing(annotation.getView(), t, annotation, count));
+  }
+
+  /**
+   * Returns the n annotations following the given annotation
+   * 
+   * @param <T>
+   *          the JCas type.
    * @param aJCas
    *          a JCas.
    * @param aType