Interface CAS
- All Superinterfaces:
AbstractCas
- All Known Implementing Classes:
CASImpl
A CAS
object provides the starting point for working with the CAS. It provides
access to the type system, to indexes, iterators and filters (constraints). It also lets you
create new annotations and other data structures. You can create a CAS
object using
static methods on the class CasCreationUtils
.
The CAS
object is also the container that manages multiple Subjects of Analysis or
Sofas. A Sofa represents some form of an unstructured artifact that is processed in a UIMA
pipeline. The Java string called the "DocumentText" used in a UIMA text processing pipeline is an
example of a Sofa. A Sofa can be analyzed independently using the standard UIMA programming model
or analyzed together with other Sofas utilizing the Sofa programming model extensions.
A Sofa is implemented as a built-in CAS type uima.cas.Sofa. Use
CAS.createSofa()
to instantiate a Sofa feature
structure. The SofaFS
class provides methods to set and get the features of a
SofaFS. Although Sofas are implemented as standard feature structures, generic CAS APIs must
never be used to create Sofas or set their features.
Use getView(String)
or
getView(SofaFS)
to obtain a view of a particular Sofa in the CAS.
This view will provide access to the Sofa data (for example the document text) as well as the
index repository, which contains metadata (annotations and other feature structures) about that
Sofa.
Use getTypeSystem()
to access the type system. With a TypeSystem
object, you can access the Type
and Feature
objects for
the CAS built-in types. Note that this interface also provides constants for the names of the
built-in types and features.
-
Field Summary
Modifier and TypeFieldDescriptionstatic final String
static final String
Base name of annotation begin feature.static final String
Base name of annotation end feature.static final String
Base name of FSArrayList fsArray feature.static final String
Base name of list head feature.static final String
Base name of FSArrayList fsArray feature.static final String
Base name of document language feature.static final String
Sofa ID feature that is the handle to a text Sofa.static final String
Base name of Sofa array fs data feature.static final String
Base name of Sofa ID feature.static final String
Base name of Sofa mime type feature.static final String
Base name of Sofa Number feature.static final String
Base name of Sofa string data feature.static final String
Base name of Sofa URI feature.static final String
Base name of list tail feature.static final String
Fully qualified name of annotation begin feature.static final String
Fully qualified name of annotation end feature.static final String
Qualified name of float list head feature.static final String
Qualified name of float list tail feature.static final String
Qualified name of fs list head feature.static final String
Qualified name of fs list tail feature.static final String
Qualified name of integer list head feature.static final String
Qualified name of integer list tail feature.static final String
Fully qualified name of document language feature.static final String
Fully qualified name of annotation sofa feature.static final String
Qualified name of Sofa array fs data feature.static final String
Qualified name of Sofa id feature.static final String
Qualified name of Sofa mime type feature.static final String
Qualified name of Sofa number feature.static final String
Qualified name of Sofa string data feature.static final String
Qualified name of Sofa URI feature.static final String
Qualified name of string list head feature.static final String
Qualified name of string list tail feature.static final String
Sofa name for the initial view's sofa.static final String
Deprecated.static final String
UIMA CAS name space.static final String
Name of Text CAS name space.static final String
Sofa Index name.static final String
Name of the built-in index on annotations.static final String
Name of annotation type.static final String
Name of annotation base type.static final String
ArrayBase type.static final String
Boolean type.static final String
Boolean array type.static final String
Byte type.static final String
Byte array type.static final String
Name of document annotation type.static final String
Double type.static final String
Double array type.static final String
Empty float type.static final String
Empty feature structure list type.static final String
Empty integer list type.static final String
Empty string list type.static final String
Float type.static final String
Float array type.static final String
Float list type.static final String
Feature structure array type.static final String
Feature structure list type.static final String
Integer type.static final String
Integer array type.static final String
Integer list type.static final String
Abstract list base type.static final String
Long type.static final String
Long array type.static final String
Non-empty float list type.static final String
Non-empty feature structure list type.static final String
Non-empty integer list type.static final String
Non-empty string list type.static final String
Short type.static final String
Short array type.static final String
Sofa type.static final String
String type.static final String
String array type.static final String
String list type.static final String
Top type.static final String
UIMA CAS name space prefix to prepend to type names (adds an extra period to the name space proper.static final String
UIMA TCAS name space prefix to prepend to type names (adds an extra period to the name space proper. -
Method Summary
Modifier and TypeMethodDescriptionvoid
Add a feature structure to all appropriate indexes in the repository associated with this CAS View.<T extends AnnotationFS>
AnnotationFScreateAnnotation
(Type type, int begin, int end) Create a new annotation.createArrayFS
(int length) Create a new feature structure array.createBooleanArrayFS
(int length) Create a new Boolean array.createByteArrayFS
(int length) Create a new Byte array.createDoubleArrayFS
(int length) Create a new Double array.Create a feature path.createFeatureValuePath
(String featureValuePath) Create a feature-value path from a string.<T extends FeatureStructure>
FSIterator<T>createFilteredIterator
(FSIterator<T> it, FSMatchConstraint cons) Create an iterator over structures satisfying a given constraint.createFloatArrayFS
(int length) Create a new int array.<T extends FeatureStructure>
TCreate a new FeatureStructure.createIntArrayFS
(int length) Create a new int array.createLongArrayFS
(int length) Create a new Long array.Sets a mark and returns the marker object set with the current mark which can be used to query when certain FSs were created.createShortArrayFS
(int length) Create a new Short array.createSofa
(SofaID sofaID, String mimeType) Deprecated.As of v2.0, usecreateView(String)
instead.createStringArrayFS
(int length) Create a new String array.createView
(String localViewName) Create a view and its underlying Sofa (subject of analysis).default <T extends TOP>
CommonArrayFS<T>emptyArray
(Class<T> clazz) default BooleanArray
default ByteArray
default DoubleArray
default FloatArray
default EmptyFloatList
default <T extends FeatureStructure>
FSArray<T>default <T extends FeatureStructure>
FSArray<T>emptyFSArray
(Type type) default <T extends TOP>
EmptyFSList<T>default IntegerArray
default EmptyIntegerList
default LongArray
default ShortArray
default StringArray
default EmptyStringList
<T extends FeatureStructure>
ListIterator<T>fs2listIterator
(FSIterator<T> it) Wrap a standard JavaListIterator
around an FSListIterator.default <T extends TOP>
FSIterator<T>getAllIndexedFS
(Class<T> clazz) Gets an iterator over all indexed (in this CAS view) FeatureStructures of the specified Type (and any of its subtypes).default <T extends TOP>
FSIterator<T>getAllIndexedFS
(Type type) Gets an iterator over all indexed (in this CAS view) FeatureStructures of the specified Type (and any of its subtypes).<T extends AnnotationFS>
AnnotationIndex<T>Get the standard annotation index.default <T extends AnnotationFS>
AnnotationIndex<T>getAnnotationIndex
(Class<T> clazz) Get the standard annotation index restricted to a specific annotation type.<T extends AnnotationFS>
AnnotationIndex<T>getAnnotationIndex
(Type type) Get the standard annotation index restricted to a specific annotation type.Get the type object for the annotation type.Get the feature object for the annotation begin feature.getCasType
(Class<T> clazz) Get a constraint factory.Get the Cas view that the current component should use.<T extends AnnotationFS>
TGet the Document Annotation.Gets the language code for this document from the language feature of the special instance of the DocumentationAnnotation associated with this CAS.Get the document text.Get the feature object for the annotation end feature.default Collection<TOP>
Returns an unmodifiable collection of all of the FSs that are indexed in this view, in an arbitrary order.default <T extends TOP>
Collection<T>getIndexedFSs
(Class<T> clazz) Returns a collection of all the FSs that are indexed in this view, in an arbitrary order.default <T extends TOP>
Collection<T>getIndexedFSs
(Type type) Returns an unmodifiable collection of all the FSs that are indexed in this view, in an arbitrary order.Get the index repository.getJCas()
Get the JCas view for this CAS viewCreate a JCas view for a Sofa.Deprecated.As of v2.0, usegetView(String)
followed bygetJCas()
.default JCasImpl
Get the JCasImpl view for this CAS viewGet an instance of the low-level CAS.getSofa()
Get the Sofa feature structure associated with this CAS view.Deprecated.As of v2.0, use {#getView(String)}.Get the Sofa data array.Get the Sofa data as a byte stream.Get the Sofa Data String (a.k.a.Get the Sofa data array.<T extends SofaFS>
FSIterator<T>Get iterator for all SofaFS in the CAS.Get the mime type of the Sofa data being analyzed.Return the type system of this CAS instance.Get the view for a Sofa (subject of analysis).Get the view for a Sofa (subject of analysis).Get iterator over all views in this CAS.getViewIterator
(String localViewNamePrefix) Get iterator over all views with the given name prefix.Get the view name.Call this method to set up a region, ended by aAutoCloseable.close()
call on the returned object, You can use this or theprotectIndexes(Runnable)
method to protected the indexes.void
protectIndexes
(Runnable runnable) Runs the code in the runnable inside a protection block, where any modifications to features done while in this block will be done in a way to protect any indexes which otherwise might become corrupted by the update action; the protection is achieved by temporarily removing the FS (if it is in the indexes), before the update happens.void
Remove a feature structure from all indexes in the repository associated with this CAS View.void
reset()
Reset the CAS, emptying it of all content.select()
select
(int jcasType) void
Informs the CAS of relevant information about the component that is currently processing it.void
setDocumentLanguage
(String languageCode) Sets the language for this document.void
setDocumentText
(String text) Set the document text.void
setSofaDataArray
(FeatureStructure array, String mime) Set the Sofa data as an ArrayFS.void
setSofaDataString
(String text, String mimetype) Set the document text.void
setSofaDataURI
(String uri, String mime) Set the Sofa data as a URI.int
size()
Estimate the memory consumption of this CAS instance (in bytes).Methods inherited from interface org.apache.uima.cas.AbstractCas
release
-
Field Details
-
NAME_SPACE_UIMA_CAS
UIMA CAS name space.- See Also:
-
UIMA_CAS_PREFIX
UIMA CAS name space prefix to prepend to type names (adds an extra period to the name space proper.- See Also:
-
TYPE_NAME_TOP
Top type.- See Also:
-
TYPE_NAME_INTEGER
Integer type.- See Also:
-
TYPE_NAME_FLOAT
Float type.- See Also:
-
TYPE_NAME_STRING
String type.- See Also:
-
TYPE_NAME_BOOLEAN
Boolean type.- See Also:
-
TYPE_NAME_BYTE
Byte type.- See Also:
-
TYPE_NAME_SHORT
Short type.- See Also:
-
TYPE_NAME_LONG
Long type.- See Also:
-
TYPE_NAME_DOUBLE
Double type.- See Also:
-
TYPE_NAME_ARRAY_BASE
ArrayBase type.- See Also:
-
TYPE_NAME_FS_ARRAY
Feature structure array type.- See Also:
-
TYPE_NAME_INTEGER_ARRAY
Integer array type.- See Also:
-
TYPE_NAME_FLOAT_ARRAY
Float array type.- See Also:
-
TYPE_NAME_STRING_ARRAY
String array type.- See Also:
-
TYPE_NAME_BOOLEAN_ARRAY
Boolean array type.- See Also:
-
TYPE_NAME_BYTE_ARRAY
Byte array type.- See Also:
-
TYPE_NAME_SHORT_ARRAY
Short array type.- See Also:
-
TYPE_NAME_LONG_ARRAY
Long array type.- See Also:
-
TYPE_NAME_DOUBLE_ARRAY
Double array type.- See Also:
-
TYPE_NAME_SOFA
Sofa type.- See Also:
-
TYPE_NAME_ANNOTATION_BASE
Name of annotation base type.- See Also:
-
FEATURE_BASE_NAME_SOFANUM
Base name of Sofa Number feature.- See Also:
-
FEATURE_BASE_NAME_SOFAID
Base name of Sofa ID feature.- See Also:
-
FEATURE_BASE_NAME_SOFAMIME
Base name of Sofa mime type feature.- See Also:
-
FEATURE_BASE_NAME_SOFAURI
Base name of Sofa URI feature.- See Also:
-
FEATURE_BASE_NAME_SOFASTRING
Base name of Sofa string data feature.- See Also:
-
FEATURE_BASE_NAME_SOFAARRAY
Base name of Sofa array fs data feature.- See Also:
-
FEATURE_BASE_NAME_FS_ARRAY
Base name of FSArrayList fsArray feature. Base name of FSHashSet fsArray feature.- See Also:
-
FEATURE_BASE_NAME_INT_ARRAY
Base name of FSArrayList fsArray feature.- See Also:
-
FEATURE_FULL_NAME_SOFANUM
Qualified name of Sofa number feature.- See Also:
-
FEATURE_FULL_NAME_SOFAID
Qualified name of Sofa id feature.- See Also:
-
FEATURE_FULL_NAME_SOFAMIME
Qualified name of Sofa mime type feature.- See Also:
-
FEATURE_FULL_NAME_SOFAURI
Qualified name of Sofa URI feature.- See Also:
-
FEATURE_FULL_NAME_SOFASTRING
Qualified name of Sofa string data feature.- See Also:
-
FEATURE_FULL_NAME_SOFAARRAY
Qualified name of Sofa array fs data feature.- See Also:
-
SOFA_INDEX_NAME
Sofa Index name.- See Also:
-
NAME_DEFAULT_TEXT_SOFA
Deprecated.As of v2.0, this is replaced byNAME_DEFAULT_SOFA
, and the value has changed. In general, user code should not need to refer to this name.Sofa name for the default text sofa.- See Also:
-
NAME_DEFAULT_SOFA
Sofa name for the initial view's sofa.- See Also:
-
TYPE_NAME_LIST_BASE
Abstract list base type.- See Also:
-
TYPE_NAME_FS_LIST
Feature structure list type.- See Also:
-
TYPE_NAME_NON_EMPTY_FS_LIST
Non-empty feature structure list type.- See Also:
-
TYPE_NAME_EMPTY_FS_LIST
Empty feature structure list type.- See Also:
-
TYPE_NAME_INTEGER_LIST
Integer list type.- See Also:
-
TYPE_NAME_NON_EMPTY_INTEGER_LIST
Non-empty integer list type.- See Also:
-
TYPE_NAME_EMPTY_INTEGER_LIST
Empty integer list type.- See Also:
-
TYPE_NAME_FLOAT_LIST
Float list type.- See Also:
-
TYPE_NAME_NON_EMPTY_FLOAT_LIST
Non-empty float list type.- See Also:
-
TYPE_NAME_EMPTY_FLOAT_LIST
Empty float type.- See Also:
-
TYPE_NAME_STRING_LIST
String list type.- See Also:
-
TYPE_NAME_NON_EMPTY_STRING_LIST
Non-empty string list type.- See Also:
-
TYPE_NAME_EMPTY_STRING_LIST
Empty string list type.- See Also:
-
FEATURE_BASE_NAME_HEAD
Base name of list head feature.- See Also:
-
FEATURE_BASE_NAME_TAIL
Base name of list tail feature.- See Also:
-
FEATURE_FULL_NAME_FS_LIST_HEAD
Qualified name of fs list head feature.- See Also:
-
FEATURE_FULL_NAME_INTEGER_LIST_HEAD
Qualified name of integer list head feature.- See Also:
-
FEATURE_FULL_NAME_FLOAT_LIST_HEAD
Qualified name of float list head feature.- See Also:
-
FEATURE_FULL_NAME_STRING_LIST_HEAD
Qualified name of string list head feature.- See Also:
-
FEATURE_FULL_NAME_FS_LIST_TAIL
Qualified name of fs list tail feature.- See Also:
-
FEATURE_FULL_NAME_INTEGER_LIST_TAIL
Qualified name of integer list tail feature.- See Also:
-
FEATURE_FULL_NAME_FLOAT_LIST_TAIL
Qualified name of float list tail feature.- See Also:
-
FEATURE_FULL_NAME_STRING_LIST_TAIL
Qualified name of string list tail feature.- See Also:
-
NAME_SPACE_UIMA_TCAS
Name of Text CAS name space.- See Also:
-
UIMA_TCAS_PREFIX
UIMA TCAS name space prefix to prepend to type names (adds an extra period to the name space proper.- See Also:
-
TYPE_NAME_ANNOTATION
Name of annotation type.- See Also:
-
TYPE_NAME_DOCUMENT_ANNOTATION
Name of document annotation type.- See Also:
-
FEATURE_BASE_NAME_SOFA
Sofa ID feature that is the handle to a text Sofa.- See Also:
-
FEATURE_BASE_NAME_BEGIN
Base name of annotation begin feature.- See Also:
-
FEATURE_BASE_NAME_END
Base name of annotation end feature.- See Also:
-
FEATURE_BASE_NAME_LANGUAGE
Base name of document language feature.- See Also:
-
FEATURE_FULL_NAME_BEGIN
Fully qualified name of annotation begin feature.- See Also:
-
FEATURE_FULL_NAME_SOFA
Fully qualified name of annotation sofa feature.- See Also:
-
FEATURE_FULL_NAME_END
Fully qualified name of annotation end feature.- See Also:
-
FEATURE_FULL_NAME_LANGUAGE
Fully qualified name of document language feature.- See Also:
-
STD_ANNOTATION_INDEX
Name of the built-in index on annotations.- See Also:
-
DEFAULT_LANGUAGE_NAME
- See Also:
-
-
Method Details
-
createFS
Create a new FeatureStructure.- Type Parameters:
T
- the Java cover class for the FS being created- Parameters:
type
- The type of the FS.- Returns:
- The new FS.
- Throws:
CASRuntimeException
-
createArrayFS
Create a new feature structure array.- Parameters:
length
- The length of the array.- Returns:
- The new array.
- Throws:
CASRuntimeException
-
createIntArrayFS
Create a new int array.- Parameters:
length
- The length of the array.- Returns:
- The new array.
- Throws:
CASRuntimeException
-
createFloatArrayFS
Create a new int array.- Parameters:
length
- The length of the array.- Returns:
- The new array.
- Throws:
CASRuntimeException
-
createStringArrayFS
Create a new String array.- Parameters:
length
- The length of the array.- Returns:
- The new array.
- Throws:
CASRuntimeException
-
createByteArrayFS
Create a new Byte array.- Parameters:
length
- The length of the array.- Returns:
- The new array.
- Throws:
CASRuntimeException
-
createBooleanArrayFS
Create a new Boolean array.- Parameters:
length
- The length of the array.- Returns:
- The new array.
- Throws:
CASRuntimeException
-
createShortArrayFS
Create a new Short array.- Parameters:
length
- The length of the array.- Returns:
- The new array.
- Throws:
CASRuntimeException
-
createLongArrayFS
Create a new Long array.- Parameters:
length
- The length of the array.- Returns:
- The new array.
- Throws:
CASRuntimeException
-
createDoubleArrayFS
Create a new Double array.- Parameters:
length
- The length of the array.- Returns:
- The new array.
- Throws:
CASRuntimeException
-
getJCas
Get the JCas view for this CAS view- Returns:
- The JCas view for this CAS view
- Throws:
CASException
- not thrown in v3, but kept for backwards compatibility
-
getJCasImpl
Get the JCasImpl view for this CAS view- Returns:
- the JCasImpl view for this CAS view
-
getCurrentView
CAS getCurrentView()Get the Cas view that the current component should use. This should only be used by single-view components.- Returns:
- the Cas view specified for the current component by Sofa mapping. Defaults to _InitialView if there is no Sofa mapping.
-
getSofa
Deprecated.As of v2.0, use {#getView(String)}. From the view you can access the Sofa data, or callgetSofa()
if you truly need to access the SofaFS object.Get sofaFS for given Subject of Analysis ID.- Parameters:
sofaID
- -- Returns:
- The sofaFS.
-
getSofa
SofaFS getSofa()Get the Sofa feature structure associated with this CAS view.- Returns:
- The SofaFS associated with this CAS view.
-
createView
Create a view and its underlying Sofa (subject of analysis). The view provides access to the Sofa data and the index repository that contains metadata (annotations and other feature structures) pertaining to that Sofa.This method creates the underlying Sofa feature structure, but does not set the Sofa data. Setting ths Sofa data must be done by calling
setSofaDataArray(FeatureStructure, String)
,setSofaDataString(String, String)
orsetSofaDataURI(String, String)
on the CAS view returned by this method.- Parameters:
localViewName
- the local name, before any sofa name mapping is done, for this view (note: this is the same as the associated Sofa name).- Returns:
- The view corresponding to this local name.
- Throws:
CASRuntimeException
- if a View with this name already exists in this CAS
-
getJCas
Create a JCas view for a Sofa. Note: as of UIMA v2.0, can be replaced with getView(sofaFS).getJCas().- Parameters:
aSofa
- a Sofa feature structure in this CAS.- Returns:
- The JCas view for the given Sofa.
- Throws:
CASException
- -
-
getJCas
Deprecated.As of v2.0, usegetView(String)
followed bygetJCas()
.Create a JCas view for a Sofa. Note: this is provided for convenience. It is equivalent togetView(aSofaID).getJCas()
.- Parameters:
aSofaID
- the ID of a Sofa defined in this CAS- Returns:
- The view for the Sofa with ID
aSofaID
. - Throws:
CASException
- if no Sofa with the given ID exists in this CAS
-
getView
Get the view for a Sofa (subject of analysis). The view provides access to the Sofa data and the index repository that contains metadata (annotations and other feature structures) pertaining to that Sofa.- Parameters:
localViewName
- the local name, before any sofa name mapping is done, for this view (note: this is the same as the associated Sofa name).- Returns:
- The view corresponding to this local name.
- Throws:
CASRuntimeException
- if no View with this name exists in this CAS
-
getView
Get the view for a Sofa (subject of analysis). The view provides access to the Sofa data and the index repository that contains metadata (annotations and other feature structures) pertaining to that Sofa.- Parameters:
aSofa
- a Sofa feature structure in the CAS- Returns:
- The view for the given Sofa
-
getLowLevelCAS
LowLevelCAS getLowLevelCAS()Get an instance of the low-level CAS. Low-level and regular CAS can be used in parallel, all data is always contained in both.Note: This is for internal use.
- Returns:
- A low-level CAS.
- See Also:
-
getAnnotationType
Type getAnnotationType()Get the type object for the annotation type.- Returns:
- The annotation type.
-
getBeginFeature
Feature getBeginFeature()Get the feature object for the annotation begin feature.- Returns:
- The annotation begin feature.
-
getEndFeature
Feature getEndFeature()Get the feature object for the annotation end feature.- Returns:
- The annotation end feature.
-
getAnnotationIndex
Get the standard annotation index.- Type Parameters:
T
- either Annotation (if JCas is in use) or AnnotationImpl- Returns:
- The standard annotation index.
-
getAnnotationIndex
<T extends AnnotationFS> AnnotationIndex<T> getAnnotationIndex(Type type) throws CASRuntimeException Get the standard annotation index restricted to a specific annotation type.- Type Parameters:
T
- the topmost Java class corresponding to the type- Parameters:
type
- The annotation type the index is restricted to.- Returns:
- The standard annotation index, restricted to
type
. - Throws:
CASRuntimeException
- Whentype
is not an annotation type.
-
getAnnotationIndex
default <T extends AnnotationFS> AnnotationIndex<T> getAnnotationIndex(Class<T> clazz) throws CASRuntimeException Get the standard annotation index restricted to a specific annotation type.- Type Parameters:
T
- the topmost Java class corresponding to the type- Parameters:
clazz
- The annotation type the index is restricted to, specified as a JCas class- Returns:
- The standard annotation index, restricted to
type
. - Throws:
CASRuntimeException
- Whentype
is not an annotation type.
-
createAnnotation
Create a new annotation. Note that you still need to insert the annotation into the index repository yourself.- Type Parameters:
T
- the Java class corresponding to the type- Parameters:
type
- The type of the annotation.begin
- The start of the annotation.end
- The end of the annotation.- Returns:
- A new annotation object.
-
getDocumentAnnotation
Get the Document Annotation. The Document Annotation has a string-valued feature called "language" where the document language is specified.- Type Parameters:
T
- the Java class for the document annotation. Could be the JCas cover class or FeatureStructure- Returns:
- The document annotation. If it doesn't exist, one is created. The return value is the JCas cover class or the plain Java cover class for FeatureStructures if there is no JCas cover class for this type.
-
setCurrentComponentInfo
Informs the CAS of relevant information about the component that is currently processing it. This is called by the framework automatically; users do not need to call it.- Parameters:
info
- information about the component that is currently processing this CAS.
-
getTypeSystem
Return the type system of this CAS instance.- Returns:
- The type system, or
null
if none is available. - Throws:
CASRuntimeException
- If the type system has not been committed.
-
createSofa
Deprecated.As of v2.0, usecreateView(String)
instead.Create a Subject of Analysis. The new sofaFS is automatically added to the SofaIndex.- Parameters:
sofaID
- -mimeType
- -- Returns:
- The sofaFS.
-
getSofaIterator
Get iterator for all SofaFS in the CAS.- Type Parameters:
T
- generic type of sofa iterator- Returns:
- an iterator over SofaFS.
-
createFilteredIterator
<T extends FeatureStructure> FSIterator<T> createFilteredIterator(FSIterator<T> it, FSMatchConstraint cons) Create an iterator over structures satisfying a given constraint. Constraints are described in the javadocs forConstraintFactory
and related classes.- Type Parameters:
T
- - the type of the Feature Structure- Parameters:
it
- The input iterator.cons
- The constraint specifying what structures should be returned.- Returns:
- An iterator over FSs.
-
getConstraintFactory
ConstraintFactory getConstraintFactory()Get a constraint factory. A constraint factory is a simple way of creatingFSMatchConstraints
.- Returns:
- A constraint factory to create new FS constraints.
-
createFeaturePath
FeaturePath createFeaturePath()Create a feature path. This is mainly useful for creatingFSMatchConstraints
.- Returns:
- A new, empty feature path.
-
getIndexRepository
FSIndexRepository getIndexRepository()Get the index repository.- Returns:
- The index repository, or
null
if none is available.
-
fs2listIterator
Wrap a standard JavaListIterator
around an FSListIterator. Use if you feel more comfortable with java style iterators.- Type Parameters:
T
- The type of FeatureStructure- Parameters:
it
- TheFSListIterator
to be wrapped.- Returns:
- An equivalent
ListIterator
.
-
reset
Reset the CAS, emptying it of all content. Feature structures and iterators will no longer be valid. Note: this method may only be called from an application. Calling it from an annotator will trigger a runtime exception.- Throws:
CASRuntimeException
- When called out of sequence.CASAdminException
- See Also:
-
getViewName
String getViewName()Get the view name. The view name is the same as the name of the view's Sofa, retrieved by getSofa().getSofaID(), except for the initial View before its Sofa has been created.- Returns:
- The name of the view
-
size
int size()Estimate the memory consumption of this CAS instance (in bytes).- Returns:
- The estimated memory used by this CAS instance.
-
createFeatureValuePath
Create a feature-value path from a string.- Parameters:
featureValuePath
- String representation of the feature-value path.- Returns:
- Feature-value path object.
- Throws:
CASRuntimeException
- If the input string is not well-formed.
-
setDocumentText
Set the document text. Once set, Sofa data is immutable, and cannot be set again until the CAS has been reset.- Parameters:
text
- The text to be analyzed.- Throws:
CASRuntimeException
- If the Sofa data has already been set.
-
setSofaDataString
Set the document text. Once set, Sofa data is immutable, and cannot be set again until the CAS has been reset.- Parameters:
text
- The text to be analyzed.mimetype
- The mime type of the data- Throws:
CASRuntimeException
- If the Sofa data has already been set.
-
getDocumentText
String getDocumentText()Get the document text.- Returns:
- The text being analyzed, or
null
if not set.
-
getSofaDataString
String getSofaDataString()Get the Sofa Data String (a.k.a. the document text).- Returns:
- The Sofa data string, or
null
if not set.
-
setDocumentLanguage
Sets the language for this document. This value sets the language feature of the special instance of DocumentAnnotation associated with this CAS.- Parameters:
languageCode
- -- Throws:
CASRuntimeException
- passthru
-
getDocumentLanguage
String getDocumentLanguage()Gets the language code for this document from the language feature of the special instance of the DocumentationAnnotation associated with this CAS.- Returns:
- language identifier
-
setSofaDataArray
Set the Sofa data as an ArrayFS. Once set, Sofa data is immutable, and cannot be set again until the CAS has been reset.- Parameters:
array
- The ArrayFS to be analyzed.mime
- The mime type of the data- Throws:
CASRuntimeException
- If the Sofa data has already been set.
-
getSofaDataArray
FeatureStructure getSofaDataArray()Get the Sofa data array.- Returns:
- The Sofa Data being analyzed, or
null
if not set.
-
setSofaDataURI
Set the Sofa data as a URI. Once set, Sofa data is immutable, and cannot be set again until the CAS has been reset.- Parameters:
uri
- The URI of the data to be analyzed.mime
- The mime type of the data- Throws:
CASRuntimeException
- If the Sofa data has already been set.
-
getSofaDataURI
String getSofaDataURI()Get the Sofa data array.- Returns:
- The Sofa URI being analyzed, or
null
if not set.
-
getSofaDataStream
InputStream getSofaDataStream()Get the Sofa data as a byte stream.- Returns:
- A stream handle to the Sofa Data, or
null
if not set.
-
getSofaMimeType
String getSofaMimeType()Get the mime type of the Sofa data being analyzed.- Returns:
- the mime type of the Sofa
-
addFsToIndexes
Add a feature structure to all appropriate indexes in the repository associated with this CAS View. If no indexes exist for the type of FS that you are adding, then a bag (unsorted) index will be automatically created.Important: after you have called
addFsToIndexes(...)
on a FS, do not change the values of any features used for indexing. If you do, the index will become corrupted and may be unusable. If you need to change an index feature value, first callremoveFsFromIndexes(...)
on the FS, change the feature values, then calladdFsToIndexes(...)
again.- Parameters:
fs
- The Feature Structure to be added.- Throws:
NullPointerException
- If thefs
parameter isnull
.
-
removeFsFromIndexes
Remove a feature structure from all indexes in the repository associated with this CAS View. The remove operation removes the exact fs from the indexes, unlike operations such as moveTo which use the fs argument as a template. It is not an error if the FS is not present in the indexes.- Parameters:
fs
- The Feature Structure to be removed.- Throws:
NullPointerException
- If thefs
parameter isnull
.
-
getViewIterator
Get iterator over all views in this CAS. Each view provides access to Sofa data and the index repository that contains metadata (annotations and other feature structures) pertaining to that Sofa.- Type Parameters:
T
- generic type of returned view- Returns:
- an iterator which returns all views. Each object returned by the iterator is of type CAS or a subtype.
-
getViewIterator
Get iterator over all views with the given name prefix. Each view provides access to Sofa data and the index repository that contains metadata (annotations and other feature structures) pertaining to that Sofa.When passed the prefix namePrefix, the iterator will return all views who name is either exactly equal to namePrefix or is of the form namePrefix
.
suffix, where suffix can be any String.- Parameters:
localViewNamePrefix
- the local name prefix, before any sofa name mapping is done, for this view (note: this is the same as the associated Sofa name prefix).- Returns:
- an iterator which returns all views with the given name prefix. Each object returned by the iterator is of type CAS.
-
createMarker
Marker createMarker()Sets a mark and returns the marker object set with the current mark which can be used to query when certain FSs were created. This can then be used to identify FSs as added before or after the mark was set and to identify FSs modified after the mark is set. Note: this method may only be called from an application. Calling it from an annotator will trigger a runtime exception.- Returns:
- a marker object.
-
protectIndexes
AutoCloseable protectIndexes()Call this method to set up a region, ended by aAutoCloseable.close()
call on the returned object, You can use this or theprotectIndexes(Runnable)
method to protected the indexes.This approach allows arbitrary code between the protectIndexes and the associated close method.
The close method is best done in a finally block, or using the try-with-resources statement in Java 8.
- Returns:
- an object used to record things that need adding back
-
protectIndexes
Runs the code in the runnable inside a protection block, where any modifications to features done while in this block will be done in a way to protect any indexes which otherwise might become corrupted by the update action; the protection is achieved by temporarily removing the FS (if it is in the indexes), before the update happens. At the end of the block, affected indexes have any removed-under-the-covers FSs added back.- Parameters:
runnable
- code to execute while protecting the indexes.
-
select
- Type Parameters:
T
- the Type of the elements being accessed- Returns:
- a newly created selection object for accessing feature structures
-
select
- Type Parameters:
T
- the Type of the elements being accessed- Parameters:
type
- specifies the type (and subtypes of that type) to access- Returns:
- a newly created selection object for accessing feature structures of that type and its subtypes
- Throws:
IllegalArgumentException
- if no type is specified.
-
select
- Type Parameters:
T
- the Type of the elements being accessed- Parameters:
clazz
- a JCas class corresponding to the type (and subtypes of that type) to access- Returns:
- a newly created selection object for accessing feature structures of that type and its subtypes
- Throws:
IllegalArgumentException
- if no type is specified.
-
select
- Type Parameters:
T
- the Type of the elements being accessed- Parameters:
jcasType
- the "type" field from the JCas class corresponding to the type (and subtypes of that type) to access- Returns:
- a newly created selection object for accessing feature structures of that type and its subtypes
- Throws:
IllegalArgumentException
- if no type is specified.
-
select
- Type Parameters:
T
- the Type of the elements being accessed- Parameters:
fullyQualifiedTypeName
- the string name of the type to access- Returns:
- a newly created selection object for accessing feature structures of that type and its subtypes
- Throws:
IllegalArgumentException
- if no type is specified.
-
emptyList
- Type Parameters:
T
- the type of the element of the list- Parameters:
clazz
- a JCas class corresponding to the type (and subtypes of that type) to access- Returns:
- a lazily created shared (for this CAS) empty list
-
emptyFloatList
- Returns:
- a lazily created shared (for this CAS) empty list
-
emptyFSList
- Type Parameters:
T
- the type of the elements of the FSList- Returns:
- a lazily created shared (for this CAS) empty list
-
emptyIntegerList
- Returns:
- a lazily created shared (for this CAS) empty list
-
emptyStringList
- Returns:
- a lazily created shared (for this CAS) empty list
-
emptyArray
- Type Parameters:
T
- the type of the elements of the array- Parameters:
clazz
- the class of the elements of the array- Returns:
- a lazily created shared (for this CAS) 0-length array
-
emptyFloatArray
- Returns:
- a lazily created shared (for this CAS) 0-length array
-
emptyFSArray
- Type Parameters:
T
- the type of the elements of the FSArray- Returns:
- a lazily created shared (for this CAS) 0-length FSarray
-
emptyFSArray
- Type Parameters:
T
- the type of the elements of the FSArray- Parameters:
type
- the type of the elements of the FSArray- Returns:
- a lazily created shared (for this CAS) 0-length subtype of FSarray holding elements of type element-type
-
emptyIntegerArray
- Returns:
- a lazily created shared (for this CAS) 0-length array
-
emptyStringArray
- Returns:
- a lazily created shared (for this CAS) 0-length array
-
emptyDoubleArray
- Returns:
- a lazily created shared (for this CAS) 0-length array
-
emptyLongArray
- Returns:
- a lazily created shared (for this CAS) 0-length array
-
emptyShortArray
- Returns:
- a lazily created shared (for this CAS) 0-length array
-
emptyByteArray
- Returns:
- a lazily created shared (for this CAS) 0-length array
-
emptyBooleanArray
- Returns:
- a lazily created shared (for this CAS) 0-length array
-
getCasType
- Type Parameters:
T
- the type of the JCas class- Parameters:
clazz
- - a JCas class- Returns:
- the corresponding Type, for this CAS
-
getAllIndexedFS
Gets an iterator over all indexed (in this CAS view) FeatureStructures of the specified Type (and any of its subtypes). The elements are returned in arbitrary order, and duplicates (if they exist) are not removed.- Type Parameters:
T
- the Java clazz- Parameters:
clazz
- - the JCas Java class specifing which type and subtypes are included- Returns:
- An iterator that returns all indexed FeatureStructures of the Type and its subtypes, corresponding to the JCas clazz, in no particular order.
-
getAllIndexedFS
Gets an iterator over all indexed (in this CAS view) FeatureStructures of the specified Type (and any of its subtypes). The elements are returned in arbitrary order, and duplicates (if they exist) are not removed.- Type Parameters:
T
- the JCas class the iterator uses- Parameters:
type
- the type of Feature Structures to include (including subtypes)- Returns:
- An iterator that returns all indexed FeatureStructures of the Type and its subtypes, corresponding to the JCas clazz, in no particular order.
-
getIndexedFSs
Returns an unmodifiable collection of all the FSs that are indexed in this view, in an arbitrary order. Subsequent modifications to the indexes do not affect this collection.- Type Parameters:
T
- The Java class associated with type- Parameters:
type
- the type of Feature Structures to include (including subtypes)- Returns:
- an unmodifiable, unordered collection of all indexed (in this view) Feature Structures of the specified type (including subtypes)
-
getIndexedFSs
Returns an unmodifiable collection of all of the FSs that are indexed in this view, in an arbitrary order. Subsequent modifications to the indexes do not affect this collection.- Returns:
- an unmodifiable, unordered collection of all indexed (in this view) Feature Structures of the specified type (including subtypes)
-
getIndexedFSs
Returns a collection of all the FSs that are indexed in this view, in an arbitrary order. Subsequent modifications to the indexes do not affect this collection.- Type Parameters:
T
- The Java class associated with type- Parameters:
clazz
- The JCas class corresponding to the type- Returns:
- an unmodifiable, unordered collection of all indexed (in this view) Feature Structures of the specified type (including subtypes)
-
NAME_DEFAULT_SOFA
, and the value has changed.