// types
casConsumerDesc.getCasConsumerMetaData().getCapabilities()[0].addInputType("uima.cas.TOP",
true);
// if XML tag was specified, also create XmlDetagger annotator that handles this
AnalysisEngineDescription xmlDetaggerDesc = null;
if (xmlTag != null && xmlTag.length() > 0) {
xmlDetaggerDesc = XmlDetagger.getDescription();
ConfigurationParameterSettings xmlDetaggerParamSettings = xmlDetaggerDesc.getMetaData()
.getConfigurationParameterSettings();
xmlDetaggerParamSettings.setParameterValue(XmlDetagger.PARAM_TEXT_TAG, xmlTag);
usingXmlDetagger = true;
}
else {
usingXmlDetagger = false;
}
// create an aggregate AE that includes the XmlDetagger (if needed), followed by
//th user's AE descriptor, followed by the XMI Writer CAS Consumer, using fixed flow.
// We use an aggregate AE here, rather than just adding the CAS Consumer to the CPE, so
//that we can support the user's AE being a CAS Multiplier and we can specify sofa mappings.
AnalysisEngineDescription aggDesc = UIMAFramework.getResourceSpecifierFactory()
.createAnalysisEngineDescription();
aggDesc.setPrimitive(false);
aggDesc.getDelegateAnalysisEngineSpecifiersWithImports().put("UserAE", aeSpecifier);
aggDesc.getDelegateAnalysisEngineSpecifiersWithImports().put("XmiWriter", casConsumerDesc);
FixedFlow flow = UIMAFramework.getResourceSpecifierFactory().createFixedFlow();
if (xmlDetaggerDesc != null) {
aggDesc.getDelegateAnalysisEngineSpecifiersWithImports().put("XmlDetagger", xmlDetaggerDesc);
flow.setFixedFlow(new String[] {"XmlDetagger", "UserAE", "XmiWriter"});
//to run XmlDetagger we need sofa mappings
//XmlDetagger's "xmlDocument" input sofa gets mapped to the default sofa
SofaMapping sofaMapping1 = UIMAFramework.getResourceSpecifierFactory().createSofaMapping();
sofaMapping1.setComponentKey("XmlDetagger");
sofaMapping1.setComponentSofaName("xmlDocument");
sofaMapping1.setAggregateSofaName(CAS.NAME_DEFAULT_SOFA);
//for UserAE and XmiWriter, may default sofa to the "plainTextDocument" produced by the XmlDetagger
SofaMapping sofaMapping2 = UIMAFramework.getResourceSpecifierFactory().createSofaMapping();
sofaMapping2.setComponentKey("UserAE");
sofaMapping2.setAggregateSofaName("plainTextDocument");
SofaMapping sofaMapping3 = UIMAFramework.getResourceSpecifierFactory().createSofaMapping();
sofaMapping3.setComponentKey("XmiWriter");
sofaMapping3.setAggregateSofaName("plainTextDocument");
aggDesc.setSofaMappings(new SofaMapping[] {sofaMapping1, sofaMapping2, sofaMapping3});
}
else {
//no XML detagger needed in the aggregate in flow
flow.setFixedFlow(new String[] { "UserAE", "XmiWriter" });
}
aggDesc.getAnalysisEngineMetaData().setName("DocumentAnalyzerAE");
aggDesc.getAnalysisEngineMetaData().setFlowConstraints(flow);
aggDesc.getAnalysisEngineMetaData().getOperationalProperties().setMultipleDeploymentAllowed(
false);
progressMonitor.setProgress(1);
// instantiate AE
// keep this a local variable - so it doesn't hang on to the ae object