[
https://issues.apache.org/jira/browse/UIMA-4480?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=14631489#comment-14631489
]
Min Jiang commented on UIMA-4480:
---------------------------------
I am trying to use the java code to run the ruta script as follows,
Collection<TypeSystemDescription> tsds = new ArrayList<TypeSystemDescription>();
ResourceManager resMgr =
UIMAFramework.newDefaultResourceManager();
URL aedesc = new File(descriptorPath
+"/descriptor/BasicEngine.xml").toURL();
XMLInputSource inae = new XMLInputSource(aedesc);
ResourceSpecifier specifier =
UIMAFramework.getXMLParser().parseResourceSpecifier(inae);
AnalysisEngineDescription aed =
(AnalysisEngineDescription) specifier;
TypeSystemDescription basicTypeSystem =
aed.getAnalysisEngineMetaData().getTypeSystem();
tsds.add(basicTypeSystem);
//add default type system
URL aedesc2 = new File(descriptorPath
+"/descriptor/defaultEngine.xml").toURL();
XMLInputSource inae2 = new XMLInputSource(aedesc2);
ResourceSpecifier specifier2 =
UIMAFramework.getXMLParser().parseResourceSpecifier(inae2);
AnalysisEngineDescription aed2 =
(AnalysisEngineDescription) specifier2;
TypeSystemDescription defaultTypeSystem =
aed2.getAnalysisEngineMetaData().getTypeSystem();
tsds.add(defaultTypeSystem);
// add some other type system descriptors
// that are needed by your script file
TypeSystemDescription mergeTypeSystems =
CasCreationUtils.mergeTypeSystems(tsds);
aed.getAnalysisEngineMetaData().setTypeSystem(mergeTypeSystems);
aed.resolveImports(resMgr);
AnalysisEngine ae = UIMAFramework.produceAnalysisEngine(aed,
resMgr, null);
File scriptFile = new File(ruleFile);
ae.setConfigParameterValue(RutaEngine.PARAM_SCRIPT_PATHS,
new String[] { scriptFile.getParentFile().getAbsolutePath()
});
String name = scriptFile.getName().substring(0,
scriptFile.getName().length() - 5);
ae.setConfigParameterValue(RutaEngine.PARAM_MAIN_SCRIPT, name);
ae.reconfigure();
ae.process(aJCas);
defaultEngine.xml are automatically generated by script, which include some new
type I declared in our script.
in the defualtTypeSystem.xml, it has:
<types>
<typeDescription>
<name>default.PERSON</name>
<description>Type defined in default</description>
<supertypeName>uima.tcas.Annotation</supertypeName>
</typeDescription>
</types>
It turns out the following error when we run the code, I wonder how to make the
analysis engine recognize the new type declared in the script in Java code?
Caused by: java.lang.IllegalArgumentException: Not able to resolve type: PERSON
at
org.apache.uima.ruta.expression.type.SimpleTypeExpression.getType(SimpleTypeExpression.java:47)
at
org.apache.uima.ruta.action.AbstractMarkAction.createAnnotation(AbstractMarkAction.java:42)
at org.apache.uima.ruta.action.MarkAction.execute(MarkAction.java:57)
at
org.apache.uima.ruta.rule.AbstractRuleElement.apply(AbstractRuleElement.java:130)
at
org.apache.uima.ruta.rule.RuleElementCaretaker.applyRuleElements(RuleElementCaretaker.java:111)
at
org.apache.uima.ruta.rule.ComposedRuleElement.applyRuleElements(ComposedRuleElement.java:559)
at
org.apache.uima.ruta.rule.AbstractRuleElement.doneMatching(AbstractRuleElement.java:84)
at
org.apache.uima.ruta.rule.ComposedRuleElement.fallback(ComposedRuleElement.java:480)
at
org.apache.uima.ruta.rule.ComposedRuleElement.fallbackContinue(ComposedRuleElement.java:384)
at
org.apache.uima.ruta.rule.RutaRuleElement.startMatch(RutaRuleElement.java:106)
at
org.apache.uima.ruta.rule.ComposedRuleElement.startMatch(ComposedRuleElement.java:73)
at org.apache.uima.ruta.rule.RutaRule.apply(RutaRule.java:47)
at org.apache.uima.ruta.rule.RutaRule.apply(RutaRule.java:40)
at org.apache.uima.ruta.rule.RutaRule.apply(RutaRule.java:29)
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:494)
> Cannot declar new type in Java code to apply Ruta rules
> -------------------------------------------------------
>
> Key: UIMA-4480
> URL: https://issues.apache.org/jira/browse/UIMA-4480
> Project: UIMA
> Issue Type: Bug
> Components: ruta
> Affects Versions: 2.2.1ruta
> Reporter: Min Jiang
> Assignee: Peter Klügl
> Fix For: 2.3.1ruta
>
>
> I used Java code to apply UIMA Ruta rules, but with declare statement, ruta
> cannot recognize the new created annotation type.
> Here is the code I used:
> String rutaStr2 = "DECLARE person; W{REGEXP(\"Patient\") -> MARK(person)};";
> Ruta.apply( aJCas.getCas(), rutaStr2 );
> The error is like:
> Jun 24, 2015 3:01:07 PM
> org.apache.uima.analysis_engine.impl.PrimitiveAnalysisEngine_impl
> callAnalysisComponentProcess(417)
> SEVERE: Exception occurred
> org.apache.uima.analysis_engine.AnalysisEngineProcessException: Annotator
> processing failed.
> at org.apache.uima.ruta.engine.RutaEngine.process(RutaEngine.java:496)
> 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:385)
> at
> org.apache.uima.analysis_engine.impl.PrimitiveAnalysisEngine_impl.processAndOutputNewCASes(PrimitiveAnalysisEngine_impl.java:309)
> at
> org.apache.uima.analysis_engine.impl.AnalysisEngineImplBase.process(AnalysisEngineImplBase.java:267)
> at org.apache.uima.ruta.engine.Ruta.apply(Ruta.java:75)
> at org.apache.uima.ruta.engine.Ruta.apply(Ruta.java:83)
> at
> edu.uth.clamp.nlp.attr.ast.LinearAssertion.main(LinearAssertion.java:610)
> Caused by: java.lang.IllegalArgumentException: Not able to resolve type:
> animal
> at
> org.apache.uima.ruta.expression.type.SimpleTypeExpression.getType(SimpleTypeExpression.java:47)
> at
> org.apache.uima.ruta.action.AbstractMarkAction.createAnnotation(AbstractMarkAction.java:42)
> at org.apache.uima.ruta.action.MarkAction.execute(MarkAction.java:57)
> at
> org.apache.uima.ruta.rule.AbstractRuleElement.apply(AbstractRuleElement.java:130)
> at
> org.apache.uima.ruta.rule.RuleElementCaretaker.applyRuleElements(RuleElementCaretaker.java:111)
> at
> org.apache.uima.ruta.rule.ComposedRuleElement.applyRuleElements(ComposedRuleElement.java:559)
> at
> org.apache.uima.ruta.rule.AbstractRuleElement.doneMatching(AbstractRuleElement.java:84)
> at
> org.apache.uima.ruta.rule.ComposedRuleElement.fallback(ComposedRuleElement.java:480)
> at
> org.apache.uima.ruta.rule.ComposedRuleElement.fallbackContinue(ComposedRuleElement.java:384)
> at
> org.apache.uima.ruta.rule.RutaRuleElement.startMatch(RutaRuleElement.java:106)
> at
> org.apache.uima.ruta.rule.ComposedRuleElement.startMatch(ComposedRuleElement.java:73)
> at org.apache.uima.ruta.rule.RutaRule.apply(RutaRule.java:47)
> at org.apache.uima.ruta.rule.RutaRule.apply(RutaRule.java:40)
> at org.apache.uima.ruta.rule.RutaRule.apply(RutaRule.java:29)
> 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:494)
> ... 7 more
> org.apache.uima.analysis_engine.AnalysisEngineProcessException: Annotator
> processing failed.
> at org.apache.uima.ruta.engine.RutaEngine.process(RutaEngine.java:496)
> 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:385)
> at
> org.apache.uima.analysis_engine.impl.PrimitiveAnalysisEngine_impl.processAndOutputNewCASes(PrimitiveAnalysisEngine_impl.java:309)
> at
> org.apache.uima.analysis_engine.impl.AnalysisEngineImplBase.process(AnalysisEngineImplBase.java:267)
> at org.apache.uima.ruta.engine.Ruta.apply(Ruta.java:75)
> at org.apache.uima.ruta.engine.Ruta.apply(Ruta.java:83)
> at
> edu.uth.clamp.nlp.attr.ast.LinearAssertion.main(LinearAssertion.java:610)
> Caused by: java.lang.IllegalArgumentException: Not able to resolve type:
> animal
> at
> org.apache.uima.ruta.expression.type.SimpleTypeExpression.getType(SimpleTypeExpression.java:47)
> at
> org.apache.uima.ruta.action.AbstractMarkAction.createAnnotation(AbstractMarkAction.java:42)
> at org.apache.uima.ruta.action.MarkAction.execute(MarkAction.java:57)
> at
> org.apache.uima.ruta.rule.AbstractRuleElement.apply(AbstractRuleElement.java:130)
> at
> org.apache.uima.ruta.rule.RuleElementCaretaker.applyRuleElements(RuleElementCaretaker.java:111)
> at
> org.apache.uima.ruta.rule.ComposedRuleElement.applyRuleElements(ComposedRuleElement.java:559)
> at
> org.apache.uima.ruta.rule.AbstractRuleElement.doneMatching(AbstractRuleElement.java:84)
> at
> org.apache.uima.ruta.rule.ComposedRuleElement.fallback(ComposedRuleElement.java:480)
> at
> org.apache.uima.ruta.rule.ComposedRuleElement.fallbackContinue(ComposedRuleElement.java:384)
> at
> org.apache.uima.ruta.rule.RutaRuleElement.startMatch(RutaRuleElement.java:106)
> at
> org.apache.uima.ruta.rule.ComposedRuleElement.startMatch(ComposedRuleElement.java:73)
> at org.apache.uima.ruta.rule.RutaRule.apply(RutaRule.java:47)
> at org.apache.uima.ruta.rule.RutaRule.apply(RutaRule.java:40)
> at org.apache.uima.ruta.rule.RutaRule.apply(RutaRule.java:29)
> 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:494)
> ... 7 more
--
This message was sent by Atlassian JIRA
(v6.3.4#6332)