org.apache.uima.examples.casMultiplier
Class SimpleTextMerger

java.lang.Object
  extended by org.apache.uima.analysis_component.AnalysisComponent_ImplBase
      extended by org.apache.uima.analysis_component.JCasMultiplier_ImplBase
          extended by org.apache.uima.examples.casMultiplier.SimpleTextMerger
All Implemented Interfaces:
AnalysisComponent

public class SimpleTextMerger
extends JCasMultiplier_ImplBase

An example CasMultiplier, which merges text documents into larger ones. It attempts to merge all of the segments that came from one original artifact. This is done by checking the "lastSegment" feature of the SourceDocumentInformation FeatureStructure, which is expected to be populated by the CollectionReader or CasMultiplier that produced the input CASes.

Limitations: if the lastSegment feature is never set to true by the component producing the input CASes, the merger will never produce any output. Also, this implementation relies on the CASes arriving in order, which could be a problem in a mulithreaded framework implementation. The order requirement could be relieved by recording a segment number in the SourceDocumentInformation, but that would also make this example more complicated.


Field Summary
static java.lang.String MESSAGE_DIGEST
           
static java.lang.String MISSING_SOURCE_DOCUMENT_INFO
           
static java.lang.String NO_NEXT_CAS
           
 
Constructor Summary
SimpleTextMerger()
           
 
Method Summary
 boolean hasNext()
          Asks if this AnalysisComponent has another CAS to output.
 void initialize(UimaContext aContext)
          Performs any startup tasks required by this component.
 AbstractCas next()
          Gets the next output CAS.
 void process(JCas aJCas)
          This method should be overriden by subclasses.
 
Methods inherited from class org.apache.uima.analysis_component.JCasMultiplier_ImplBase
getCasInstancesRequired, getEmptyJCas, getRequiredCasInterface, process
 
Methods inherited from class org.apache.uima.analysis_component.AnalysisComponent_ImplBase
batchProcessComplete, collectionProcessComplete, destroy, getContext, getResultSpecification, reconfigure, setResultSpecification
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

MESSAGE_DIGEST

public static final java.lang.String MESSAGE_DIGEST
See Also:
Constant Field Values

MISSING_SOURCE_DOCUMENT_INFO

public static final java.lang.String MISSING_SOURCE_DOCUMENT_INFO
See Also:
Constant Field Values

NO_NEXT_CAS

public static final java.lang.String NO_NEXT_CAS
See Also:
Constant Field Values
Constructor Detail

SimpleTextMerger

public SimpleTextMerger()
Method Detail

initialize

public void initialize(UimaContext aContext)
                throws ResourceInitializationException
Description copied from interface: AnalysisComponent
Performs 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 UimaContext that it will use, for example to access configuration settings or resources. This AnalysisComponent should store a reference to its the UimaContext for later use.

Specified by:
initialize in interface AnalysisComponent
Overrides:
initialize in class AnalysisComponent_ImplBase
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.

process

public void process(JCas aJCas)
             throws AnalysisEngineProcessException
Description copied from class: JCasMultiplier_ImplBase
This method should be overriden by subclasses. Inputs a JCAS to the AnalysisComponent. The AnalysisComponent "owns" this JCAS until such time as AnalysisComponent.hasNext() is called and returns false, or until the process method is called again (see AnalysisComponent for details).

Specified by:
process in class JCasMultiplier_ImplBase
Parameters:
aJCas - a JCAS that this AnalysisComponent should process.
Throws:
AnalysisEngineProcessException - if a problem occurs during processing

hasNext

public boolean hasNext()
                throws AnalysisEngineProcessException
Description copied from interface: AnalysisComponent
Asks if this AnalysisComponent has another CAS to output. If this method returns true, then a call to AnalysisComponent.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 its AnalysisComponent.process(AbstractCas) method.

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: AnalysisComponent
Gets the next output CAS. The framework will only call this method after first calling AnalysisComponent.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).

Returns:
the next output CAS.
Throws:
AnalysisEngineProcessException - if a problem occurs during processing


Copyright © 2013. All Rights Reserved.