我是 UIMA Ruta 的新手。我使用脚本语言制作了一些注释器。我能够在 EclipseIDE 中运行它们。我想编写一个 JAVA API 来根据提供的输入自动运行脚本。
我正在使用 UIMA 文档中提供的相同示例项目。
到目前为止,我已经能够做到这一点
try {
File taeDescriptor = null;
File inputDir = null;
// Read and validate command line arguments
boolean validArgs = false;
if (args.length == 2) {
taeDescriptor = new File(args[0]);
inputDir = new File(args[1]);
validArgs = taeDescriptor.exists()
&& !taeDescriptor.isDirectory()
&& inputDir.isDirectory();
}
if (!validArgs) {
printUsageMessage();
} else {
// get Resource Specifier from XML file
XMLInputSource in = new XMLInputSource(taeDescriptor);
ResourceSpecifier specifier = UIMAFramework.getXMLParser()
.parseResourceSpecifier(in);
// for debugging, output the Resource Specifier
// System.out.println(specifier);
// create Analysis Engine
AnalysisEngine ae = UIMAFramework
.produceAnalysisEngine(specifier);
// create a CAS
CAS cas = ae.newCAS();
// get all files in the input directory
File[] files = inputDir.listFiles();
if (files == null) {
System.out.println("No files to process");
} else {
// process documents
for (int i = 0; i < files.length; i++) {
if (!files[i].isDirectory()) {
processFile(files[i], ae, cas);
}
}
}
ae.destroy();
}
} catch (Exception e) {
e.printStackTrace();
}
}
在使用默认 BasicEngine.xml 和输入文本文件运行上述代码段时。它给出了下面的堆栈跟踪
org.apache.uima.resource.ResourceInitializationException: Annotator class "org.apache.uima.ruta.engine.RutaEngine" was not found. (Descriptor: file:/D:/uimaOutput/ruta-2.1.0/example-projects/ExampleProject/descriptor/BasicEngine.xml)
at org.apache.uima.analysis_engine.impl.PrimitiveAnalysisEngine_impl.initializeAnalysisComponent(PrimitiveAnalysisEngine_impl.java:209)
at org.apache.uima.analysis_engine.impl.PrimitiveAnalysisEngine_impl.initialize(PrimitiveAnalysisEngine_impl.java:158)
at org.apache.uima.impl.AnalysisEngineFactory_impl.produceResource(AnalysisEngineFactory_impl.java:94)
at org.apache.uima.impl.CompositeResourceFactory_impl.produceResource(CompositeResourceFactory_impl.java:62)
at org.apache.uima.UIMAFramework.produceResource(UIMAFramework.java:279)
at org.apache.uima.UIMAFramework.produceAnalysisEngine(UIMAFramework.java:369)
at org.apache.uima.examples.ExampleApplication.main(ExampleApplication.java:81)
Caused by: java.lang.ClassNotFoundException: org.apache.uima.ruta.engine.RutaEngine
at java.net.URLClassLoader$1.run(URLClassLoader.java:366)
at java.net.URLClassLoader$1.run(URLClassLoader.java:355)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:354)
at java.lang.ClassLoader.loadClass(ClassLoader.java:423)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308)
at java.lang.ClassLoader.loadClass(ClassLoader.java:356)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Class.java:186)
at org.apache.uima.analysis_engine.impl.PrimitiveAnalysisEngine_impl.initializeAnalysisComponent(PrimitiveAnalysisEngine_impl.java:206)
... 6 more
我被困住了。请帮忙。
编辑:
上面编写的 Java API 来自 uima 文档中的 uimaj-example。我在类路径中添加了一些 ruta jar 和通用 jar,之后文件执行良好。