public class JCasImpl extends AbstractCas_ImplBase implements AbstractCas, JCas
There are variables here that hold references to constant, frequently needed Cas values, such as 0-length FSArrays, 0-length Strings, etc. These can be used to improve efficiency, since the same object can be shared and used for all instances because it is unchangeable. These objects are reset when the CAS is reset, and are initialized lazily, on first use.
Modifier and Type | Class and Description |
---|---|
static class |
JCasImpl.ErrorReport |
INVALID_FEATURE_CODE
Modifier and Type | Method and Description |
---|---|
void |
addFsToIndexes(FeatureStructure instance)
Add a feature structure to all appropriate indexes in the repository associated with this CAS
View.
|
void |
checkArrayBounds(int fsRef,
int pos) |
static void |
clearData(CAS cas) |
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 constraint)
Create an iterator over structures satisfying a given constraint.
|
SofaFS |
createSofa(SofaID sofaID,
String mimeType)
Create a Subject of Analysis.
|
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() |
CASImpl |
getCasImpl() |
Type |
getCasType(Class<? extends TOP> clazz)
Return the UIMA Type object corresponding to this JCas's JCas cover class
(Note: different JCas's, with different type systems, may share the same cover class impl)
|
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.
|
FloatArray |
getFloatArray0L()
A constant for each cas which holds a 0-length instance.
|
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.
|
static JCas |
getJCas(CASImpl cas)
creates a new JCas instance that corresponds to a CAS 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.
|
LowLevelCAS |
getLowLevelCas() |
LowLevelIndexRepository |
getLowLevelIndexRepository() |
Feature |
getRequiredFeature(Type t,
String s) |
Feature |
getRequiredFeatureDE(Type t,
String s,
String rangeName,
boolean featOkTst) |
Type |
getRequiredType(String s)
Make the instance of the JCas xxx_Type class for this CAS.
|
Sofa |
getSofa()
Get the Sofa feature structure associated with this JCas view.
|
Sofa |
getSofa(SofaID sofaID) |
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)
get the JCas x_Type instance for a particular Java instance of a type
|
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 |
instantiateJCas_Types(ClassLoader cl) |
void |
maybeInitializeForClassLoader(ClassLoader cl)
called when switching to JCas and the JCas already exists to check if
the JCas needs to have classes loaded for this class loader.
|
void |
processInit()
initialize the JCas for new Cas content.
|
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
JCas.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 |
release()
Default implementation that returns this CAS to its CasManager by calling
CasOwner.releaseCas(AbstractCas) . |
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 instance)
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 language)
Sets the language for this document.
|
void |
setDocumentText(String text)
Set the document text.
|
void |
setOwner(CasOwner aCasOwner)
Provides this CAS with a handle to the CASOwner that owns it.
|
void |
setSofaDataArray(FeatureStructure array,
String mime)
Set the Sofa data as an ArrayFS.
|
void |
setSofaDataString(String text,
String mime)
Set the document text.
|
void |
setSofaDataURI(String uri,
String mime)
Set the Sofa data as a URI.
|
void |
showJfsFromCaddrHistogram() |
int |
size()
Estimate the memory consumption of this CAS instance (in bytes).
|
void |
switchClassLoader(ClassLoader cl)
This is only called when the JCas is already set up
|
void |
throwFeatMissing(String feat,
String type)
Internal - throw missing feature exception at runtime
|
public FSIndexRepository getFSIndexRepository()
getFSIndexRepository
in interface JCas
public LowLevelIndexRepository getLowLevelIndexRepository()
getLowLevelIndexRepository
in interface JCas
public CAS getCas()
public CASImpl getCasImpl()
getCasImpl
in interface JCas
public LowLevelCAS getLowLevelCas()
getLowLevelCas
in interface JCas
public TypeSystem getTypeSystem()
JCas
getTypeSystem
in interface JCas
null
if none is available.public TOP_Type getType(int i)
JCas
public Type getCasType(int i)
JCas
getCasType
in interface JCas
i
- -
index returned by Foo.typepublic TOP_Type getType(TOP instance)
JCas
public void switchClassLoader(ClassLoader cl)
cl
- class loader to switch topublic void maybeInitializeForClassLoader(ClassLoader cl)
cl
- the class loader in usepublic void instantiateJCas_Types(ClassLoader cl)
cl
- the class loader to use as the initiating loader for loading JCas classespublic static JCas getJCas(CASImpl cas) throws CASException
cas
- a CAS instanceCASException
- -public Type getRequiredType(String s) throws CASException
getRequiredType
in interface JCas
CASException
public Feature getRequiredFeature(Type t, String s) throws CASException
getRequiredFeature
in interface JCas
CASException
public Feature getRequiredFeatureDE(Type t, String s, String rangeName, boolean featOkTst)
getRequiredFeatureDE
in interface JCas
public void throwFeatMissing(String feat, String type)
throwFeatMissing
in interface JCas
feat
- -type
- -public void putJfsFromCaddr(int casAddr, FeatureStructure fs)
putJfsFromCaddr
in interface JCas
public <T extends TOP> T getJfsFromCaddr(int casAddr)
getJfsFromCaddr
in interface JCas
public void showJfsFromCaddrHistogram()
public static void clearData(CAS cas)
public void reset()
JCas
public final void checkArrayBounds(int fsRef, int pos)
checkArrayBounds
in interface JCas
public Sofa getSofa()
JCas
public JCas createView(String sofaID) throws CASException
JCas
This method creates the underlying Sofa feature structure, but does not set the Sofa data.
Setting ths Sofa data must be done by calling JCas.setSofaDataArray(FeatureStructure, String)
,
JCas.setSofaDataString(String, String)
or JCas.setSofaDataURI(String, String)
on the
JCas view returned by this method.
createView
in interface JCas
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 CASpublic JCas getJCas(Sofa sofa) throws CASException
JCas
getJCas
in interface JCas
sofa
- a Sofa feature structure in this CAS.CASException
- -public FSIterator<SofaFS> getSofaIterator()
JCas
getSofaIterator
in interface JCas
public JFSIndexRepository getJFSIndexRepository()
JCas
JCas.getFSIndexRepository()
except that the methods that take a "type"
argument take type arguments obtainable easily from the JCas type.getJFSIndexRepository
in interface JCas
public TOP getDocumentAnnotationFs()
JCas
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.
getDocumentAnnotationFs
in interface JCas
CAS.getDocumentAnnotation()
public String getDocumentText()
JCas
getDocumentText
in interface JCas
public String getSofaDataString()
JCas
getSofaDataString
in interface JCas
public FeatureStructure getSofaDataArray()
JCas
getSofaDataArray
in interface JCas
public String getSofaDataURI()
JCas
getSofaDataURI
in interface JCas
public String getSofaMimeType()
JCas
getSofaMimeType
in interface JCas
public void setDocumentText(String text) throws CASRuntimeException
JCas
setDocumentText
in interface JCas
text
- The text to be analyzed.CASRuntimeException
- If the Sofa data has already been set.public void setSofaDataString(String text, String mime) throws CASRuntimeException
JCas
setSofaDataString
in interface JCas
text
- The text to be analyzed.mime
- The mime type of the dataCASRuntimeException
- If the Sofa data has already been set.public void setSofaDataArray(FeatureStructure array, String mime) throws CASRuntimeException
JCas
setSofaDataArray
in interface JCas
array
- The ArrayFS to be analyzed.mime
- The mime type of the dataCASRuntimeException
- If the Sofa data has already been set.public void setSofaDataURI(String uri, String mime) throws CASRuntimeException
JCas
setSofaDataURI
in interface JCas
uri
- The URI of the data to be analyzed.mime
- The mime type of the dataCASRuntimeException
- If the Sofa data has already been set.public String getDocumentLanguage()
JCas
getDocumentLanguage
in interface JCas
public void setDocumentLanguage(String language) throws CASRuntimeException
JCas
setDocumentLanguage
in interface JCas
language
- the language codeCASRuntimeException
- passthrupublic InputStream getSofaDataStream()
JCas
getSofaDataStream
in interface JCas
public ConstraintFactory getConstraintFactory()
JCas
FSMatchConstraints
.getConstraintFactory
in interface JCas
public FeaturePath createFeaturePath()
JCas
FSMatchConstraints
.createFeaturePath
in interface JCas
public <T extends FeatureStructure> FSIterator<T> createFilteredIterator(FSIterator<T> it, FSMatchConstraint constraint)
JCas
ConstraintFactory
and related classes.createFilteredIterator
in interface JCas
T
- the particular FeatureStructure typeit
- The input iterator.constraint
- The constraint specifying what structures should be returned.public StringArray getStringArray0L()
JCas
getStringArray0L
in interface JCas
public IntegerArray getIntegerArray0L()
JCas
getIntegerArray0L
in interface JCas
public FloatArray getFloatArray0L()
JCas
getFloatArray0L
in interface JCas
public FSArray getFSArray0L()
JCas
getFSArray0L
in interface JCas
public void processInit()
JCas
processInit
in interface JCas
public void setOwner(CasOwner aCasOwner)
AbstractCas_ImplBase
setOwner
in class AbstractCas_ImplBase
aCasOwner
- -public void release()
AbstractCas_ImplBase
CasOwner.releaseCas(AbstractCas)
.release
in interface AbstractCas
release
in class AbstractCas_ImplBase
public JCas getView(String localViewName) throws CASException
JCas
getView
in interface JCas
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
- passthrupublic JCas getView(SofaFS aSofa) throws CASException
JCas
getView
in interface JCas
aSofa
- a Sofa feature structure in the CASCASException
- passthrupublic void addFsToIndexes(FeatureStructure instance)
JCas
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.
addFsToIndexes
in interface JCas
instance
- The Feature Structure to be added.public void removeFsFromIndexes(FeatureStructure instance)
JCas
removeFsFromIndexes
in interface JCas
instance
- The Feature Structure to be removed.public void removeAllIncludingSubtypes(int i)
JCas
removeAllIncludingSubtypes
in interface JCas
i
- the CAS type constant, written as Foo.type (for a given JCas Type) or anInstanceOfFoo.getTypeIndexID(), for an instancepublic void removeAllExcludingSubtypes(int i)
JCas
removeAllExcludingSubtypes
in interface JCas
i
- the CAS type constant, written as Foo.type (for a given JCas Type) or anInstanceOfFoo.getTypeIndexID(), for an instancepublic <T extends FeatureStructure> ListIterator<T> fs2listIterator(FSIterator<T> it)
JCas
ListIterator
around an FSListIterator. Use
if you feel more comfortable with java style iterators.fs2listIterator
in interface JCas
T
- The particular Feature Structure typeit
- The FSListIterator
to be wrapped.ListIterator
.CAS.fs2listIterator(FSIterator)
public FeatureValuePath createFeatureValuePath(String featureValuePath) throws CASRuntimeException
JCas
createFeatureValuePath
in interface JCas
featureValuePath
- String representation of the feature-value path.CASRuntimeException
- If the input string is not well-formed.public SofaFS createSofa(SofaID sofaID, String mimeType)
JCas
createSofa
in interface JCas
sofaID
- the SofA IDmimeType
- the mime typepublic FSIndexRepository getIndexRepository()
JCas
getIndexRepository
in interface JCas
null
if none is available.public String getViewName()
JCas
getViewName
in interface JCas
public int size()
JCas
public AnnotationIndex<Annotation> getAnnotationIndex()
JCas
getAnnotationIndex
in interface JCas
public <T extends Annotation> AnnotationIndex<T> getAnnotationIndex(Type type) throws CASRuntimeException
JCas
getAnnotationIndex
in interface JCas
T
- the Java class corresponding to typetype
- The annotation type the index is restricted to.type
.CASRuntimeException
public <T extends Annotation> AnnotationIndex<T> getAnnotationIndex(int type) throws CASRuntimeException
JCas
getAnnotationIndex
in interface JCas
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
- -public <T extends Annotation> AnnotationIndex<T> getAnnotationIndex(Class<T> clazz)
JCas
getAnnotationIndex
in interface JCas
T
- the Java class clazzclazz
- The JCas cover class for the annotation type the index is restricted to,type
.public Iterator<JCas> getViewIterator() throws CASException
JCas
getViewIterator
in interface JCas
CASException
- -public Iterator<JCas> getViewIterator(String localViewNamePrefix) throws CASException
JCas
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.
getViewIterator
in interface JCas
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
- -public AutoCloseable protectIndexes()
JCas
JCas.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.
protectIndexes
in interface JCas
public void protectIndexes(Runnable runnable)
JCas
protectIndexes
in interface JCas
runnable
- code to execute while protecting the indexes.public Type getCasType(Class<? extends TOP> clazz)
clazz
- a JCas cover classpublic <T extends TOP> FSIterator<T> getAllIndexedFS(Class<T> clazz)
JCas
getAllIndexedFS
in interface JCas
T
- the Java clazzclazz
- - the JCas Java class specifing which type and subtypes are includedpublic <T extends TOP> FSIndex<T> getIndex(String label, Class<T> clazz)
JCas
getIndex
in interface JCas
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.Copyright © 2006–2021 The Apache Software Foundation. All rights reserved.