我是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来自uimaj-example来自uima文档。我在classpath中添加了一些ruta jar和普通jar,之后文件执行得很好。
答案 0 :(得分:3)
问题的评论已经解决了这个问题。我只想用指针扩展答案。
库ruta-core.jar及其依赖项(antlr-runtime,uima,uimafit,...)需要位于应用程序的类路径中。 eclipse插件ruta-ep-engine.jar包含uima旁边的依赖项。对于使用maven构建的项目:
<dependency>
<groupId>org.apache.uima</groupId>
<artifactId>ruta-core</artifactId>
<version>2.2.0</version>
</dependency>
该文档包含有关如何从Java中调用UIMA Ruta脚本的示例: https://uima.apache.org/d/ruta-current/tools.ruta.book.html#ugr.tools.ruta.ae.basic https://uima.apache.org/d/ruta-current/tools.ruta.book.html#ugr.tools.ruta.integration
对于想要创建命令行界面的开发人员,此类可能很有趣: https://svn.apache.org/repos/asf/uima/ruta/trunk/ruta-ep-ide-ui/src/main/java/org/apache/uima/ruta/ide/launching/RutaLauncher.java
如果您处于UIMA环境中(CAS实例已经可用),则可以使用方法Ruta.apply(CAS cas,String script)在CAS上应用某些规则。
对于喜欢使用uimaFIT的开发人员: https://svn.apache.org/repos/asf/uima/ruta/trunk/ruta-core/src/test/java/org/apache/uima/ruta/engine/UimafitTest.java
答案 1 :(得分:0)