2

I'm working on a Maven project which dynamically executes some ruta scripts to annotate some tags and process the output in java.

Now that I want to use NLP (mostly dkpro) first and then pass the output to the ruta scripts (pipeline) and process further. How to achieve it ?


Edited:

Below is my new script;

    AnalysisEngineDescription pipeline = createEngineDescription(createEngineDescription(OpenNlpSegmenter.class),
            createEngineDescription(OpenNlpPosTagger.class),
            AnalysisEngineFactory.createEngineDescription(RutaEngine.class, RutaEngine.PARAM_MAIN_SCRIPT,
                    "com.textjuicer.ruta.date.Author_updated"),
            createEngineDescription(ConsoleWriter.class));

Error:

Not able to resolve type: Reference

May 25, 2016 6:45:43 PM org.apache.uima.analysis_engine.impl.AggregateAnalysisEngine_impl processAndOutputNewCASes(273) SEVERE: Exception occurred org.apache.uima.analysis_engine.AnalysisEngineProcessException: Annotator processing failed.
at org.apache.uima.ruta.engine.RutaEngine.process(RutaEngine.java:563) at org.apache.uima.analysis_component.JCasAnnotator_ImplBase.process(JCasAnnotator_ImplBase.java:48) at org.apache.uima.analysis_engine.impl.PrimitiveAnalysisEngine_impl.callAnalysisComponentProcess(PrimitiveAnalysisEngine_impl.java:378) at org.apache.uima.analysis_engine.impl.PrimitiveAnalysisEngine_impl.processAndOutputNewCASes(PrimitiveAnalysisEngine_impl.java:298) at org.apache.uima.analysis_engine.asb.impl.ASB_impl$AggregateCasIterator.processUntilNextOutputCas(ASB_impl.java:568) at org.apache.uima.analysis_engine.asb.impl.ASB_impl$AggregateCasIterator.(ASB_impl.java:410) at org.apache.uima.analysis_engine.asb.impl.ASB_impl.process(ASB_impl.java:343) at org.apache.uima.analysis_engine.impl.AggregateAnalysisEngine_impl.processAndOutputNewCASes(AggregateAnalysisEngine_impl.java:265) at org.apache.uima.analysis_engine.asb.impl.ASB_impl$AggregateCasIterator.processUntilNextOutputCas(ASB_impl.java:568) at org.apache.uima.analysis_engine.asb.impl.ASB_impl$AggregateCasIterator.(ASB_impl.java:410) at org.apache.uima.analysis_engine.asb.impl.ASB_impl.process(ASB_impl.java:343) at org.apache.uima.analysis_engine.impl.AggregateAnalysisEngine_impl.processAndOutputNewCASes(AggregateAnalysisEngine_impl.java:265) at org.apache.uima.analysis_engine.impl.AnalysisEngineImplBase.process(AnalysisEngineImplBase.java:267) at org.apache.uima.fit.pipeline.SimplePipeline.runPipeline(SimplePipeline.java:170) at org.apache.uima.fit.pipeline.SimplePipeline.runPipeline(SimplePipeline.java:191) at com.textjuicer.ruta.date.ArtifactAnnotator.runNLP(ArtifactAnnotator.java:225) at com.textjuicer.ruta.date.ArtifactAnnotator.getAllAnnotations(ArtifactAnnotator.java:70) at com.textjuicer.ruta.date.ArtifactAnnotator.main(ArtifactAnnotator.java:38) Caused by: java.lang.IllegalArgumentException: Not able to resolve type: Reference at org.apache.uima.ruta.expression.type.SimpleTypeExpression.getType(SimpleTypeExpression.java:48) at org.apache.uima.ruta.rule.RegExpRule.getGroup2Types(RegExpRule.java:148) at org.apache.uima.ruta.rule.RegExpRule.apply(RegExpRule.java:80) at org.apache.uima.ruta.RutaScriptBlock.apply(RutaScriptBlock.java:63) at org.apache.uima.ruta.RutaModule.apply(RutaModule.java:48) at org.apache.uima.ruta.engine.RutaEngine.process(RutaEngine.java:561) ... 17 more

