6.2.1. Installing a PEAR file using the PEAR APIs
The example below shows how to use the PEAR APIs to install a PEAR package and access the installed PEAR package data. For more details about the PackageBrowser API, please refer to the Javadocs for the org.apache.uima.pear.tools package.
To run a PEAR package after it was installed using the PEAR API see the example below. It use the generated PEAR specifier that was automatically created during the PEAR installation. For more details about the APIs please refer to the Javadocs.
File installDir = new File("/home/user/uimaApp/installedPears");
File pearFile = new File("/home/user/uimaApp/testpear.pear");
boolean doVerification = true;
try {
// Install PEAR package
PackageBrowser instPear = PackageInstaller.installPackage(
installDir, pearFile, doVerification);
// Create a default resouce manager
ResourceManager rsrcMgr = UIMAFramework.newDefaultResourceManager();
// Create analysis engine from the installed PEAR package using
// the created PEAR specifier
XMLInputSource in =
new XMLInputSource(instPear.getComponentPearDescPath());
ResourceSpecifier specifier =
UIMAFramework.getXMLParser().parseResourceSpecifier(in);
AnalysisEngine ae =
UIMAFramework.produceAnalysisEngine(specifier, rsrcMgr, null);
// Create a CAS with a sample document text
CAS cas = ae.newCAS();
cas.setDocumentText("Sample text to process");
cas.setDocumentLanguage("en");
// Process the sample document
ae.process(cas);
} catch (Exception ex) {
ex.printStackTrace();
}
Read full article from UIMA References
No comments:
Post a Comment