Class CasUtil
CAS
.-
Field Summary
Modifier and TypeFieldDescriptionstatic final String
Package name of JCas wrapper classes built into UIMA. -
Method Summary
Modifier and TypeMethodDescriptionstatic <T extends TOP>
booleanTest if a CAS contains an annotation of the given type.static Type
getAnnotationType
(CAS aCas, Class<?> aJCasClass) Get the CAS type for the given JCas wrapper class making sure it is or inherits fromAnnotation
.static Type
getAnnotationType
(CAS aCas, String aTypeName) Get the CAS type for the given name making sure it is or inherits from Annotation.static Type
Get the CAS type for the given JCas wrapper class.static Type
Get the CAS type for the given name.static Type
getType
(TypeSystem aTypeSystem, Class<?> type) Get the CAS type for the given JCas wrapper class.static Type
getType
(TypeSystem aTypeSystem, String aTypename) Get the CAS type for the given name.static CAS
Convenience method to get the specified view or create a new view if the requested view does not exist.static CAS
Convenience method to get the specified view or a default view if the requested view does not exist.static Map
<AnnotationFS, List<AnnotationFS>> indexCovered
(CAS cas, Type type, Type coveredType) Create an index for quickly lookup up the annotations covered by a particular annotation.static Map
<AnnotationFS, List<AnnotationFS>> indexCovering
(CAS cas, Type type, Type coveringType) Create an index for quickly lookup up the annotations covering a particular annotation.static boolean
isAnnotationType
(CAS aCas, Type aType) static <T extends AnnotationFS>
Iterator<T> Get an iterator over the given annotation type.static <T extends FeatureStructure>
Iterator<T> iteratorFS
(CAS cas, Type type) Deprecated.static void
requireAnnotationType
(CAS aCas, Type aType) static List
<AnnotationFS> Convenience method to iterator over all annotations of a given type.static Collection
<AnnotationFS> Convenience method to iterator over all annotations of a given type.static Collection
<AnnotationFS> Convenience method to iterator over all annotations.static Collection
<FeatureStructure> selectAllFS
(CAS aCas) Convenience method to iterator over all features structures.static List
<AnnotationFS> Get all annotations of the given type at the specified offsets.static List
<AnnotationFS> selectBetween
(CAS cas, Type type, AnnotationFS ann1, AnnotationFS ann2) Get a list of annotations of the given annotation type located between two annotations.static List
<AnnotationFS> selectBetween
(Type type, AnnotationFS ann1, AnnotationFS ann2) Get a list of annotations of the given annotation type located between two annotations.static AnnotationFS
selectByIndex
(CAS cas, Type type, int index) This method exists simply as a convenience method for unit testing.static List
<AnnotationFS> selectCovered
(CAS cas, Type type, int begin, int end) Get a list of annotations of the given annotation type constraint by a certain annotation.static List
<AnnotationFS> selectCovered
(CAS cas, Type type, AnnotationFS coveringAnnotation) Get a list of annotations of the given annotation type constraint by a certain annotation.static List
<AnnotationFS> selectCovered
(Type type, AnnotationFS coveringAnnotation) Get a list of annotations of the given annotation type constraint by a certain annotation.static List
<AnnotationFS> selectCovering
(CAS cas, Type type, int begin, int end) Get a list of annotations of the given annotation type constraint by a certain annotation.static List
<AnnotationFS> selectCovering
(CAS cas, Type type, AnnotationFS coveredAnnotation) Get a list of annotations of the given annotation type constraint by a certain annotation.static List
<AnnotationFS> selectCovering
(Type type, AnnotationFS coveredAnnotation) Get a list of annotations of the given annotation type constraint by a certain annotation.static List
<AnnotationFS> selectFollowing
(CAS cas, Type type, AnnotationFS anchor, int count) Returns the n annotations following the given annotationstatic List
<FeatureStructure> Convenience method to iterator over all feature structures of a given type.static <T extends FeatureStructure>
List<T> Deprecated.Usecas.select(type).asList()
static List
<AnnotationFS> selectOverlapping
(CAS aCas, Type aType, int aSelBegin, int aSelEnd) Get a list of annotations of the given annotation type overlapping the given span.static List
<AnnotationFS> selectOverlapping
(CAS aCas, Type aType, AnnotationFS aBoundaryAnnotation) Get a list of annotations of the given annotation type overlapping the given annotation.static List
<AnnotationFS> selectOverlapping
(Type aType, AnnotationFS aBoundaryAnnotation) Get a list of annotations of the given annotation type overlapping the given annotation.static List
<AnnotationFS> selectPreceding
(CAS cas, Type type, AnnotationFS anchor, int count) Returns the n annotations preceding the given annotationstatic AnnotationFS
selectSingle
(CAS cas, Type type) Get the single instance of the specified type from the CAS.static AnnotationFS
selectSingleAt
(CAS aCas, Type aType, int aBegin, int aEnd) Get the single instance of the specified type from the CAS at the given offsets.static FeatureStructure
selectSingleFS
(CAS cas, Type type) Get the single instance of the specified type from the CAS.static AnnotationFS
selectSingleRelative
(CAS cas, Type type, AnnotationFS aAnchor, int aPosition) Return an annotation preceding or following of a given reference annotation.static AnnotationFS
selectSingleRelative
(Type type, AnnotationFS annotation, int index) Return an annotation preceding or following of a given reference annotation.static <T extends AnnotationFS>
List<String> Fetch the text covered by the specified annotations and return it as a list of strings.static <T extends AnnotationFS>
List<String> Fetch the text covered by the specified annotations and return it as a list of strings.
-
Field Details
-
UIMA_BUILTIN_JCAS_PREFIX
Package name of JCas wrapper classes built into UIMA.- See Also:
-
-
Method Details
-
iteratorFS
Deprecated.Usecas.select(type).iterator()
Get an iterator over the given feature structures type.- Type Parameters:
T
- the JCas type.- Parameters:
cas
- a CAS.type
- a type.- Returns:
- a return value.
- See Also:
-
iterator
Get an iterator over the given annotation type.- Type Parameters:
T
- the JCas type.- Parameters:
cas
- a CAS.type
- a type.- Returns:
- a return value.
- See Also:
-
getType
Get the CAS type for the given JCas wrapper class.- Parameters:
cas
- the CAS hosting the type system.type
- the JCas wrapper class.- Returns:
- the CAS type.
-
getType
Get the CAS type for the given JCas wrapper class.- Parameters:
aTypeSystem
- the CAS hosting the type system.type
- the JCas wrapper class.- Returns:
- the CAS type.
-
getType
Get the CAS type for the given name.- Parameters:
aCas
- the CAS hosting the type system.aTypename
- the fully qualified type name.- Returns:
- the CAS type.
-
getType
Get the CAS type for the given name.- Parameters:
aTypeSystem
- the type systemaTypename
- the fully qualified type name.- Returns:
- the CAS type.
-
getAnnotationType
Get the CAS type for the given JCas wrapper class making sure it is or inherits fromAnnotation
.- Parameters:
aCas
- the CAS hosting the type system.aJCasClass
- the JCas wrapper class.- Returns:
- the CAS type.
-
getAnnotationType
Get the CAS type for the given name making sure it is or inherits from Annotation.- Parameters:
aCas
- the CAS hosting the type system.aTypeName
- the fully qualified type name.- Returns:
- the CAS type.
-
selectFS
Convenience method to iterator over all feature structures of a given type.- Parameters:
array
- features structure array.type
- the type.- Returns:
- A collection of the selected type.
- See Also:
-
select
Convenience method to iterator over all annotations of a given type.- Parameters:
array
- features structure array.type
- the type.- Returns:
- A collection of the selected type.
- See Also:
-
selectAllFS
Convenience method to iterator over all features structures.- Parameters:
aCas
- the CAS hosting the type system.- Returns:
- A collection of the selected type.
- See Also:
-
selectFS
Deprecated.Usecas.select(type).asList()
Convenience method to iterator over all feature structures of a given type.- Parameters:
cas
- the CAS containing the type system.type
- the type.- Returns:
- A collection of the selected type.
- See Also:
-
selectAll
Convenience method to iterator over all annotations.- Parameters:
aCas
- the CAS hosting the type system.- Returns:
- A collection of the selected type.
- See Also:
-
select
Convenience method to iterator over all annotations of a given type.- Parameters:
cas
- the CAS containing the type system.type
- the type.- Returns:
- A collection of the selected type.
- See Also:
-
selectAt
Get all annotations of the given type at the specified offsets.- Parameters:
aCas
- the CAS containing the annotations.aType
- the type of annotations to fetch.aBegin
- the begin offset.aEnd
- the end offset.- Returns:
- the annotations at the specified offsets.
-
selectSingleAt
Get the single instance of the specified type from the CAS at the given offsets.- Parameters:
aCas
- the CAS containing the annotations.aType
- the type of annotations to fetch.aBegin
- the begin offset.aEnd
- the end offset.- Returns:
- the single annotation at the specified offsets.
-
selectBetween
Get a list of annotations of the given annotation type located between two annotations. Does not use subiterators and does not respect type priorities. Zero-width annotations what lie on the borders are included in the result, e.g. if the boundary annotations are [1..2] and [2..3] then an annotation [2..2] is returned. If there is a non-zero overlap between the boundary annotations, the result is empty. The method properly handles cases where the second boundary annotations occurs before the first boundary annotation by switching their roles.- Parameters:
type
- a UIMA type.ann1
- the first boundary annotation.ann2
- the second boundary annotation.- Returns:
- a return value.
- See Also:
-
selectBetween
public static List<AnnotationFS> selectBetween(CAS cas, Type type, AnnotationFS ann1, AnnotationFS ann2) Get a list of annotations of the given annotation type located between two annotations. Does not use subiterators and does not respect type priorities. Zero-width annotations what lie on the borders are included in the result, e.g. if the boundary annotations are [1..2] and [2..3] then an annotation [2..2] is returned. If there is a non-zero overlap between the boundary annotations, the result is empty. The method properly handles cases where the second boundary annotations occurs before the first boundary annotation by switching their roles.- Parameters:
cas
- a CAS.type
- a UIMA type.ann1
- the first boundary annotation.ann2
- the second boundary annotation.- Returns:
- a return value.
- See Also:
-
selectCovered
Get a list of annotations of the given annotation type constraint by a certain annotation. Iterates over all annotations of the given type to find the covered annotations. Does not use subiterators and does not respect type prioritites. Was adapted fromSubiterator
. Uses the same approach except that type priorities are ignored.The covering annotation is never returned itself, even if it is of the queried-for type or a subtype of that type.
The method only returns properly covered annotations, that is annotations where the begin/end offsets are equal to the 'covering' annotation or where both the begin/end are included in the span of the 'covering' annotation. Partially overlapping annotations are not returned.
- Parameters:
type
- a UIMA type.coveringAnnotation
- the covering annotation.- Returns:
- a return value.
- See Also:
-
selectCovered
Get a list of annotations of the given annotation type constraint by a certain annotation. Iterates over all annotations of the given type to find the covered annotations. Does not use subiterators and does not respect type prioritites. Was adapted fromSubiterator
. Uses the same approach except that type priorities are ignored.The covering annotation is never returned itself, even if it is of the queried-for type or a subtype of that type.
The method only returns properly covered annotations, that is annotations where the begin/end offsets are equal to the 'covering' annotation or where both the begin/end are included in the span of the 'covering' annotation. Partially overlapping annotations are not returned.
- Parameters:
cas
- a CAS.type
- a UIMA type.coveringAnnotation
- the covering annotation.- Returns:
- a return value.
- See Also:
-
selectCovered
Get a list of annotations of the given annotation type constraint by a certain annotation. Iterates over all annotations of the given type to find the covered annotations. Does not use subiterators and does not respect type prioritites. Was adapted fromSubiterator
. Uses the same approach except that type priorities are ignored.Note: this is significantly slower than using
selectCovered(CAS, Type, AnnotationFS)
. It is possible to useselectCovered(cas, type, new Annotation(jCas, int, int))
, but that will allocate memory in the jCas for the new annotation. If you do that repeatedly many times, memory may fill up.The method only returns properly covered annotations, that is annotations where the begin/end offsets are equal to the given begin/end or where both the begin/end are included in the span of the given span. Partially overlapping annotations are not returned.
- Parameters:
cas
- a CAS.type
- a UIMA type.begin
- begin offset.end
- end offset.- Returns:
- a return value.
- See Also:
-
selectCovering
Get a list of annotations of the given annotation type constraint by a certain annotation. Iterates over all annotations to find the covering annotations.The method only returns properly covering annotations, that is annotations where the begin/end offsets are equal to the begin/end of the given annotation or where given 'covered' annotation is properly contained within the span of the 'covering' annotation. Partially overlapping annotations are not returned.
Note: this is REALLY SLOW! You don't want to use this. Instead, consider using
indexCovering(CAS, Type, Type)
or aContainmentIndex
.- Parameters:
type
- a UIMA type.coveredAnnotation
- the covered annotation.- Returns:
- a return value.
- See Also:
-
selectCovering
Get a list of annotations of the given annotation type constraint by a certain annotation. Iterates over all annotations to find the covering annotations.The method only returns properly covering annotations, that is annotations where the begin/end offsets are equal to the begin/end of the given annotation or where given 'covered' annotation is properly contained within the span of the 'covering' annotation. Partially overlapping annotations are not returned.
Note: this is REALLY SLOW! You don't want to use this. Instead, consider using
indexCovering(CAS, Type, Type)
or aContainmentIndex
.- Parameters:
cas
- a CAS.type
- a UIMA type.coveredAnnotation
- the covered annotation.- Returns:
- a return value.
- See Also:
-
selectCovering
Get a list of annotations of the given annotation type constraint by a certain annotation. Iterates over all annotations to find the covering annotations.The method only returns properly covering annotations, that is annotations where the begin/end offsets are equal to the given begin/end to or where given span is properly contained within the span of the 'covering' annotation. Partially overlapping annotations are not returned.
Note: this is REALLY SLOW! You don't want to use this. Instead, consider using
indexCovering(CAS, Type, Type)
or aContainmentIndex
.- Parameters:
cas
- a CAS.type
- a UIMA type.begin
- begin offset.end
- end offset.- Returns:
- a return value.
- See Also:
-
indexCovering
public static Map<AnnotationFS,List<AnnotationFS>> indexCovering(CAS cas, Type type, Type coveringType) Create an index for quickly lookup up the annotations covering a particular annotation. This is preferable to usingselectCovering(CAS, Type, int, int)
because the overhead of scanning the CAS occurs only when the index is build. Subsequent lookups to the index are fast.The method only returns properly covering annotations, that is annotations where the begin/end offsets are equal to the begin/end of the given annotation or where given 'covered' annotation is properly contained within the span of the 'covering' annotation. Partially overlapping annotations are not returned.
When querying for the annotations covering a given annotation, the given annotation itself is never returned, even if it is of the queried type.
- Parameters:
cas
- a CAS.type
- type to create the index for - this is used in lookups.coveringType
- type of covering annotations.- Returns:
- the index.
- See Also:
-
indexCovered
public static Map<AnnotationFS,List<AnnotationFS>> indexCovered(CAS cas, Type type, Type coveredType) Create an index for quickly lookup up the annotations covered by a particular annotation. This is preferable to usingselectCovered(CAS, Type, int, int)
because the overhead of scanning the CAS occurs only when the index is build. Subsequent lookups to the index are fast. The order of entries in the map is not defined. However, lists of covered annotations in the map are guaranteed to be in the same order as in the UIMA default annotation index.The method only returns properly covered annotations, that is annotations where the begin/end offsets are equal to the 'covering' annotation or where both the begin/end are included in the span of the 'covering' annotation. Partially overlapping annotations are not returned.
When querying for the annotations covered by a given annotation, the given annotation itself is never returned, even if it is of the queried type. *
- Parameters:
cas
- a CAS.type
- type to create the index for - this is used in lookups.coveredType
- type of covering annotations.- Returns:
- the index.
- See Also:
-
selectOverlapping
Get a list of annotations of the given annotation type overlapping the given annotation. Does not use subiterators and does not respect type prioritites.- Parameters:
aType
- a UIMA type.aBoundaryAnnotation
- the covering annotation.- Returns:
- a list of overlapping annotations.
- See Also:
-
selectOverlapping
public static List<AnnotationFS> selectOverlapping(CAS aCas, Type aType, AnnotationFS aBoundaryAnnotation) Get a list of annotations of the given annotation type overlapping the given annotation. Does not use subiterators and does not respect type prioritites.- Parameters:
aCas
- a CAS.aType
- a UIMA type.aBoundaryAnnotation
- the covering annotation.- Returns:
- a list of overlapping annotations.
- See Also:
-
selectOverlapping
public static List<AnnotationFS> selectOverlapping(CAS aCas, Type aType, int aSelBegin, int aSelEnd) Get a list of annotations of the given annotation type overlapping the given span. Does not use subiterators and does not respect type prioritites.- Parameters:
aCas
- a CAS.aType
- a UIMA type.aSelBegin
- begin offset.aSelEnd
- end offset.- Returns:
- a list of overlapping annotations.
- See Also:
-
selectByIndex
This method exists simply as a convenience method for unit testing. It is not very efficient and should not, in general be used outside the context of unit testing.- Parameters:
cas
- a CAS containing the annotation.type
- a UIMA type.index
- this can be either positive (0 corresponds to the first annotation of a type) or negative (-1 corresponds to the last annotation of a type.)- Returns:
- an annotation of the given type
- See Also:
-
selectSingle
Get the single instance of the specified type from the CAS.- Parameters:
cas
- a CAS containing the annotation.type
- a UIMA type.- Returns:
- the single instance of the given type. throws IllegalArgumentException if not exactly one instance if the given type is present.
-
selectSingleFS
Get the single instance of the specified type from the CAS.- Parameters:
cas
- a CAS containing the annotation.type
- a UIMA type.- Returns:
- the single instance of the given type. throws IllegalArgumentException if not exactly one instance if the given type is present.
-
selectSingleRelative
Return an annotation preceding or following of a given reference annotation.- Parameters:
type
- a type.annotation
- anchor annotationindex
- relative position to access. A negative value selects a preceding annotation while a positive number selects a following annotation.- Returns:
- the addressed annotation.
- See Also:
-
selectSingleRelative
public static AnnotationFS selectSingleRelative(CAS cas, Type type, AnnotationFS aAnchor, int aPosition) Return an annotation preceding or following of a given reference annotation. If the type parameter corresponds to the type or a subtype of the anchor annotation and the relative position is 0, then the anchor annotation is returned.- Parameters:
cas
- a CAS containing the annotation.type
- a type.aAnchor
- anchor annotationaPosition
- relative position to access. A negative value selects a preceding annotation while a positive number selects a following annotation.- Returns:
- the addressed annotation.
- Throws:
IndexOutOfBoundsException
- if the relative position points beyond the type index bounds.IllegalArgumentException
- if the relative position is0
and the anchor type does not subsume the selected type.- See Also:
-
selectPreceding
public static List<AnnotationFS> selectPreceding(CAS cas, Type type, AnnotationFS anchor, int count) Returns the n annotations preceding the given annotation- Parameters:
cas
- a CAS.type
- a UIMA type.anchor
- anchor annotationcount
- number of annotations to collect- Returns:
- List of aType annotations preceding anchor annotation
- See Also:
-
selectFollowing
public static List<AnnotationFS> selectFollowing(CAS cas, Type type, AnnotationFS anchor, int count) Returns the n annotations following the given annotation- Parameters:
cas
- a CAS.type
- a UIMA type.anchor
- anchor annotationcount
- number of annotations to collect- Returns:
- List of aType annotations following anchor annotation
- See Also:
-
exists
Test if a CAS contains an annotation of the given type.- Type Parameters:
T
- the annotation type.- Parameters:
aCas
- a CAS.aType
- a annotation type.- Returns:
true
if there is at least one annotation of the given type in the CAS.
-
getView
Convenience method to get the specified view or a default view if the requested view does not exist. The default can also benull
.- Parameters:
cas
- a CASviewName
- the requested view.fallback
- the default view if the requested view does not exist.- Returns:
- the requested view or the default if the requested view does not exist.
-
getView
Convenience method to get the specified view or create a new view if the requested view does not exist.- Parameters:
cas
- a CASviewName
- the requested view.create
- the view is created if it does not exist.- Returns:
- the requested view
- Throws:
IllegalArgumentException
- if the view does not exist and is not to be created.
-
toText
Fetch the text covered by the specified annotations and return it as a list of strings.- Type Parameters:
T
- UIMA JCas type.- Parameters:
iterable
- annotation container.- Returns:
- list of covered strings.
-
toText
Fetch the text covered by the specified annotations and return it as a list of strings.- Type Parameters:
T
- UIMA JCas type.- Parameters:
iterator
- annotation iterator.- Returns:
- list of covered strings.
-
isAnnotationType
-
requireAnnotationType
-
cas.select(type).iterator()