Class AnnotatorAdapter
- java.lang.Object
-
- org.apache.uima.analysis_engine.impl.compatibility.AnnotatorAdapter
-
- All Implemented Interfaces:
AnalysisComponent
public class AnnotatorAdapter extends java.lang.Object implements AnalysisComponent
Adapter that allows Annotators to implement the AnalysisComponent interface.
-
-
Field Summary
Fields Modifier and Type Field Description private BaseAnnotatormAnnotatorprivate java.lang.Class<? extends AbstractCas>mCasInterfaceprivate ResultSpecificationmDefaultResultSpecificationprivate java.util.Map<java.lang.String,ResultSpecification>mLanguageToResultSpecMapprivate TypeSystemmLastTypeSystem
-
Constructor Summary
Constructors Constructor Description AnnotatorAdapter(BaseAnnotator aAnnotator, AnalysisEngineMetaData aMetaData, java.util.Map<java.lang.String,java.lang.Object> aAdditionalParams)Create a new annotator adapter.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidbatchProcessComplete()Completes the processing of a batch of CASes.voidcheckTypeSystemChange(AbstractCas aCAS)Checks it the type system of the given CAS is different from the last type system this component was operating on.voidcollectionProcessComplete()Notifies this AnalysisComponent that processing of an entire collection has been completed.voiddestroy()Frees all resources held by this AnalysisComponent.protected BaseAnnotatorgetAnnotator()intgetCasInstancesRequired()Returns the maximum number of CAS instances that this AnalysisComponent expects to use at the same time.java.lang.Class<? extends AbstractCas>getRequiredCasInterface()Get the CAS interface required by this annotator.private ResultSpecificationgetResultSpecForLanguage(java.lang.String language)booleanhasNext()Asks if this AnalysisComponent has another CAS to output.voidinitialize(UimaContext aContext)Performs any startup tasks required by this component.AbstractCasnext()Gets the next output CAS.voidprocess(AbstractCas aCAS)Inputs a CAS to the AnalysisComponent.voidreconfigure()Alerts this AnalysisComponent that the values of its configuration parameters or external resources have changed.voidsetResultSpecification(ResultSpecification aResultSpec)Sets the ResultSpecification that this AnalysisComponent should use.
-
-
-
Field Detail
-
mAnnotator
private BaseAnnotator mAnnotator
-
mCasInterface
private java.lang.Class<? extends AbstractCas> mCasInterface
-
mLastTypeSystem
private TypeSystem mLastTypeSystem
-
mDefaultResultSpecification
private ResultSpecification mDefaultResultSpecification
-
mLanguageToResultSpecMap
private java.util.Map<java.lang.String,ResultSpecification> mLanguageToResultSpecMap
-
-
Constructor Detail
-
AnnotatorAdapter
public AnnotatorAdapter(BaseAnnotator aAnnotator, AnalysisEngineMetaData aMetaData, java.util.Map<java.lang.String,java.lang.Object> aAdditionalParams) throws ResourceInitializationException
Create a new annotator adapter.- Parameters:
aAnnotator- the annotator instanceaMetaData- metadata for the annotator. Needed to compute ResultSpecification.aAdditionalParams- parameters passed to AE's initialize method. Used to allow containing Aggregate to influence ResultSpecification, for backwards compatibility with CapabilityLanguageFlow.- Throws:
ResourceInitializationException- if the component is sofa-aware
-
-
Method Detail
-
initialize
public void initialize(UimaContext aContext) throws ResourceInitializationException
Description copied from interface:AnalysisComponentPerforms any startup tasks required by this component. The framework calls this method only once, just after the AnalysisComponent has been instantiated.The framework supplies this AnalysisComponent with a reference to the
UimaContextthat it will use, for example to access configuration settings or resources. This AnalysisComponent should store a reference to its theUimaContextfor later use.- Specified by:
initializein interfaceAnalysisComponent- Parameters:
aContext- Provides access to services and resources managed by the framework. This includes configuration parameters, logging, and access to external resources.- Throws:
ResourceInitializationException- if this AnalysisComponent cannot initialize successfully.
-
setResultSpecification
public void setResultSpecification(ResultSpecification aResultSpec)
Description copied from interface:AnalysisComponentSets the ResultSpecification that this AnalysisComponent should use. The ResultSpecification is a set of types and features that this AnalysisComponent is asked to produce. An Analysis Component may (but is not required to) optimize its processing by omitting the generation of any types or features that are not part of the ResultSpecification.- Specified by:
setResultSpecificationin interfaceAnalysisComponent- Parameters:
aResultSpec- the ResultSpecification for this Analysis Component to use.
-
process
public void process(AbstractCas aCAS) throws AnalysisEngineProcessException
Description copied from interface:AnalysisComponentInputs a CAS to the AnalysisComponent. The AnalysisComponent "owns" this CAS until such time asAnalysisComponent.hasNext()is called and returns false or untilprocessis called again (see class description).- Specified by:
processin interfaceAnalysisComponent- Parameters:
aCAS- A CAS that this AnalysisComponent should process. The framework will ensure that aCAS implements the specific CAS interface specified by theAnalysisComponent.getRequiredCasInterface()method.- Throws:
AnalysisEngineProcessException- if a problem occurs during processing
-
getResultSpecForLanguage
private ResultSpecification getResultSpecForLanguage(java.lang.String language)
- Parameters:
language-- Returns:
- the ResultSpecification for the language
-
checkTypeSystemChange
public void checkTypeSystemChange(AbstractCas aCAS) throws AnalysisEngineProcessException
Checks it the type system of the given CAS is different from the last type system this component was operating on. If it is different, calls the typeSystemInit method on the component.- Parameters:
aCAS- -- Throws:
AnalysisEngineProcessException- -
-
batchProcessComplete
public void batchProcessComplete() throws AnalysisEngineProcessExceptionDescription copied from interface:AnalysisComponentCompletes the processing of a batch of CASes. The size of a batch is determined based on configuration provided by the application that is using this component. The purpose ofbatchProcessCompleteis to give this AnalysisComponent the change to flush information from memory to persistent storage. In the event of an error, this allows the processing to be restarted from the end of the last completed batch.If this component's descriptor declares that it is
recoverable, then this component is required to be restartable from the end of the last completed batch.- Specified by:
batchProcessCompletein interfaceAnalysisComponent- Throws:
AnalysisEngineProcessException- if this component encounters a problem in flushing its state to persistent storage
-
collectionProcessComplete
public void collectionProcessComplete() throws AnalysisEngineProcessExceptionDescription copied from interface:AnalysisComponentNotifies this AnalysisComponent that processing of an entire collection has been completed. In this method, this component should finish writing any output relating to the current collection.- Specified by:
collectionProcessCompletein interfaceAnalysisComponent- Throws:
AnalysisEngineProcessException- if this component encounters a problem in its end-of-collection processing
-
destroy
public void destroy()
Description copied from interface:AnalysisComponentFrees all resources held by this AnalysisComponent. The framework calls this method only once, when it is finished using this component.- Specified by:
destroyin interfaceAnalysisComponent
-
reconfigure
public void reconfigure() throws ResourceConfigurationException, ResourceInitializationExceptionDescription copied from interface:AnalysisComponentAlerts this AnalysisComponent that the values of its configuration parameters or external resources have changed. This AnalysisComponent should re-read its configuration from theUimaContextand take appropriate action to reconfigure itself.In the abstract base classes provided by the framework, this is generally implemented by calling
destroyfollowed byinitializeandtypeSystemChanged. If a more efficient implementation is needed, you can override that implementation.- Specified by:
reconfigurein interfaceAnalysisComponent- Throws:
ResourceConfigurationException- if the configuration specified for this component is invalid.ResourceInitializationException- if this component fails to reinitialize itself based on the new configuration.
-
hasNext
public boolean hasNext() throws AnalysisEngineProcessExceptionDescription copied from interface:AnalysisComponentAsks if this AnalysisComponent has another CAS to output. If this method returns true, then a call toAnalysisComponent.next()should retrieve the next output CAS. When this method returns false, the AnalysisComponent gives up control of the initial CAS that was passed to itsAnalysisComponent.process(AbstractCas)method.- Specified by:
hasNextin interfaceAnalysisComponent- Returns:
- true if this AnalysisComponent has another CAS to output, false if not.
- Throws:
AnalysisEngineProcessException- if a problem occurs during processing
-
next
public AbstractCas next() throws AnalysisEngineProcessException
Description copied from interface:AnalysisComponentGets the next output CAS. The framework will only call this method after first callingAnalysisComponent.hasNext()and checking that it returns true.The AnalysisComponent can obtain a new CAS by calling
UimaContext.getEmptyCas(Class)(or instead, one of the helper methods in the ImplBase class that it extended).- Specified by:
nextin interfaceAnalysisComponent- Returns:
- the next output CAS.
- Throws:
AnalysisEngineProcessException- if a problem occurs during processing
-
getRequiredCasInterface
public java.lang.Class<? extends AbstractCas> getRequiredCasInterface()
Get the CAS interface required by this annotator.- Specified by:
getRequiredCasInterfacein interfaceAnalysisComponent- Returns:
- the CAS interface required by this annotator
-
getCasInstancesRequired
public int getCasInstancesRequired()
Description copied from interface:AnalysisComponentReturns the maximum number of CAS instances that this AnalysisComponent expects to use at the same time. This only applies to CasMultipliers. Most CasMultipliers will only need one CAS at a time. Only if there is a clear need should this be overridden to return something greater than 1.- Specified by:
getCasInstancesRequiredin interfaceAnalysisComponent- Returns:
- the number of CAS instances required by this AnalysisComponent.
-
getAnnotator
protected BaseAnnotator getAnnotator()
-
-