Java API for running UIMA Ruta scripts -
i new uima ruta. made annotators using scripting language. able run them within eclipseide. want write java api automatically run scripts on input provided.
i using same example project provided in uima documentation.
so far have been able this
try { file taedescriptor = null; file inputdir = null; // read , 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 { // resource specifier xml file xmlinputsource in = new xmlinputsource(taedescriptor); resourcespecifier specifier = uimaframework.getxmlparser() .parseresourcespecifier(in); // debugging, output resource specifier // system.out.println(specifier); // create analysis engine analysisengine ae = uimaframework .produceanalysisengine(specifier); // create cas cas cas = ae.newcas(); // files in input directory file[] files = inputdir.listfiles(); if (files == null) { system.out.println("no files process"); } else { // process documents (int = 0; < files.length; i++) { if (!files[i].isdirectory()) { processfile(files[i], ae, cas); } } } ae.destroy(); } } catch (exception e) { e.printstacktrace(); } }
on running above snippet default basicengine.xml , input text file. gives below stack trace
org.apache.uima.resource.resourceinitializationexception: annotator class "org.apache.uima.ruta.engine.rutaengine" not found. (descriptor: file:/d:/uimaoutput/ruta-2.1.0/example-projects/exampleproject/descriptor/basicengine.xml) @ org.apache.uima.analysis_engine.impl.primitiveanalysisengine_impl.initializeanalysiscomponent(primitiveanalysisengine_impl.java:209) @ org.apache.uima.analysis_engine.impl.primitiveanalysisengine_impl.initialize(primitiveanalysisengine_impl.java:158) @ org.apache.uima.impl.analysisenginefactory_impl.produceresource(analysisenginefactory_impl.java:94) @ org.apache.uima.impl.compositeresourcefactory_impl.produceresource(compositeresourcefactory_impl.java:62) @ org.apache.uima.uimaframework.produceresource(uimaframework.java:279) @ org.apache.uima.uimaframework.produceanalysisengine(uimaframework.java:369) @ org.apache.uima.examples.exampleapplication.main(exampleapplication.java:81) caused by: java.lang.classnotfoundexception: org.apache.uima.ruta.engine.rutaengine @ java.net.urlclassloader$1.run(urlclassloader.java:366) @ java.net.urlclassloader$1.run(urlclassloader.java:355) @ java.security.accesscontroller.doprivileged(native method) @ java.net.urlclassloader.findclass(urlclassloader.java:354) @ java.lang.classloader.loadclass(classloader.java:423) @ sun.misc.launcher$appclassloader.loadclass(launcher.java:308) @ java.lang.classloader.loadclass(classloader.java:356) @ java.lang.class.forname0(native method) @ java.lang.class.forname(class.java:186) @ org.apache.uima.analysis_engine.impl.primitiveanalysisengine_impl.initializeanalysiscomponent(primitiveanalysisengine_impl.java:206) ... 6 more
i stuck. please help.
edit:
the java api written above uimaj-example uima documentation. added ruta jars , general jars classpath after file executed fine.
the problem solved in comments of question. want extend answer pointers.
the library ruta-core.jar , dependencies (antlr-runtime, uima, uimafit, ...) need in classpath of application. eclipse plugin ruta-ep-engine.jar contains dependencies beside uima. projects built maven:
<dependency> <groupid>org.apache.uima</groupid> <artifactid>ruta-core</artifactid> <version>2.2.0</version> </dependency>
the documentation contains examples on how call uima ruta scripts within java: 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
for developers want create command line interface, class might interesting: https://svn.apache.org/repos/asf/uima/ruta/trunk/ruta-ep-ide-ui/src/main/java/org/apache/uima/ruta/ide/launching/rutalauncher.java
if in uima environment (cas instance available), method ruta.apply(cas cas, string script) can used applying rules on cas.
for developers prefer use uimafit: https://svn.apache.org/repos/asf/uima/ruta/trunk/ruta-core/src/test/java/org/apache/uima/ruta/engine/uimafittest.java
Comments
Post a Comment