Uploaded image for project: 'UIMA'
  1. UIMA
  2. UIMA-4480

Cannot declar new type in Java code to apply Ruta rules

    Details

    • Type: Bug
    • Status: Resolved
    • Priority: Major
    • Resolution: Fixed
    • Affects Version/s: 2.2.1ruta
    • Fix Version/s: 2.3.1ruta
    • Component/s: Ruta
    • Labels:
      None

      Description

      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

        Activity

        Hide
        pkluegl Peter Klügl added a comment -

        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.

        Show
        pkluegl Peter Klügl added a comment - 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.
        Hide
        jmlongriver Min Jiang added a comment -

        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,

        However, I am not familiar with the application interface of UIMA, could you please give me some example code snippets to dynamically create a new type defined in the script using java code?

        I really appreciate that.

        Thanks.
        Min

        Show
        jmlongriver Min Jiang added a comment - 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, However, I am not familiar with the application interface of UIMA, could you please give me some example code snippets to dynamically create a new type defined in the script using java code? I really appreciate that. Thanks. Min
        Hide
        pkluegl Peter Klügl added a comment -

        Here's my reply on the dev mailing list for completeness:

        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

        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.

        Concerning dynamic features:

        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.

        Show
        pkluegl Peter Klügl added a comment - Here's my reply on the dev mailing list for completeness: 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 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. Concerning dynamic features: 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.
        Hide
        pkluegl Peter Klügl added a comment -

        Much depends on how you use UIMA or to be more precise, on how you create your CAS. Do you use, for example, a uimaFIT factory method for creating the CAS, or an analysis engine?

        If I know how you create your CAS, then I can provide a simpler code snippet

        Is you code open source?

        Show
        pkluegl Peter Klügl added a comment - Much depends on how you use UIMA or to be more precise, on how you create your CAS. Do you use, for example, a uimaFIT factory method for creating the CAS, or an analysis engine? If I know how you create your CAS, then I can provide a simpler code snippet Is you code open source?
        Hide
        jmlongriver Min Jiang added a comment -

        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)

        Show
        jmlongriver Min Jiang added a comment - 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)
        Hide
        pkluegl Peter Klügl added a comment -

        Looks like the type system in your CAS does not contain that type. How did you create the aJCas object and with which type system? If it is an option you could use the analysis engine to create the CAS.

        btw, if the descriptors is correctly created, then the defaultEngine,xml should contain the type of the BasicEngine.xml already. So you shouln't need to merge the type systems.

        Show
        pkluegl Peter Klügl added a comment - Looks like the type system in your CAS does not contain that type. How did you create the aJCas object and with which type system? If it is an option you could use the analysis engine to create the CAS. btw, if the descriptors is correctly created, then the defaultEngine,xml should contain the type of the BasicEngine.xml already. So you shouln't need to merge the type systems.
        Hide
        jmlongriver Min Jiang added a comment -

        As you suggested, I am trying using only the defaultEngine.xml.
        The code is like:
        ResourceManager resMgr = UIMAFramework.newDefaultResourceManager();

        URL aedesc = new File(descriptorPath File.separator"descriptor"File.separator"defaultEngine.xml").toURL();
        XMLInputSource inae = new XMLInputSource(aedesc);
        ResourceSpecifier specifier = UIMAFramework.getXMLParser().parseResourceSpecifier(inae);
        AnalysisEngineDescription aed = (AnalysisEngineDescription) specifier;
        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);

        I got the error:
        org.apache.uima.resource.ResourceInitializationException: Initialization of annotator class "org.apache.uima.ruta.engine.RutaEngine" failed. (Descriptor: file:/Users/mjiang/Documents/runtime-ClampGUI.product/new/descriptor/defaultEngine.xml)
        at org.apache.uima.analysis_engine.impl.PrimitiveAnalysisEngine_impl.initializeAnalysisComponent(PrimitiveAnalysisEngine_impl.java:265)
        at org.apache.uima.analysis_engine.impl.PrimitiveAnalysisEngine_impl.initialize(PrimitiveAnalysisEngine_impl.java:170)
        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.produceResource(UIMAFramework.java:331)
        at org.apache.uima.UIMAFramework.produceAnalysisEngine(UIMAFramework.java:448)
        at edu.uth.ccb.clinicalnlp.processor.ner.RutaRulebasedMedicalNameEntityRecognizer.process(RutaRulebasedMedicalNameEntityRecognizer.java:263)
        at edu.uth.ccb.clamp.job.RunPipelineJob.run(RunPipelineJob.java:103)
        at org.eclipse.core.internal.jobs.Worker.run(Worker.java:54)
        Caused by: org.apache.uima.resource.ResourceInitializationException
        at org.apache.uima.ruta.engine.RutaEngine.initialize(RutaEngine.java:468)
        at org.apache.uima.analysis_engine.impl.PrimitiveAnalysisEngine_impl.initializeAnalysisComponent(PrimitiveAnalysisEngine_impl.java:263)
        ... 9 more
        Caused by: org.apache.uima.analysis_engine.AnalysisEngineProcessException
        at org.apache.uima.ruta.engine.RutaEngine.initializeScript(RutaEngine.java:675)
        at org.apache.uima.ruta.engine.RutaEngine.initialize(RutaEngine.java:466)
        ... 10 more
        Caused by: java.io.FileNotFoundException: Script [default] cannot be found at [{}] or classpath with extension .ruta
        ... 12 more

        "defaultEngine.xml" include the BasicEngine.xml and the new type created by script, which is like:

        <typeSystemDescription>
        <imports>
        <import location="defaultTypeSystem.xml"/>
        </imports>
        </typeSystemDescription>
        <typePriorities>
        <priorityList>
        <type>org.apache.uima.ruta.type.RutaFrame</type>
        <type>uima.tcas.Annotation</type>
        <type>org.apache.uima.ruta.type.RutaBasic</type>
        </priorityList>
        </typePriorities>
        <fsIndexCollection/>
        <capabilities>
        <capability>
        <inputs/>
        <outputs/>
        <languagesSupported/>
        </capability>
        <capability>
        <inputs>
        <type>default.PERSON</type>
        </inputs>
        <outputs>
        <type>default.PERSON</type>
        </outputs>
        <languagesSupported/>
        </capability>
        </capabilities>
        <operationalProperties>
        <modifiesCas>true</modifiesCas>
        <multipleDeploymentAllowed>true</multipleDeploymentAllowed>
        <outputsNewCASes>true</outputsNewCASes>
        </operationalProperties>
        </analysisEngineMetaData>
        <resourceManagerConfiguration/>

        Show
        jmlongriver Min Jiang added a comment - As you suggested, I am trying using only the defaultEngine.xml. The code is like: ResourceManager resMgr = UIMAFramework.newDefaultResourceManager(); URL aedesc = new File(descriptorPath File.separator "descriptor" File.separator "defaultEngine.xml").toURL(); XMLInputSource inae = new XMLInputSource(aedesc); ResourceSpecifier specifier = UIMAFramework.getXMLParser().parseResourceSpecifier(inae); AnalysisEngineDescription aed = (AnalysisEngineDescription) specifier; 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); I got the error: org.apache.uima.resource.ResourceInitializationException: Initialization of annotator class "org.apache.uima.ruta.engine.RutaEngine" failed. (Descriptor: file:/Users/mjiang/Documents/runtime-ClampGUI.product/new/descriptor/defaultEngine.xml ) at org.apache.uima.analysis_engine.impl.PrimitiveAnalysisEngine_impl.initializeAnalysisComponent(PrimitiveAnalysisEngine_impl.java:265) at org.apache.uima.analysis_engine.impl.PrimitiveAnalysisEngine_impl.initialize(PrimitiveAnalysisEngine_impl.java:170) 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.produceResource(UIMAFramework.java:331) at org.apache.uima.UIMAFramework.produceAnalysisEngine(UIMAFramework.java:448) at edu.uth.ccb.clinicalnlp.processor.ner.RutaRulebasedMedicalNameEntityRecognizer.process(RutaRulebasedMedicalNameEntityRecognizer.java:263) at edu.uth.ccb.clamp.job.RunPipelineJob.run(RunPipelineJob.java:103) at org.eclipse.core.internal.jobs.Worker.run(Worker.java:54) Caused by: org.apache.uima.resource.ResourceInitializationException at org.apache.uima.ruta.engine.RutaEngine.initialize(RutaEngine.java:468) at org.apache.uima.analysis_engine.impl.PrimitiveAnalysisEngine_impl.initializeAnalysisComponent(PrimitiveAnalysisEngine_impl.java:263) ... 9 more Caused by: org.apache.uima.analysis_engine.AnalysisEngineProcessException at org.apache.uima.ruta.engine.RutaEngine.initializeScript(RutaEngine.java:675) at org.apache.uima.ruta.engine.RutaEngine.initialize(RutaEngine.java:466) ... 10 more Caused by: java.io.FileNotFoundException: Script [default] cannot be found at [{}] or classpath with extension .ruta ... 12 more "defaultEngine.xml" include the BasicEngine.xml and the new type created by script, which is like: <typeSystemDescription> <imports> <import location="defaultTypeSystem.xml"/> </imports> </typeSystemDescription> <typePriorities> <priorityList> <type>org.apache.uima.ruta.type.RutaFrame</type> <type>uima.tcas.Annotation</type> <type>org.apache.uima.ruta.type.RutaBasic</type> </priorityList> </typePriorities> <fsIndexCollection/> <capabilities> <capability> <inputs/> <outputs/> <languagesSupported/> </capability> <capability> <inputs> <type>default.PERSON</type> </inputs> <outputs> <type>default.PERSON</type> </outputs> <languagesSupported/> </capability> </capabilities> <operationalProperties> <modifiesCas>true</modifiesCas> <multipleDeploymentAllowed>true</multipleDeploymentAllowed> <outputsNewCASes>true</outputsNewCASes> </operationalProperties> </analysisEngineMetaData> <resourceManagerConfiguration/>
        Hide
        pkluegl Peter Klügl added a comment -

        Hmm... this is very strange. The exception indicates that the script default.ruta cannot be found, neither in the scriptPaths nor the classpath. This is strange because you set the scriptPaths but the exception says that it is empty. Are you sure that you apply the code above when the exception occurs? Can you check using the debugger if the configuration parameter is actually set? Did the exception already occur for UIMAFramework.produceAnalysisEngine()?

        btw, you also shouldn't need to set the configuration parameters since they should be correctly set by the maven build process.

        I am sorry that so many problems occur. Normally, that should not happen at all.

        The problem before is caused by the creation of the CAS. Did you check the used type system?

        In case your code is somewhere on github or similar, I could take a look at it directly if that is an option for you.

        Show
        pkluegl Peter Klügl added a comment - Hmm... this is very strange. The exception indicates that the script default.ruta cannot be found, neither in the scriptPaths nor the classpath. This is strange because you set the scriptPaths but the exception says that it is empty. Are you sure that you apply the code above when the exception occurs? Can you check using the debugger if the configuration parameter is actually set? Did the exception already occur for UIMAFramework.produceAnalysisEngine()? btw, you also shouldn't need to set the configuration parameters since they should be correctly set by the maven build process. I am sorry that so many problems occur. Normally, that should not happen at all. The problem before is caused by the creation of the CAS. Did you check the used type system? In case your code is somewhere on github or similar, I could take a look at it directly if that is an option for you.
        Hide
        jmlongriver Min Jiang added a comment -

        Such is error is caused by the segments in the defaultEngine.xml as follows:

        <nameValuePair>
        <name>mainScript</name>
        <value>
        <string>default</string>
        </value>
        </nameValuePair>
        <nameValuePair>
        <name>scriptPaths</name>
        <value>
        <array/>
        </value>
        </nameValuePair>
        <nameValuePair>
        <name>descriptorPaths</name>
        <value>
        <array>
        <string>/Users/mjiang/Documents/runtime-ClampGUI.product/new/descriptor</string>
        </array>
        </value>
        </nameValuePair>
        <nameValuePair>
        <name>resourcePaths</name>
        <value>
        <array>
        <string>/Users/mjiang/Documents/runtime-ClampGUI.product/new/resources</string>
        </array>
        </value>
        </nameValuePair>
        <nameValuePair>
        <name>additionalScripts</name>
        <value>
        <array/>
        </value>
        </nameValuePair>
        <nameValuePair>
        <name>additionalEngines</name>
        <value>
        <array/>
        </value>
        </nameValuePair>
        <nameValuePair>
        <name>additionalUimafitEngines</name>
        <value>
        <array/>
        </value>
        </nameValuePair>
        <nameValuePair>
        <name>additionalExtensions</name>
        <value>
        <array>
        <string>org.apache.uima.ruta.example.extensions.ExampleConditionExtension</string>
        <string>org.apache.uima.ruta.example.extensions.ExampleActionExtension</string>
        <string>org.apache.uima.ruta.example.extensions.ExampleBooleanFunctionExtension</string>
        <string>org.apache.uima.ruta.string.bool.BooleanOperationsExtension</string>
        <string>org.apache.uima.ruta.example.extensions.ExampleNumberFunctionExtension</string>
        <string>org.apache.uima.ruta.example.extensions.ExampleStringFunctionExtension</string>
        <string>org.apache.uima.ruta.string.StringOperationsExtension</string>
        <string>org.apache.uima.ruta.example.extensions.ExampleTypeFunctionExtension</string>
        <string>org.apache.uima.ruta.example.extensions.ExampleBlockExtension</string>
        <string>org.apache.uima.ruta.block.OnlyFirstBlockExtension</string>
        <string>org.apache.uima.ruta.block.OnlyOnceBlockExtension</string>
        <string>org.apache.uima.ruta.block.fst.FSTBlockExtension</string>
        </array>
        </value>
        </nameValuePair>
        <nameValuePair>
        <name>additionalEngineLoaders</name>
        <value>
        <array/>
        </value>
        </nameValuePair>

        if I remove such a section, I will get the error as before, "cannot resolve" the new type "person".

        Basically i am usng aJcasFactory to create a new JCAS object before I load the defaultEngine in the code, so if I want the AE recognize new type I created, what should I do to
        create new type in JCAS object, do you have any kind of code segment to show that?

        Thanks.
        Min

        Show
        jmlongriver Min Jiang added a comment - Such is error is caused by the segments in the defaultEngine.xml as follows: <nameValuePair> <name>mainScript</name> <value> <string>default</string> </value> </nameValuePair> <nameValuePair> <name>scriptPaths</name> <value> <array/> </value> </nameValuePair> <nameValuePair> <name>descriptorPaths</name> <value> <array> <string>/Users/mjiang/Documents/runtime-ClampGUI.product/new/descriptor</string> </array> </value> </nameValuePair> <nameValuePair> <name>resourcePaths</name> <value> <array> <string>/Users/mjiang/Documents/runtime-ClampGUI.product/new/resources</string> </array> </value> </nameValuePair> <nameValuePair> <name>additionalScripts</name> <value> <array/> </value> </nameValuePair> <nameValuePair> <name>additionalEngines</name> <value> <array/> </value> </nameValuePair> <nameValuePair> <name>additionalUimafitEngines</name> <value> <array/> </value> </nameValuePair> <nameValuePair> <name>additionalExtensions</name> <value> <array> <string>org.apache.uima.ruta.example.extensions.ExampleConditionExtension</string> <string>org.apache.uima.ruta.example.extensions.ExampleActionExtension</string> <string>org.apache.uima.ruta.example.extensions.ExampleBooleanFunctionExtension</string> <string>org.apache.uima.ruta.string.bool.BooleanOperationsExtension</string> <string>org.apache.uima.ruta.example.extensions.ExampleNumberFunctionExtension</string> <string>org.apache.uima.ruta.example.extensions.ExampleStringFunctionExtension</string> <string>org.apache.uima.ruta.string.StringOperationsExtension</string> <string>org.apache.uima.ruta.example.extensions.ExampleTypeFunctionExtension</string> <string>org.apache.uima.ruta.example.extensions.ExampleBlockExtension</string> <string>org.apache.uima.ruta.block.OnlyFirstBlockExtension</string> <string>org.apache.uima.ruta.block.OnlyOnceBlockExtension</string> <string>org.apache.uima.ruta.block.fst.FSTBlockExtension</string> </array> </value> </nameValuePair> <nameValuePair> <name>additionalEngineLoaders</name> <value> <array/> </value> </nameValuePair> if I remove such a section, I will get the error as before, "cannot resolve" the new type "person". Basically i am usng aJcasFactory to create a new JCAS object before I load the defaultEngine in the code, so if I want the AE recognize new type I created, what should I do to create new type in JCAS object, do you have any kind of code segment to show that? Thanks. Min
        Hide
        jmlongriver Min Jiang added a comment -

        I have a question, if I declare a new type in the script, how to generate the responding class file by calling api?

        Thanks.
        Min

        Show
        jmlongriver Min Jiang added a comment - I have a question, if I declare a new type in the script, how to generate the responding class file by calling api? Thanks. Min
        Hide
        pkluegl Peter Klügl added a comment -

        The best way is probably to use the maven plugins.

        First, generate the type system xml with the ruta-maven-plugin:
        https://uima.apache.org/d/ruta-current/tools.ruta.book.html#d5e3271

        Then, generate the JCas classes using the jcasgen-maven-plugin:
        https://uima.apache.org/d/uimaj-2.8.0/tools.html#ugr.tools.jcasgen.maven_plugin

        Note that the maven phases need to be correct, e.g., the second plugin needs to be executed after the first one.

        Show
        pkluegl Peter Klügl added a comment - The best way is probably to use the maven plugins. First, generate the type system xml with the ruta-maven-plugin: https://uima.apache.org/d/ruta-current/tools.ruta.book.html#d5e3271 Then, generate the JCas classes using the jcasgen-maven-plugin: https://uima.apache.org/d/uimaj-2.8.0/tools.html#ugr.tools.jcasgen.maven_plugin Note that the maven phases need to be correct, e.g., the second plugin needs to be executed after the first one.
        Hide
        pkluegl Peter Klügl added a comment -

        It's not related to the missing JCas class for that type. The type system used to create the CAS is the problem. If you use the classpath scanning functionality of uimaFIT, then you need to include the generated type system in the lookup (types.txt), or you follow the code snippet I mentioned that merges the type systems.

        btw, how did you create that engine descriptor? It's not valid, e.g., no Ruta component would create one without mainScript.

        Show
        pkluegl Peter Klügl added a comment - It's not related to the missing JCas class for that type. The type system used to create the CAS is the problem. If you use the classpath scanning functionality of uimaFIT, then you need to include the generated type system in the lookup (types.txt), or you follow the code snippet I mentioned that merges the type systems. btw, how did you create that engine descriptor? It's not valid, e.g., no Ruta component would create one without mainScript.
        Hide
        pkluegl Peter Klügl added a comment -

        Can we resolve this issue?

        Show
        pkluegl Peter Klügl added a comment - Can we resolve this issue?
        Hide
        pkluegl Peter Klügl added a comment -

        (probably) fixed / answered question

        Show
        pkluegl Peter Klügl added a comment - (probably) fixed / answered question

          People

          • Assignee:
            pkluegl Peter Klügl
            Reporter:
            jmlongriver Min Jiang
          • Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved:

              Development