public final class CasUtil extends Object
CAS
.Modifier and Type | Field and Description |
---|---|
static String |
UIMA_BUILTIN_JCAS_PREFIX
Package name of JCas wrapper classes built into UIMA.
|
Modifier and Type | Method and Description |
---|---|
static org.apache.uima.cas.Type |
getAnnotationType(org.apache.uima.cas.CAS aCas,
Class<?> aJCasClass)
Get the CAS type for the given JCas wrapper class making sure it is or inherits from
Annotation . |
static org.apache.uima.cas.Type |
getAnnotationType(org.apache.uima.cas.CAS aCas,
String aTypeName)
Get the CAS type for the given name making sure it is or inherits from Annotation.
|
static org.apache.uima.cas.Type |
getType(org.apache.uima.cas.CAS cas,
Class<?> type)
Get the CAS type for the given JCas wrapper class.
|
static org.apache.uima.cas.Type |
getType(org.apache.uima.cas.CAS aCas,
String aTypename)
Get the CAS type for the given name.
|
static org.apache.uima.cas.CAS |
getView(org.apache.uima.cas.CAS cas,
String viewName,
boolean create)
Convenience method to get the specified view or create a new view if the requested view does
not exist.
|
static org.apache.uima.cas.CAS |
getView(org.apache.uima.cas.CAS cas,
String viewName,
org.apache.uima.cas.CAS fallback)
Convenience method to get the specified view or a default view if the requested view does not
exist.
|
static Map<org.apache.uima.cas.text.AnnotationFS,Collection<org.apache.uima.cas.text.AnnotationFS>> |
indexCovered(org.apache.uima.cas.CAS cas,
org.apache.uima.cas.Type type,
org.apache.uima.cas.Type coveredType)
Create an index for quickly lookup up the annotations covered by a particular annotation.
|
static Map<org.apache.uima.cas.text.AnnotationFS,Collection<org.apache.uima.cas.text.AnnotationFS>> |
indexCovering(org.apache.uima.cas.CAS cas,
org.apache.uima.cas.Type type,
org.apache.uima.cas.Type coveringType)
Create an index for quickly lookup up the annotations covering a particular annotation.
|
static <T extends org.apache.uima.cas.text.AnnotationFS> |
iterator(org.apache.uima.cas.CAS cas,
org.apache.uima.cas.Type type)
Get an iterator over the given annotation type.
|
static <T extends org.apache.uima.cas.FeatureStructure> |
iteratorFS(org.apache.uima.cas.CAS cas,
org.apache.uima.cas.Type type)
Get an iterator over the given feature structures type.
|
static Collection<org.apache.uima.cas.text.AnnotationFS> |
select(org.apache.uima.cas.ArrayFS array,
org.apache.uima.cas.Type type)
Convenience method to iterator over all annotations of a given type.
|
static Collection<org.apache.uima.cas.text.AnnotationFS> |
select(org.apache.uima.cas.CAS cas,
org.apache.uima.cas.Type type)
Convenience method to iterator over all annotations of a given type.
|
static Collection<org.apache.uima.cas.text.AnnotationFS> |
selectAll(org.apache.uima.cas.CAS aCas)
Convenience method to iterator over all annotations.
|
static Collection<org.apache.uima.cas.FeatureStructure> |
selectAllFS(org.apache.uima.cas.CAS aCas)
Convenience method to iterator over all features structures.
|
static List<org.apache.uima.cas.text.AnnotationFS> |
selectBetween(org.apache.uima.cas.CAS cas,
org.apache.uima.cas.Type type,
org.apache.uima.cas.text.AnnotationFS ann1,
org.apache.uima.cas.text.AnnotationFS ann2)
Get a list of annotations of the given annotation type located between two annotations.
|
static List<org.apache.uima.cas.text.AnnotationFS> |
selectBetween(org.apache.uima.cas.Type type,
org.apache.uima.cas.text.AnnotationFS ann1,
org.apache.uima.cas.text.AnnotationFS ann2)
Get a list of annotations of the given annotation type located between two annotations.
|
static org.apache.uima.cas.text.AnnotationFS |
selectByIndex(org.apache.uima.cas.CAS cas,
org.apache.uima.cas.Type type,
int index)
This method exists simply as a convenience method for unit testing.
|
static List<org.apache.uima.cas.text.AnnotationFS> |
selectCovered(org.apache.uima.cas.CAS cas,
org.apache.uima.cas.Type type,
org.apache.uima.cas.text.AnnotationFS coveringAnnotation)
Get a list of annotations of the given annotation type constraint by a certain annotation.
|
static List<org.apache.uima.cas.text.AnnotationFS> |
selectCovered(org.apache.uima.cas.CAS cas,
org.apache.uima.cas.Type type,
int begin,
int end)
Get a list of annotations of the given annotation type constraint by a certain annotation.
|
static List<org.apache.uima.cas.text.AnnotationFS> |
selectCovered(org.apache.uima.cas.Type type,
org.apache.uima.cas.text.AnnotationFS coveringAnnotation)
Get a list of annotations of the given annotation type constraint by a certain annotation.
|
static List<org.apache.uima.cas.text.AnnotationFS> |
selectCovering(org.apache.uima.cas.CAS cas,
org.apache.uima.cas.Type type,
org.apache.uima.cas.text.AnnotationFS coveredAnnotation)
Get a list of annotations of the given annotation type constraint by a certain annotation.
|
static List<org.apache.uima.cas.text.AnnotationFS> |
selectCovering(org.apache.uima.cas.CAS cas,
org.apache.uima.cas.Type type,
int begin,
int end)
Get a list of annotations of the given annotation type constraint by a certain annotation.
|
static List<org.apache.uima.cas.text.AnnotationFS> |
selectCovering(org.apache.uima.cas.Type type,
org.apache.uima.cas.text.AnnotationFS coveredAnnotation)
Get a list of annotations of the given annotation type constraint by a certain annotation.
|
static List<org.apache.uima.cas.text.AnnotationFS> |
selectFollowing(org.apache.uima.cas.CAS cas,
org.apache.uima.cas.Type type,
org.apache.uima.cas.text.AnnotationFS annotation,
int count)
Returns the n annotations following the given annotation
|
static Collection<org.apache.uima.cas.FeatureStructure> |
selectFS(org.apache.uima.cas.ArrayFS array,
org.apache.uima.cas.Type type)
Convenience method to iterator over all feature structures of a given type.
|
static Collection<org.apache.uima.cas.FeatureStructure> |
selectFS(org.apache.uima.cas.CAS cas,
org.apache.uima.cas.Type type)
Convenience method to iterator over all feature structures of a given type.
|
static List<org.apache.uima.cas.text.AnnotationFS> |
selectPreceding(org.apache.uima.cas.CAS cas,
org.apache.uima.cas.Type type,
org.apache.uima.cas.text.AnnotationFS annotation,
int count)
Returns the n annotations preceding the given annotation
|
static org.apache.uima.cas.FeatureStructure |
selectSingle(org.apache.uima.cas.CAS cas,
org.apache.uima.cas.Type type)
Get the single instance of the specified type from the JCas.
|
static org.apache.uima.cas.text.AnnotationFS |
selectSingleRelative(org.apache.uima.cas.CAS cas,
org.apache.uima.cas.Type type,
org.apache.uima.cas.text.AnnotationFS annotation,
int index)
Return an annotation preceding or following of a given reference annotation.
|
static org.apache.uima.cas.text.AnnotationFS |
selectSingleRelative(org.apache.uima.cas.Type type,
org.apache.uima.cas.text.AnnotationFS annotation,
int index)
Return an annotation preceding or following of a given reference annotation.
|
static <T extends org.apache.uima.cas.text.AnnotationFS> |
toText(Iterable<T> iterable)
Fetch the text covered by the specified annotations and return it as a list of strings.
|
static <T extends org.apache.uima.cas.text.AnnotationFS> |
toText(Iterator<T> iterator)
Fetch the text covered by the specified annotations and return it as a list of strings.
|
public static final String UIMA_BUILTIN_JCAS_PREFIX
public static <T extends org.apache.uima.cas.FeatureStructure> Iterator<T> iteratorFS(org.apache.uima.cas.CAS cas, org.apache.uima.cas.Type type)
T
- the JCas type.cas
- a CAS.type
- a type.public static <T extends org.apache.uima.cas.text.AnnotationFS> Iterator<T> iterator(org.apache.uima.cas.CAS cas, org.apache.uima.cas.Type type)
T
- the JCas type.cas
- a CAS.type
- a type.public static org.apache.uima.cas.Type getType(org.apache.uima.cas.CAS cas, Class<?> type)
cas
- the CAS hosting the type system.type
- the JCas wrapper class.public static org.apache.uima.cas.Type getType(org.apache.uima.cas.CAS aCas, String aTypename)
aCas
- the CAS hosting the type system.aTypename
- the fully qualified type name.public static org.apache.uima.cas.Type getAnnotationType(org.apache.uima.cas.CAS aCas, Class<?> aJCasClass)
Annotation
.aCas
- the CAS hosting the type system.aJCasClass
- the JCas wrapper class.public static org.apache.uima.cas.Type getAnnotationType(org.apache.uima.cas.CAS aCas, String aTypeName)
aCas
- the CAS hosting the type system.aTypeName
- the fully qualified type name.public static Collection<org.apache.uima.cas.FeatureStructure> selectFS(org.apache.uima.cas.ArrayFS array, org.apache.uima.cas.Type type)
array
- features structure array.type
- the type.public static Collection<org.apache.uima.cas.text.AnnotationFS> select(org.apache.uima.cas.ArrayFS array, org.apache.uima.cas.Type type)
array
- features structure array.type
- the type.public static Collection<org.apache.uima.cas.FeatureStructure> selectAllFS(org.apache.uima.cas.CAS aCas)
aCas
- the CAS hosting the type system.public static Collection<org.apache.uima.cas.FeatureStructure> selectFS(org.apache.uima.cas.CAS cas, org.apache.uima.cas.Type type)
cas
- the CAS containing the type system.type
- the type.public static Collection<org.apache.uima.cas.text.AnnotationFS> selectAll(org.apache.uima.cas.CAS aCas)
aCas
- the CAS hosting the type system.public static Collection<org.apache.uima.cas.text.AnnotationFS> select(org.apache.uima.cas.CAS cas, org.apache.uima.cas.Type type)
cas
- the CAS containing the type system.type
- the type.public static List<org.apache.uima.cas.text.AnnotationFS> selectBetween(org.apache.uima.cas.Type type, org.apache.uima.cas.text.AnnotationFS ann1, org.apache.uima.cas.text.AnnotationFS ann2)
type
- a UIMA type.ann1
- the first boundary annotation.ann2
- the second boundary annotation.Subiterator
,
Order of selected feature structurespublic static List<org.apache.uima.cas.text.AnnotationFS> selectBetween(org.apache.uima.cas.CAS cas, org.apache.uima.cas.Type type, org.apache.uima.cas.text.AnnotationFS ann1, org.apache.uima.cas.text.AnnotationFS ann2)
cas
- a CAS.type
- a UIMA type.ann1
- the first boundary annotation.ann2
- the second boundary annotation.Subiterator
,
Order of selected feature structurespublic static List<org.apache.uima.cas.text.AnnotationFS> selectCovered(org.apache.uima.cas.Type type, org.apache.uima.cas.text.AnnotationFS coveringAnnotation)
Subiterator
. Uses
the same approach except that type priorities are ignored.type
- a UIMA type.coveringAnnotation
- the covering annotation.Subiterator
,
Order of selected feature structurespublic static List<org.apache.uima.cas.text.AnnotationFS> selectCovered(org.apache.uima.cas.CAS cas, org.apache.uima.cas.Type type, org.apache.uima.cas.text.AnnotationFS coveringAnnotation)
Subiterator
. Uses
the same approach except that type priorities are ignored.cas
- a CAS.type
- a UIMA type.coveringAnnotation
- the covering annotation.Subiterator
,
Order of selected feature structurespublic static List<org.apache.uima.cas.text.AnnotationFS> selectCovered(org.apache.uima.cas.CAS cas, org.apache.uima.cas.Type type, int begin, int end)
Subiterator
. 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 use
selectCovered(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.
cas
- a CAS.type
- a UIMA type.begin
- begin offset.end
- end offset.Subiterator
,
Order of selected feature structurespublic static List<org.apache.uima.cas.text.AnnotationFS> selectCovering(org.apache.uima.cas.Type type, org.apache.uima.cas.text.AnnotationFS coveredAnnotation)
Note: this is REALLY SLOW! You don't want to use this. Instead, consider using
indexCovering(CAS, Type, Type)
or a ContainmentIndex
.
type
- a UIMA type.coveredAnnotation
- the covered annotation.public static List<org.apache.uima.cas.text.AnnotationFS> selectCovering(org.apache.uima.cas.CAS cas, org.apache.uima.cas.Type type, org.apache.uima.cas.text.AnnotationFS coveredAnnotation)
Note: this is REALLY SLOW! You don't want to use this. Instead, consider using
indexCovering(CAS, Type, Type)
or a ContainmentIndex
.
cas
- a CAS.type
- a UIMA type.coveredAnnotation
- the covered annotation.public static List<org.apache.uima.cas.text.AnnotationFS> selectCovering(org.apache.uima.cas.CAS cas, org.apache.uima.cas.Type type, int begin, int end)
Note: this is REALLY SLOW! You don't want to use this. Instead, consider using
indexCovering(CAS, Type, Type)
or a ContainmentIndex
.
cas
- a CAS.type
- a UIMA type.begin
- begin offset.end
- end offset.public static Map<org.apache.uima.cas.text.AnnotationFS,Collection<org.apache.uima.cas.text.AnnotationFS>> indexCovering(org.apache.uima.cas.CAS cas, org.apache.uima.cas.Type type, org.apache.uima.cas.Type coveringType)
selectCovering(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.cas
- a CAS.type
- type to create the index for - this is used in lookups.coveringType
- type of covering annotations.public static Map<org.apache.uima.cas.text.AnnotationFS,Collection<org.apache.uima.cas.text.AnnotationFS>> indexCovered(org.apache.uima.cas.CAS cas, org.apache.uima.cas.Type type, org.apache.uima.cas.Type coveredType)
selectCovered(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.cas
- a CAS.type
- type to create the index for - this is used in lookups.coveredType
- type of covering annotations.public static org.apache.uima.cas.text.AnnotationFS selectByIndex(org.apache.uima.cas.CAS cas, org.apache.uima.cas.Type type, int index)
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.)public static org.apache.uima.cas.FeatureStructure selectSingle(org.apache.uima.cas.CAS cas, org.apache.uima.cas.Type type)
cas
- a CAS containing the annotation.type
- a UIMA type.public static org.apache.uima.cas.text.AnnotationFS selectSingleRelative(org.apache.uima.cas.Type type, org.apache.uima.cas.text.AnnotationFS annotation, int index)
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.public static org.apache.uima.cas.text.AnnotationFS selectSingleRelative(org.apache.uima.cas.CAS cas, org.apache.uima.cas.Type type, org.apache.uima.cas.text.AnnotationFS annotation, int index)
cas
- a CAS containing the annotation.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.IndexOutOfBoundsException
- if the relative index points beyond the type index bounds.public static List<org.apache.uima.cas.text.AnnotationFS> selectPreceding(org.apache.uima.cas.CAS cas, org.apache.uima.cas.Type type, org.apache.uima.cas.text.AnnotationFS annotation, int count)
cas
- a CAS.type
- a UIMA type.annotation
- anchor annotationcount
- number of annotations to collectpublic static List<org.apache.uima.cas.text.AnnotationFS> selectFollowing(org.apache.uima.cas.CAS cas, org.apache.uima.cas.Type type, org.apache.uima.cas.text.AnnotationFS annotation, int count)
cas
- a CAS.type
- a UIMA type.annotation
- anchor annotationcount
- number of annotations to collectpublic static org.apache.uima.cas.CAS getView(org.apache.uima.cas.CAS cas, String viewName, org.apache.uima.cas.CAS fallback)
null
.cas
- a CASviewName
- the requested view.fallback
- the default view if the requested view does not exist.public static org.apache.uima.cas.CAS getView(org.apache.uima.cas.CAS cas, String viewName, boolean create)
cas
- a CASviewName
- the requested view.create
- the view is created if it does not exist.IllegalArgumentException
- if the view does not exist and is not to be created.public static <T extends org.apache.uima.cas.text.AnnotationFS> List<String> toText(Iterable<T> iterable)
T
- UIMA JCas type.iterable
- annotation container.public static <T extends org.apache.uima.cas.text.AnnotationFS> List<String> toText(Iterator<T> iterator)
T
- UIMA JCas type.iterator
- annotation iterator.Copyright © 2012–2014 The Apache Software Foundation. All rights reserved.