String documentLanguage = Language.normalize(cas.getDocumentLanguage());
if (mNodeList != null) {
// check if another engine is available
if (mIndex >= mNodeList.size()) {
return new FinalStep();
} else {
// get array of ouput capabilities for the current languge from the current result spec
TypeOrFeature[] ouputCapabilities = mResultSpec.getResultTypesAndFeatures(documentLanguage);
// strip language extension if available
int index = documentLanguage.indexOf(LANGUAGE_SEPARATOR);
// if country extension was available
if (index >= 0) {
// create HashSet for outputSpec
HashSet outputSpec = new HashSet();
// add language with country extension output capabilities to the outputSpec
if (ouputCapabilities.length > 0) {
for (int i = 0; i < ouputCapabilities.length; i++) {
outputSpec.add(ouputCapabilities[i]);
}
// get array of output capabilities only for the language without country extension
ouputCapabilities = mResultSpec.getResultTypesAndFeatures(documentLanguage.substring(0,
index));
// add language output capabilities to the outputSpec
for (int i = 0; i < ouputCapabilities.length; i++) {
outputSpec.add(ouputCapabilities[i]);
}
// convert all output capabilities to a outputCapabilities array
ouputCapabilities = new TypeOrFeature[outputSpec.size()];
outputSpec.toArray(ouputCapabilities);
} else // for language with country extension was noting found
{
// get array of output capabilities with the new main language without country extension
ouputCapabilities = mResultSpec.getResultTypesAndFeatures(documentLanguage.substring(0,
index));
}
}
// current analysis node which contains the current analysis engine
AnalysisSequenceCapabilityNode node;
// result spec for the current analysis engine
ResultSpecification currentAnalysisResultSpec = null;
// flag if current analysis engine should be called or not
boolean shouldEngineBeCalled = false;
// check output capabilites from the current result spec
do {
// get next analysis engine from the sequence node
node = (AnalysisSequenceCapabilityNode) mNodeList.get(mIndex++);
// get capability container from the current analysis engine
CapabilityContainer capabilityContainer = node.getCapabilityContainer();
// create current analysis result spec without any language information
currentAnalysisResultSpec = UIMAFramework.getResourceSpecifierFactory()
.createResultSpecification();
// check if engine should be called - loop over all ouput capabilities of the result spec
for (int i = 0; i < ouputCapabilities.length; i++) {
// check if current ToF can be produced by the current analysis engine
if (capabilityContainer.hasOutputTypeOrFeature(ouputCapabilities[i], documentLanguage,
true)) {
currentAnalysisResultSpec.addResultTypeOrFeature(ouputCapabilities[i]);
shouldEngineBeCalled = true;
// remove current ToF from the result spec
mResultSpec.removeTypeOrFeature(ouputCapabilities[i]);
}
}
// skip engine if not output capability match
} while (shouldEngineBeCalled == false && mIndex < mNodeList.size());
// check if current engine should be called
if (shouldEngineBeCalled == true) {
// set result spec for current analysis engine
node.setResultSpec(currentAnalysisResultSpec);
// return current analysis engine node
return new SimpleStepWithResultSpec(node.getCasProcessorKey(), currentAnalysisResultSpec);
} else // no engine left which can be called
{
return new FinalStep();
}
}
} else if (mFlowTable != null) {
AnalysisSequenceCapabilityNode node = null;
// check if document language is included in the flowTable
List flow = (List) mFlowTable.get(documentLanguage);
if (flow == null) // try to get flow without language extension or with x-unspecified
{
// strip language extension if available
int index = documentLanguage.indexOf(LANGUAGE_SEPARATOR);
// if country extension is available
if (index >= 0) {
// check if document language is included in the flowTable
flow = (List) mFlowTable.get(documentLanguage.substring(0, index));
// If the language was not found, use flow for unspecified lang instead.
if (flow == null) {
flow = (List) mFlowTable.get(UNSPECIFIED_LANGUAGE);
}
} else // try to get flow for language x-unspecified
{
flow = (List) mFlowTable.get(UNSPECIFIED_LANGUAGE);
}
}
// if flow is available get next node
if (flow != null) {
if (flow.size() > mIndex) {
node = (AnalysisSequenceCapabilityNode) flow.get(mIndex++);
while (node == null && flow.size() > mIndex) {
node = (AnalysisSequenceCapabilityNode) flow.get(mIndex++);
}
}
}
if (node != null) {
return new SimpleStepWithResultSpec(node.getCasProcessorKey(), node.getResultSpec());
}
}
return new FinalStep();
}