public interface JCas extends AbstractCas
A JCas
object provides the starting point for working with the CAS using
Java Cover Classes for each type, generated by the utility JCasGen.
This interface extends the CAS Interface, providing all the same functionality, plus some specific to the JCas.
It supports the creation of new instances of CAS types, using the normal Java "new" operator.
You can create a JCas
object from a CAS object by calling the getJCas()
method on the CAS object.
Modifier and Type | Field and Description |
---|---|
static int |
INVALID_FEATURE_CODE
(internal use)
|
Modifier and Type | Method and Description |
---|---|
void |
addFsToIndexes(FeatureStructure fs)
Add a feature structure to all appropriate indexes in the repository associated with this CAS
View.
|
void |
checkArrayBounds(int fsRef,
int pos) |
FeaturePath |
createFeaturePath()
Create a feature path.
|
FeatureValuePath |
createFeatureValuePath(String featureValuePath)
Create a feature-value path from a string.
|
<T extends FeatureStructure> |
createFilteredIterator(FSIterator<T> it,
FSMatchConstraint cons)
Create an iterator over structures satisfying a given constraint.
|
SofaFS |
createSofa(SofaID sofaID,
String mimeType)
Deprecated.
As of v2.0, use
createView(String) instead. |
JCas |
createView(String sofaID)
Create a view and its underlying Sofa (subject of analysis).
|
<T extends FeatureStructure> |
fs2listIterator(FSIterator<T> it)
Wrap a standard Java
ListIterator around an FSListIterator. |
<T extends TOP> |
getAllIndexedFS(Class<T> clazz)
Gets an iterator over all indexed FeatureStructures of the specified Type (and any of its
subtypes).
|
AnnotationIndex<Annotation> |
getAnnotationIndex()
Get the standard annotation index.
|
<T extends Annotation> |
getAnnotationIndex(Class<T> clazz)
Get the standard annotation index restricted to a specific annotation type.
|
<T extends Annotation> |
getAnnotationIndex(int type)
Get the standard annotation index restricted to a specific annotation type.
|
<T extends Annotation> |
getAnnotationIndex(Type type)
Get the standard annotation index restricted to a specific annotation type.
|
CAS |
getCas() |
org.apache.uima.cas.impl.CASImpl |
getCasImpl() |
Type |
getCasType(int i)
Given Foo.type, return the corresponding CAS Type object.
|
ConstraintFactory |
getConstraintFactory()
Get a constraint factory.
|
TOP |
getDocumentAnnotationFs()
Gets the document annotation.
|
String |
getDocumentLanguage()
Gets the language code for this document from the language feature of the special instance of
the DocumentationAnnotation associated with this CAS.
|
String |
getDocumentText()
Get the document text.
|
FSArray |
getFSArray0L()
A constant for each cas which holds a 0-length instance.
|
FSIndexRepository |
getFSIndexRepository() |
<T extends TOP> |
getIndex(String label,
Class<T> clazz)
Retrieve an index according to a label and a type specified using a JCas class.
|
FSIndexRepository |
getIndexRepository()
Get the index repository.
|
IntegerArray |
getIntegerArray0L()
A constant for each cas which holds a 0-length instance.
|
JCas |
getJCas(Sofa sofa)
Create a JCas view for a Sofa.
|
<T extends TOP> |
getJfsFromCaddr(int casAddr) |
JFSIndexRepository |
getJFSIndexRepository()
Gets the JCas-based interface to the Index Repository.
|
org.apache.uima.cas.impl.LowLevelCAS |
getLowLevelCas() |
org.apache.uima.cas.impl.LowLevelIndexRepository |
getLowLevelIndexRepository() |
Feature |
getRequiredFeature(Type t,
String s) |
Feature |
getRequiredFeatureDE(Type t,
String s,
String rangeName,
boolean featOkTst) |
Type |
getRequiredType(String s) |
Sofa |
getSofa()
Get the Sofa feature structure associated with this JCas view.
|
Sofa |
getSofa(SofaID sofaID)
Deprecated.
As of v2.0, use {#getView(String)}. From the view you can access the Sofa data, or
call
getSofa() if you truly need to access the SofaFS object. |
FeatureStructure |
getSofaDataArray()
Get the Sofa data array.
|
InputStream |
getSofaDataStream()
Get the Sofa data as a byte stream.
|
String |
getSofaDataString()
Get the Sofa Data String (a.k.a.
|
String |
getSofaDataURI()
Get the Sofa data array.
|
FSIterator<SofaFS> |
getSofaIterator()
Get iterator for all SofaFS in the CAS.
|
String |
getSofaMimeType()
Get the mime type of the Sofa data being analyzed.
|
StringArray |
getStringArray0L()
A constant for each cas which holds a 0-length instance.
|
TOP_Type |
getType(int i)
get the JCas _Type instance for a particular CAS type constant
|
TOP_Type |
getType(TOP instance)
Deprecated.
use instance.jcasType instead - faster
|
TypeSystem |
getTypeSystem()
Return the type system of this CAS instance.
|
JCas |
getView(SofaFS aSofa)
Get the view for a Sofa (subject of analysis).
|
JCas |
getView(String localViewName)
Get the view for a Sofa (subject of analysis).
|
Iterator<JCas> |
getViewIterator()
Get iterator over all views in this JCas.
|
Iterator<JCas> |
getViewIterator(String localViewNamePrefix)
Get iterator over all views with the given name prefix.
|
String |
getViewName()
Get the view name.
|
void |
processInit()
Deprecated.
not required, does nothing
|
AutoCloseable |
protectIndexes()
Call this method to set up a region,
ended by a close() call on the returned object,
You can use this or the
protectIndexes(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 |
putJfsFromCaddr(int casAddr,
FeatureStructure fs) |
void |
removeAllExcludingSubtypes(int i)
Remove all feature structures of a given type (excluding subtypes) from all indexes in the repository associated with this CAS View.
|
void |
removeAllIncludingSubtypes(int i)
Remove all feature structures of a given type (including subtypes) from all indexes in the repository associated with this CAS View.
|
void |
removeFsFromIndexes(FeatureStructure fs)
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.
|
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).
|
void |
throwFeatMissing(String feat,
String type) |
release
static final int INVALID_FEATURE_CODE
FSIndexRepository getFSIndexRepository()
org.apache.uima.cas.impl.LowLevelIndexRepository getLowLevelIndexRepository()
CAS getCas()
org.apache.uima.cas.impl.CASImpl getCasImpl()
org.apache.uima.cas.impl.LowLevelCAS getLowLevelCas()
TOP_Type getType(int i)
i
- the CAS type constant, written as Foo.typeType getCasType(int i)
i
- -
index returned by Foo.type@Deprecated TOP_Type getType(TOP instance)
instance
- instanceType getRequiredType(String s) throws CASException
CASException
Feature getRequiredFeature(Type t, String s) throws CASException
CASException
Feature getRequiredFeatureDE(Type t, String s, String rangeName, boolean featOkTst)
void putJfsFromCaddr(int casAddr, FeatureStructure fs)
<T extends TOP> T getJfsFromCaddr(int casAddr)
void checkArrayBounds(int fsRef, int pos)
@Deprecated Sofa getSofa(SofaID sofaID)
getSofa()
if you truly need to access the SofaFS object.sofaID
- -Sofa getSofa()
JCas createView(String sofaID) throws CASException
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)
or setSofaDataURI(String, String)
on the
JCas view returned by this method.
sofaID
- the local view name, before any sofa name mapping is done, for this view (note: this is the
same as the associated Sofa name).CASException
- -
if a View with this name already exists in this CASJCas getJCas(Sofa sofa) throws CASException
sofa
- a Sofa feature structure in this CAS.CASException
- -JFSIndexRepository getJFSIndexRepository()
getFSIndexRepository()
except that the methods that take a "type"
argument take type arguments obtainable easily from the JCas type.TOP getDocumentAnnotationFs()
The reason that the return type of this method is not DocumentAnnotation is because of problems that arise when using the UIMA Extension ClassLoader to load annotator classes. The DocumentAnnotation type may be defined in the UIMA extension ClassLoader, differently than in the framework ClassLoader.
CAS.getDocumentAnnotation()
StringArray getStringArray0L()
IntegerArray getIntegerArray0L()
FSArray getFSArray0L()
@Deprecated void processInit()
JCas getView(String localViewName) throws CASException
localViewName
- the local name, before any sofa name mapping is done, for this view (note: this is the
same as the associated Sofa name).CASException
- passthruJCas getView(SofaFS aSofa) throws CASException
aSofa
- a Sofa feature structure in the CASCASException
- passthruTypeSystem getTypeSystem() throws CASRuntimeException
null
if none is available.CASRuntimeException
- If the type system has not been committed.@Deprecated SofaFS createSofa(SofaID sofaID, String mimeType)
createView(String)
instead.sofaID
- the SofA IDmimeType
- the mime typeFSIterator<SofaFS> getSofaIterator()
<T extends FeatureStructure> FSIterator<T> createFilteredIterator(FSIterator<T> it, FSMatchConstraint cons)
ConstraintFactory
and related classes.T
- the particular FeatureStructure typeit
- The input iterator.cons
- The constraint specifying what structures should be returned.ConstraintFactory getConstraintFactory()
FSMatchConstraints
.FeaturePath createFeaturePath()
FSMatchConstraints
.FSIndexRepository getIndexRepository()
null
if none is available.<T extends FeatureStructure> ListIterator<T> fs2listIterator(FSIterator<T> it)
ListIterator
around an FSListIterator. Use
if you feel more comfortable with java style iterators.T
- The particular Feature Structure typeit
- The FSListIterator
to be wrapped.ListIterator
.void reset() throws CASAdminException
CASRuntimeException
- When called out of sequence.CASAdminException
CASMgr
String getViewName()
int size()
FeatureValuePath createFeatureValuePath(String featureValuePath) throws CASRuntimeException
featureValuePath
- String representation of the feature-value path.CASRuntimeException
- If the input string is not well-formed.void setDocumentText(String text) throws CASRuntimeException
text
- The text to be analyzed.CASRuntimeException
- If the Sofa data has already been set.void setSofaDataString(String text, String mimetype) throws CASRuntimeException
text
- The text to be analyzed.mimetype
- The mime type of the dataCASRuntimeException
- If the Sofa data has already been set.String getDocumentText()
String getSofaDataString()
void setDocumentLanguage(String languageCode) throws CASRuntimeException
languageCode
- the language codeCASRuntimeException
- passthruString getDocumentLanguage()
void setSofaDataArray(FeatureStructure array, String mime) throws CASRuntimeException
array
- The ArrayFS to be analyzed.mime
- The mime type of the dataCASRuntimeException
- If the Sofa data has already been set.FeatureStructure getSofaDataArray()
void setSofaDataURI(String uri, String mime) throws CASRuntimeException
uri
- The URI of the data to be analyzed.mime
- The mime type of the dataCASRuntimeException
- If the Sofa data has already been set.String getSofaDataURI()
InputStream getSofaDataStream()
String getSofaMimeType()
void addFsToIndexes(FeatureStructure fs)
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 call
removeFsFromIndexes(...)
on the FS, change the
feature values, then call addFsToIndexes(...)
again.
fs
- The Feature Structure to be added.NullPointerException
- If the fs
parameter is null
.void removeFsFromIndexes(FeatureStructure fs)
fs
- The Feature Structure to be removed.NullPointerException
- If the fs
parameter is null
.void removeAllIncludingSubtypes(int i)
i
- the CAS type constant, written as Foo.type (for a given JCas Type) or anInstanceOfFoo.getTypeIndexID(), for an instancevoid removeAllExcludingSubtypes(int i)
i
- the CAS type constant, written as Foo.type (for a given JCas Type) or anInstanceOfFoo.getTypeIndexID(), for an instanceAnnotationIndex<Annotation> getAnnotationIndex()
<T extends Annotation> AnnotationIndex<T> getAnnotationIndex(Type type) throws CASRuntimeException
T
- the Java class corresponding to typetype
- The annotation type the index is restricted to.type
.CASRuntimeException
<T extends Annotation> AnnotationIndex<T> getAnnotationIndex(int type) throws CASRuntimeException
T
- the Java class corresponding to typetype
- The annotation type the index is restricted to,
passed as an integer using the form
MyAnnotationType.typetype
.CASRuntimeException
- -<T extends Annotation> AnnotationIndex<T> getAnnotationIndex(Class<T> clazz) throws CASRuntimeException
T
- the Java class clazzclazz
- The JCas cover class for the annotation type the index is restricted to,type
.CASRuntimeException
- -<T extends TOP> FSIterator<T> getAllIndexedFS(Class<T> clazz)
T
- the Java clazzclazz
- - the JCas Java class specifing which type and subtypes are includedIterator<JCas> getViewIterator() throws CASException
CASException
- -Iterator<JCas> getViewIterator(String localViewNamePrefix) throws CASException
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.
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).CASException
- -AutoCloseable protectIndexes()
protectIndexes(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.
void protectIndexes(Runnable runnable)
runnable
- code to execute while protecting the indexes.<T extends TOP> FSIndex<T> getIndex(String label, Class<T> clazz)
T
- the Java clazzlabel
- The name of the index.clazz
- The JCas class (mostly likely written as MyJCasClass.class), which must correspond to a subtype of the type of the index.null
if an index with that name doesn't exist.CASRuntimeException
- When clazz
doesn't correspond to a subtype of the index's type.Copyright © 2006–2017 The Apache Software Foundation. All rights reserved.