uima-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Peter Klügl <peter.klu...@averbis.com>
Subject Re: how to call UIMA Ruta from uimaFIT
Date Fri, 13 Nov 2015 13:01:44 GMT
Hi,

I assume that there are several problems, e.g., the missing JCas cover
classes.

I have taken the liberty to create a project based on your example like
I would use ruta right now (with 2.3.1):
http://people.apache.org/~pkluegl/examples/date-example.zip

- the script file are in src/main/ruta
- the wordlist file is in src/main/resources
- the descriptors are generated to target/generated-sources/ruta
- the JCas cover classes are generated to  target/generated-sources/jcasgen
- src/test/java contains two JUnit tests: one based on the generated
descriptor and one based on uimaFIT without ae descriptor

Let me know if this helps and/or you have questions about the project setup.

Best,

Peter

Am 12.11.2015 um 17:04 schrieb Olivier Austina:
> Hi Peter,
>
>
> Thank you for you reply. To answer to your questions:
>
>
> - who created DateTypeSystem.xml? Was it the ruta-maven-plugin or the
> build process of the Ruta Workbench? Did you move the type system
> descriptor, e.g., making the import in the AE descriptor invalid?
>
> DateTypeSystem.xml is created by the Ruta Workbench. I have created the
> project with Ruta Workbench and then try to use it in java program with
> maven. This is the DateTypeSystem.xml file content :
>
> <?xml version="1.0" encoding="UTF-8"?>
> <typeSystemDescription xmlns="http://uima.apache.org/resourceSpecifier">
>     <name>tutorial.entity.DateTypeSystem</name>
>     <imports>
>         <import location="../../BasicTypeSystem.xml"/>
>     </imports>
>     <types>
>         <typeDescription>
>             <name>tutorial.entity.Date.Month</name>
>             <description>Type defined in tutorial.entity.Date</description>
>             <supertypeName>uima.tcas.Annotation</supertypeName>
>         </typeDescription>
>         <typeDescription>
>             <name>tutorial.entity.Date.Year</name>
>             <description>Type defined in tutorial.entity.Date</description>
>             <supertypeName>uima.tcas.Annotation</supertypeName>
>         </typeDescription>
>         <typeDescription>
>             <name>tutorial.entity.Date.Date</name>
>             <description>Type defined in tutorial.entity.Date</description>
>             <supertypeName>uima.tcas.Annotation</supertypeName>
>         </typeDescription>
>     </types>
> </typeSystemDescription>
>
> - did you include the jcasgen-maven-plugin in your pom? Or did you use
> the Component Descriptor Editor to create JCas cover classes.
>
> No I didn't use it. I have only create a simple maven project with eclipse
> and try to call UIMA Ruta with uimaFIT.
>
> - the error messages indicate that the type system import of your
> analysis engine has some problems and that the Month type is not
> resolved. Furthermore,tThe Month class (JCas cover class for the type)
> is missing. Either there was already a class or JCasGen was not executed.
>
> Can you provide the complete pom and a short description of the layout
> of your project?
>
> This is the pom:
>
> <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="
> http://www.w3.org/2001/XMLSchema-instance"
>   xsi:schemaLocation="http://maven.apache.org/POM/4.0.0
> http://maven.apache.org/xsd/maven-4.0.0.xsd">
>   <modelVersion>4.0.0</modelVersion>
>
>   <groupId>tuto</groupId>
>   <artifactId>tuto-step0</artifactId>
>   <version>0.0.1-SNAPSHOT</version>
>   <packaging>jar</packaging>
>
>   <name>tuto-step0</name>
>   <url>http://maven.apache.org</url>
>
>   <properties>
>     <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
>   </properties>
>
>   <dependencies>
>     <dependency>
>        <groupId>org.apache.uima</groupId>
>        <artifactId>ruta-core</artifactId>
>        <version>2.3.1</version>
>     </dependency>
>
>     <dependency>
>       <groupId>org.apache.uima</groupId>
>       <artifactId>uimafit-core</artifactId>
>       <version>2.1.0</version>
>     </dependency>
>     <dependency>
>       <groupId>junit</groupId>
>       <artifactId>junit</artifactId>
>       <version>3.8.1</version>
>       <scope>test</scope>
>     </dependency>
>   </dependencies>
> </project>
>
> This is java code with imports:
>
> package tuto.tuto_step0;
>
> import java.io.File;
> import java.io.IOException;
>
> import org.apache.uima.UIMAFramework;
> import org.apache.uima.analysis_engine.AnalysisEngine;
> import org.apache.uima.analysis_engine.AnalysisEngineProcessException;
> import org.apache.uima.cas.CAS;
> import org.apache.uima.cas.CASException;
> import org.apache.uima.cas.text.AnnotationFS;
> import org.apache.uima.cas.text.AnnotationIndex;
> import org.apache.uima.fit.util.ContainmentIndex.Type;
> import org.apache.uima.fit.util.JCasUtil;
> import org.apache.uima.jcas.JCas;
> import org.apache.uima.resource.ResourceInitializationException;
> import org.apache.uima.resource.ResourceSpecifier;
> import org.apache.uima.util.InvalidXMLException;
> import org.apache.uima.util.XMLInputSource;
>
>
>
> public class App
> {
>     public static void main( String[] args ) throws IOException,
> InvalidXMLException, ResourceInitializationException,
> AnalysisEngineProcessException, CASException
>     {
>         //System.out.println( "Hello World!" );
>         File specFile = new
> File("/home/olhome/software/workspace/rutatest1/dateproject/descriptor/tutorial/entity/DateEngine.xml");
>             XMLInputSource in = new XMLInputSource(specFile);
>             ResourceSpecifier specifier = UIMAFramework.getXMLParser().
>                 parseResourceSpecifier(in);
>             // for import by name... set the datapath in the ResourceManager
>             AnalysisEngine ae =
> UIMAFramework.produceAnalysisEngine(specifier);
>             CAS cas = ae.newCAS();
>             cas.setDocumentText("This is my document. March  June
> December");
>             ae.process(cas);
>             // For plain UIMA
>             /*
>             org.apache.uima.cas.Type monthType =
> cas.getTypeSystem().getType("tutorial.entity.Date.Month");
>             AnnotationIndex<AnnotationFS> annotationIndex =
>             cas.getAnnotationIndex(monthType);
>             for (AnnotationFS each : annotationIndex) {
>               System.out.println(each.getCoveredText());
>             }
>             */
>
>             JCas jcas = cas.getJCas();
>             for (Month month : JCasUtil.select(jcas, Month.class)) {
>                    System.out.println(month.getCoveredText());
>                 }
>
>
>     }
> }
>
> Thank you.
>
> Regards
> Olivier
>
>
> 2015-11-12 14:35 GMT+01:00 Peter Klügl <peter.kluegl@averbis.com>:
>
>> Hi,
>>
>> here a few fast comments and questions:
>> - the example code uses uimaFIT only for the select, but not for the
>> creation/initialization of the components/CAS. Thus,
>> org.apache.uima.fit/types.txt won't help much. However, the types should
>> be included by the import in the AE.
>> - who created DateTypeSystem.xml? Was it the ruta-maven-plugin or the
>> build process of the Ruta Workbench? Did you move the type system
>> descriptor, e.g., making the import in the AE descriptor invalid?
>> - did you include the jcasgen-maven-plugin in your pom? Or did you use
>> the Component Descriptor Editor to create JCas cover classes.
>> - the error messages indicate that the type system import of your
>> analysis engine has some problems and that the Month type is not
>> resolved. Furthermore,tThe Month class (JCas cover class for the type)
>> is missing. Either there was already a class or JCasGen was not executed.
>>
>> Can you provide the complete pom and a short description of the layout
>> of your project?
>>
>> Best,
>>
>> Peter
>>
>> PS: a uimaFIT like approach for creating a Ruta engine could look like
>> (whereas direct initialization of AE should be avoided in general):
>> AnalysisEngine ae = createEngine(RutaEngine.class,
>>             RutaEngine.PARAM_MAIN_SCRIPT,
>> "org.apache.uima.ruta.engine.UimafitTest",
>>             RutaEngine.PARAM_SCRIPT_PATHS, new String[] {
>> "src/test/resources" });
>>
>>
>> Am 12.11.2015 um 14:12 schrieb Olivier Austina:
>>> Hi,
>>>
>>> I try to call a simple UIMA ruta script from uimaFIT in java. It works in
>>> plain UIMA but it didn't work in uimaFIT for me.  Here is the script:
>>>
>>> PACKAGE tutorial.entity;
>>> WORDLIST MonthsList = 'month.txt';
>>> DECLARE Month;
>>> DECLARE Year;
>>> DECLARE Date;
>>> Document{-> MARKFAST(Month, MonthsList )};
>>> NUM{REGEXP("19..|20..") -> MARK(Year,1,2)};
>>> Month Year {-> MARK(Date,1,2)};
>>>
>>> Here is the java code (based on Ruta doc example):
>>>
>>> //System.out.println( "Hello World!" );
>>>         File specFile = new
>>>
>> File("/home/olhome/software/workspace/rutatest1/dateproject/descriptor/tutorial/entity/DateEngine.xml");
>>>             XMLInputSource in = new XMLInputSource(specFile);
>>>             ResourceSpecifier specifier = UIMAFramework.getXMLParser().
>>>                 parseResourceSpecifier(in);
>>>             // for import by name... set the datapath in the
>> ResourceManager
>>>             AnalysisEngine ae =
>>> UIMAFramework.produceAnalysisEngine(specifier);
>>>             CAS cas = ae.newCAS();
>>>             cas.setDocumentText("This is my document. March  June
>>> December");
>>>             ae.process(cas);
>>>
>>>             JCas jcas = cas.getJCas();
>>>             for (Month month : JCasUtil.select(jcas, Month.class)) {
>>>                    System.out.println(month.getCoveredText());
>>>                 }
>>>
>>>   This is the pom dependencies:
>>>
>>>     <dependency>
>>>        <groupId>org.apache.uima</groupId>
>>>        <artifactId>ruta-core</artifactId>
>>>        <version>2.3.1</version>
>>>     </dependency>
>>>
>>>     <dependency>
>>>       <groupId>org.apache.uima</groupId>
>>>       <artifactId>uimafit-core</artifactId>
>>>       <version>2.1.0</version>
>>>     </dependency>
>>>
>>>
>>> I have the following error:
>>>
>>> Exception in thread "main" java.lang.Error: Unresolved compilation
>>> problems:
>>>     Month cannot be resolved to a type
>>>     Bound mismatch: The generic method select(FSArray, Class<T>) of type
>>> JCasUtil is not applicable for the arguments (JCas, Class<Month>). The
>>> inferred type Month is not a valid substitute for the bounded parameter
>> <T
>>> extends TOP>
>>>     Month cannot be resolved to a type
>>>     at tuto.tuto_step0.App.main(App.java:51)
>>>
>>>
>>> It seems that I am not able to correctly import types like in the maven
>>> example. I am not so familiar with maven. I have put the
>> DateTypeSystem.xml
>>> in a folder called tuto under src folder and add the line
>>> "classpath*:/tuto/DateTypeSystem.xml" in the text file
>>> src/META-INF/org.apache.uima.fit/types.txt.
>>>
>>> Any suggestion is welcome. Thank you.
>>>
>>> Regards
>>> Olivier
>>>
>>


Mime
View raw message