Exception in thread "main" org.apache.uima.analysis_engine.AnalysisEngineProcessException: Annotator processing failed.
at org.apache.uima.ruta.engine.RutaEngine.process(RutaEngine.java:563) at org.apache.uima.analysis_component.JCasAnnotator_ImplBase.process(JCasAnnotator_ImplBase.java:48) at org.apache.uima.analysis_engine.impl.PrimitiveAnalysisEngine_impl.callAnalysisComponentProcess(PrimitiveAnalysisEngine_impl.java:378) at org.apache.uima.analysis_engine.impl.PrimitiveAnalysisEngine_impl.processAndOutputNewCASes(PrimitiveAnalysisEngine_impl.java:298) at org.apache.uima.analysis_engine.asb.impl.ASB_impl$AggregateCasIterator.processUntilNextOutputCas(ASB_impl.java:568) at org.apache.uima.analysis_engine.asb.impl.ASB_impl$AggregateCasIterator.(ASB_impl.java:410) at org.apache.uima.analysis_engine.asb.impl.ASB_impl.process(ASB_impl.java:343) at org.apache.uima.analysis_engine.impl.AggregateAnalysisEngine_impl.processAndOutputNewCASes(AggregateAnalysisEngine_impl.java:265) at org.apache.uima.analysis_engine.asb.impl.ASB_impl$AggregateCasIterator.processUntilNextOutputCas(ASB_impl.java:568) at org.apache.uima.analysis_engine.asb.impl.ASB_impl$AggregateCasIterator.(ASB_impl.java:410) at org.apache.uima.analysis_engine.asb.impl.ASB_impl.process(ASB_impl.java:343) at org.apache.uima.analysis_engine.impl.AggregateAnalysisEngine_impl.processAndOutputNewCASes(AggregateAnalysisEngine_impl.java:265) at org.apache.uima.analysis_engine.impl.AnalysisEngineImplBase.process(AnalysisEngineImplBase.java:267) at org.apache.uima.fit.pipeline.SimplePipeline.runPipeline(SimplePipeline.java:170) at org.apache.uima.fit.pipeline.SimplePipeline.runPipeline(SimplePipeline.java:191) at com.textjuicer.ruta.date.ArtifactAnnotator.runNLP(ArtifactAnnotator.java:225) at com.textjuicer.ruta.date.ArtifactAnnotator.getAllAnnotations(ArtifactAnnotator.java:70) at com.textjuicer.ruta.date.ArtifactAnnotator.main(ArtifactAnnotator.java:38) Caused by: java.lang.IllegalArgumentException: Not able to resolve type: Reference at org.apache.uima.ruta.expression.type.SimpleTypeExpression.getType(SimpleTypeExpression.java:48) at org.apache.uima.ruta.rule.RegExpRule.getGroup2Types(RegExpRule.java:148) at org.apache.uima.ruta.rule.RegExpRule.apply(RegExpRule.java:80) at org.apache.uima.ruta.RutaScriptBlock.apply(RutaScriptBlock.java:63) at org.apache.uima.ruta.RutaModule.apply(RutaModule.java:48) at org.apache.uima.ruta.engine.RutaEngine.process(RutaEngine.java:561) ... 17 more

4
  • The type system of the created CAS does not contain the type. Is the type Reference declared in the ruta script? May 25, 2016 at 15:52
  • Yes it is declared and the complete script runs fine in a UIMA ruta project. It also runs fine in my maven project when not in a pipeline as below; // final AnalysisEngine engine = AnalysisEngineFactory // .createEngine("com.textjuicer.ruta.date.Author_updatedEngine"); // final CAS cas = engine.newCAS(); // // cas.setDocumentText(artifact); // engine.process(cas); May 26, 2016 at 6:11
  • If using dkpro/any other typesystems directly from ruta, how should I do it ? Where can I get the typesystem xml file from ? What else to be done to use dkpro directly from my ruta script ? May 26, 2016 at 6:22
  • Yes, the engine does not know about the types. You need to import the dkpro type system with TYPESYSTEM or IMPORT. Or create the cas not using the engine but the type system descriptors. The dkpro type system xml can be created by using the JCasFactory and then serliazing it to xml. Put the typesystem where the rules can find it: somewhere in the classpath or in the descriptor folder. A (maybe old) type system xml can be found here: svn.apache.org/repos/asf/uima/ruta/trunk/example-projects/… May 26, 2016 at 15:15

1 Answer 1

2

You can add Ruta script simply as an analysis engine at the end of your DKPro Pipeline. The exact code mainly depends on how you build and run your pipeline.

Adapted from the uimafit documentation:

// your collecton reader
CollectionReaderDescription reader = 
  CollectionReaderFactory.createReaderDescription(
    TextReader.class, 
    TextReader.PARAM_INPUT, "/home/uimafit/documents");

// some DKPro Code component
AnalysisEngineDescription dkpro= 
  AnalysisEngineFactory.createEngineDescription(
    Tokenizer.class);

AnalysisEngineDescription ruta = 
  AnalysisEngineFactory.createEngineDescription(
    RutaEngine.class, 
    RutaEngine.PARAM_MAIN_SCRIPT, "Main.ruta");

// some writer
AnalysisEngineDescription writer= 
  AnalysisEngineFactory.createEngineDescription(
    XmiWriter.class, 
    XmiWriter.PARAM_OUTPUT, "/home/uimafit/output");

SimplePipeline.runPipeline(reader, dkpro, ruta, writer);

You can create an analysis engine of your Ruta script by using the uimaFIT factories by either specifying the mainScript parameter or by directly configuring the rules with PARAM_RULES. You can also use the xml descriptor of the Ruta script to create the analysis engine.

If the ruta script declares new types, then either the xml descriptor has to be used to create the analysis engine, or the types.txt file of uimaFIT needs to be extended by the generated type system of the script. (... or the type system need to be included in some other way.)

If the ruta script imports and calls other scripts, then the generated descriptor need to be used, or the corresponding parameters need to be set correctly, e.g., additionalScripts. Same is true for imported analysis engines.

If you import the NLP/DKPro typesystem in your Ruta script, then you can simply write rules using the DKPro annotations.

(I am a developer of UIMA Ruta)

5
  • I extended the answer May 25, 2016 at 15:54
  • I created the pipeline as u said (with OpenNlpSegmenter & OpenNlpPosTagger instead of Tokenizer), but couldn't figure out how to use the output of these nlp tags directly in my ruta script. Can you please guide ? Jun 28, 2016 at 6:41
  • You can simply write rules that build upon these annotations like any other annotations. You should also import the type system of these analsis engines in your ruta script with TYPESYSTEM or IMPORT. Are there an specific problems or exceptions? Jul 7, 2016 at 7:38
  • How do you generated a type system from a RUTA script? Aug 18, 2016 at 19:50
  • A typesystem (descriptor) containing the types declared in a ruta script and also containing all imported types, that is the type system of the ruta script, is automatically created by the builder in old ruta project in the workbench, or by the ruta maven plugin in maven-built projects. Both approaches use the RutaDescriptorFactory, which can also be utilized to create them programmatically. Aug 19, 2016 at 8:11

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.