Hi,

which ruta version do you use? From the exception below, I'd guess
2.2.1. You need functionality introduced in 2.3.0. Besides that, you
should update anyway since a lot of bugs have been fixed in 2.3.0

Am 25.06.2015 um 20:33 schrieb Min Jiang:
> Hello Peter,
>
> Thanks very much for your comments.
>
> Since we need to  apply rules containing defining a new type in java code,  I 
> would like to choose the first option you provided as below:
> generate the type system for the script and use it when creating the CAS
>
> I am not familiar with the UIMA source code and interface,  could you please 
> give me some example code snippets to dynamically create a new type defined 
> in the script using java code?

The important methods are:
- RutaDescriptorFactory.parseDescriptorInformation() for parsing the
script and getting the required information about declared types.
- RutaDescriptorFactory.createTypeSystemDescription() for creating the
descriptor object using the result of the first method

Example code how these methods are applied can be found, for example, in
the ruta-maven-plugin RutaGenerateDescriptorMojo.java:
http://svn.apache.org/viewvc/uima/ruta/trunk/ruta-maven-plugin/src/main/java/org/apache/uima/ruta/maven/RutaGenerateDescriptorMojo.java?view=markup

Let me know if you need more information, or a simpler/shorter code snippet.


> I also have another question, we define a dynamic feature (using json in the 
> code ) in a type defined in the type system, when we were calling method 
> "setfeature" in the ruta rules, it comes error as below:

The line
Feature feature =
annotationFS.getType().getFeatureByBaseName(featureString);
returns null, so I assume that the feature is not defined in the
typesystem of the CAS.

What do you mean exactly with a dynamic feature? Is there an actual
value for that feature in the annotation? I haven't used the json
functionality in UIMA yet.

Best,

Peter

>  Jun 25, 2015 1:31:45 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 assign feature 
> value (e.g., coveredText).
>       at 
> org.apache.uima.ruta.action.SetFeatureAction.execute(SetFeatureAction.java:115)
>       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 assign feature 
> value (e.g., coveredText).
>       at 
> org.apache.uima.ruta.action.SetFeatureAction.execute(SetFeatureAction.java:115)
>       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
>
> Thanks.
> Min
>
>
> ________________________________________
> From: Peter Klügl (JIRA) <[email protected]>
> Sent: Thursday, June 25, 2015 2:57 AM
> To: Min Jiang
> Subject: [jira] [Commented] (UIMA-4480) Cannot declar new type in Java code 
> to apply Ruta rules
>
>     [ 
> https://urldefense.proofpoint.com/v2/url?u=https-3A__issues.apache.org_jira_browse_UIMA-2D4480-3Fpage-3Dcom.atlassian.jira.plugin.system.issuetabpanels-3Acomment-2Dtabpanel-26focusedCommentId-3D14600836-23comment-2D14600836&d=BQIFaQ&c=6vgNTiRn9_pqCD9hKx9JgXN1VapJQ8JVoF8oWH1AgfQ&r=jz3QK4K87Lm_Nwht1EPnpOuO0lNxA_ixkxTg7PAIq2A&m=mirXZjzV5uoNjKYfVBVQxw6osS2Eu9EVXMmCwfVghdw&s=JUvIkvmlK8d7Wem1kJq-VY2yENmn9uanfoF2qDcdF3c&e=
>   ]
>
> Peter Klügl commented on UIMA-4480:
> -----------------------------------
>
> Yes, this is normal behavior. Some explanation from the UIMa perspective 
> without Ruta:
> You create a CAs using a specific type system A and then apply an analysis 
> engine that uses a type system A+X. When the analysis engine tries to access 
> a type of X, it fails. It is not (yet) possible in UIMA to introduce new 
> types in an analysis engine.
>
> In your rule example, X is the "person" type. The exception, however, states 
> that the rules use an "animal" type that is not present in the type system.
>
> The thing is that you cannot use Ruta.apply() with ruta code continaing 
> declare statements this way. The declare statements are ignored when 
> executing ruta rules since they would before have had influenced the type 
> system that is used to create the CAS. The declare statements are solely used 
> by the ruta workbench and the ruta maven plugin for generating the 
> corresponding type system descriptors (there is also java code for creating 
> the java object without an xml file). These have be considered when the CAs 
> is created, either by using them in the creation method or by importing them 
> in the analysis engine that creates the CAS.
>
> What you can do depends on your use case and how you create your CAS:
> - generate the type system for the script and use it when creating the CAS
> - do not use additional types in the rules in Ruta.apply
> - do not use Ruta.apply in your Java code
>
> Does this make sense to you?
>
> Any suggestions to improve this situation are welcome.
>
>
>
>> Cannot declar new type in Java code to apply Ruta rules
>> -------------------------------------------------------
>>
>>                 Key: UIMA-4480
>>                 URL: 
>> https://urldefense.proofpoint.com/v2/url?u=https-3A__issues.apache.org_jira_browse_UIMA-2D4480&d=BQIFaQ&c=6vgNTiRn9_pqCD9hKx9JgXN1VapJQ8JVoF8oWH1AgfQ&r=jz3QK4K87Lm_Nwht1EPnpOuO0lNxA_ixkxTg7PAIq2A&m=mirXZjzV5uoNjKYfVBVQxw6osS2Eu9EVXMmCwfVghdw&s=Pt8sWS4o5C5FJA10uxN7klLqfr69mexkP3BkHjxr5Vw&e=
>>             Project: UIMA
>>          Issue Type: Bug
>>          Components: ruta
>>    Affects Versions: 2.2.1ruta
>>            Reporter: Min Jiang
>>            Assignee: Peter Klügl
>>
>> 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)

Reply via email to