You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@uima.apache.org by Tiziano Lorenzetti <ti...@gmail.com> on 2014/05/13 15:55:26 UTC

dinamically type system creation

Dear all,
I'm new to UIMA and I'm trying to develope an annotator that creates
dinamically a type system with serveral feature structure.
To accomplish this, the annotator does:

...
TypeSystemDescription tsd =
TypeSystemDescriptionFactory.createTypeSystemDescription(new String[0]);
tsd.addType("it.uniroma2.art.ExcelAnnotation", "", "uima.tcas.Annotation");
TypeDescription type = tsd.getType("it.uniroma2.art.ExcelAnnotation");
type.addFeature("newUIMAFeature", "", "uima.cas.String");
...

In another annotator, I try to access this type system and its features in
this way:

TypeSystem ts = aCAS.getTypeSystem();
Iterator<Type> types = ts.getTypeIterator();
Iterator<Feature> features = ts.getFeatures();

but neither the type system and its features are present. How could I reach
my goal?

Thank you all.

Tiziano Lorenzetti

Re: dinamically type system creation

Posted by Richard Eckart de Castilho <re...@apache.org>.
You can use CasCreationUtil.mergeTypeSystems(...) to merge multiple TSDs
into one and then pass it to the JCasFactory (or to CasCreationUtil.createCas(...))

Cheers,

-- Richard

On 13.05.2014, at 18:15, Tiziano Lorenzetti <ti...@gmail.com> wrote:

> You got the point. I didn't tell UIMA to use my type system. In fact,
> previously, I created the CAS as follow:
> 
> JCas jcas = JCasFactory.createJCas();
> 
> and then I executed the engine with a simple pipeline.
> 
> SimplePipeline.runPipeline(jcas, ae);
> 
> Now I've found a solution: I create the TypeSystemDescription in a manager
> class, and I tell UIMA to use it
> 
> JCas jcas = JCasFactory.createJCas(tsd);
> 
> It works. The only thing remaining is to tell UIMA to use all the type
> systems, not only the one I specified...but I'll figure it out.
> 
> Thank you.
> 
> 
> 2014-05-13 17:46 GMT+02:00 Richard Eckart de Castilho <re...@apache.org>:
> 
>> How do you create the CAS and/or your reader/analysis engines/pipelines?
>> Or more specifically: how do you tell UIMA to actually use your type
>> system?
>> 
>> Cheers,
>> 
>> -- Richard
>> 
>> On 13.05.2014, at 15:55, Tiziano Lorenzetti <ti...@gmail.com>
>> wrote:
>> 
>>> Dear all,
>>> I'm new to UIMA and I'm trying to develope an annotator that creates
>>> dinamically a type system with serveral feature structure.
>>> To accomplish this, the annotator does:
>>> 
>>> ...
>>> TypeSystemDescription tsd =
>>> TypeSystemDescriptionFactory.createTypeSystemDescription(new String[0]);
>>> tsd.addType("it.uniroma2.art.ExcelAnnotation", "",
>> "uima.tcas.Annotation");
>>> TypeDescription type = tsd.getType("it.uniroma2.art.ExcelAnnotation");
>>> type.addFeature("newUIMAFeature", "", "uima.cas.String");
>>> ...
>>> 
>>> In another annotator, I try to access this type system and its features
>> in
>>> this way:
>>> 
>>> TypeSystem ts = aCAS.getTypeSystem();
>>> Iterator<Type> types = ts.getTypeIterator();
>>> Iterator<Feature> features = ts.getFeatures();
>>> 
>>> but neither the type system and its features are present. How could I
>> reach
>>> my goal?
>>> 
>>> Thank you all.
>>> 
>>> Tiziano Lorenzetti
>> 
>> 


Re: dinamically type system creation

Posted by Tiziano Lorenzetti <ti...@gmail.com>.
You got the point. I didn't tell UIMA to use my type system. In fact,
previously, I created the CAS as follow:

JCas jcas = JCasFactory.createJCas();

and then I executed the engine with a simple pipeline.

SimplePipeline.runPipeline(jcas, ae);

Now I've found a solution: I create the TypeSystemDescription in a manager
class, and I tell UIMA to use it

JCas jcas = JCasFactory.createJCas(tsd);

It works. The only thing remaining is to tell UIMA to use all the type
systems, not only the one I specified...but I'll figure it out.

Thank you.


2014-05-13 17:46 GMT+02:00 Richard Eckart de Castilho <re...@apache.org>:

> How do you create the CAS and/or your reader/analysis engines/pipelines?
> Or more specifically: how do you tell UIMA to actually use your type
> system?
>
> Cheers,
>
> -- Richard
>
> On 13.05.2014, at 15:55, Tiziano Lorenzetti <ti...@gmail.com>
> wrote:
>
> > Dear all,
> > I'm new to UIMA and I'm trying to develope an annotator that creates
> > dinamically a type system with serveral feature structure.
> > To accomplish this, the annotator does:
> >
> > ...
> > TypeSystemDescription tsd =
> > TypeSystemDescriptionFactory.createTypeSystemDescription(new String[0]);
> > tsd.addType("it.uniroma2.art.ExcelAnnotation", "",
> "uima.tcas.Annotation");
> > TypeDescription type = tsd.getType("it.uniroma2.art.ExcelAnnotation");
> > type.addFeature("newUIMAFeature", "", "uima.cas.String");
> > ...
> >
> > In another annotator, I try to access this type system and its features
> in
> > this way:
> >
> > TypeSystem ts = aCAS.getTypeSystem();
> > Iterator<Type> types = ts.getTypeIterator();
> > Iterator<Feature> features = ts.getFeatures();
> >
> > but neither the type system and its features are present. How could I
> reach
> > my goal?
> >
> > Thank you all.
> >
> > Tiziano Lorenzetti
>
>

Re: dinamically type system creation

Posted by Richard Eckart de Castilho <re...@apache.org>.
How do you create the CAS and/or your reader/analysis engines/pipelines?
Or more specifically: how do you tell UIMA to actually use your type system?

Cheers,

-- Richard

On 13.05.2014, at 15:55, Tiziano Lorenzetti <ti...@gmail.com> wrote:

> Dear all,
> I'm new to UIMA and I'm trying to develope an annotator that creates
> dinamically a type system with serveral feature structure.
> To accomplish this, the annotator does:
> 
> ...
> TypeSystemDescription tsd =
> TypeSystemDescriptionFactory.createTypeSystemDescription(new String[0]);
> tsd.addType("it.uniroma2.art.ExcelAnnotation", "", "uima.tcas.Annotation");
> TypeDescription type = tsd.getType("it.uniroma2.art.ExcelAnnotation");
> type.addFeature("newUIMAFeature", "", "uima.cas.String");
> ...
> 
> In another annotator, I try to access this type system and its features in
> this way:
> 
> TypeSystem ts = aCAS.getTypeSystem();
> Iterator<Type> types = ts.getTypeIterator();
> Iterator<Feature> features = ts.getFeatures();
> 
> but neither the type system and its features are present. How could I reach
> my goal?
> 
> Thank you all.
> 
> Tiziano Lorenzetti


Re: dinamically type system creation

Posted by Richard Eckart de Castilho <re...@apache.org>.
If you use JCasFactory.createJCas() or CasCreationUtils.createCas()
I'd recommend to load a type system description from XML and pass
it to those calls. The method you describe here should imho only be
used if you need to reconfigure the type system of the CAS from
within a CollectionReader - e.g. when loading a serialized CAS
from disk.

Btw. since UIMA 2.5.0, there are more efficient binary formats than
the Java-serialized CAS. Some inspiration of how to store/load
CASes to/from disk in the binary formats could be picked up from the
BinaryCasReader/Writer [1,2] and SerializedCasReader/Writer [3,4]
components of DKPro Core.

Cheers,

-- Richard

[1] https://code.google.com/p/dkpro-core-asl/source/browse/de.tudarmstadt.ukp.dkpro.core-asl/trunk/de.tudarmstadt.ukp.dkpro.core.io.bincas-asl/src/main/java/de/tudarmstadt/ukp/dkpro/core/io/bincas/BinaryCasReader.java
[2] https://code.google.com/p/dkpro-core-asl/source/browse/de.tudarmstadt.ukp.dkpro.core-asl/trunk/de.tudarmstadt.ukp.dkpro.core.io.bincas-asl/src/main/java/de/tudarmstadt/ukp/dkpro/core/io/bincas/BinaryCasWriter.java
[3] https://code.google.com/p/dkpro-core-asl/source/browse/de.tudarmstadt.ukp.dkpro.core-asl/trunk/de.tudarmstadt.ukp.dkpro.core.io.bincas-asl/src/main/java/de/tudarmstadt/ukp/dkpro/core/io/bincas/SerializedCasReader.java
[4] https://code.google.com/p/dkpro-core-asl/source/browse/de.tudarmstadt.ukp.dkpro.core-asl/trunk/de.tudarmstadt.ukp.dkpro.core.io.bincas-asl/src/main/java/de/tudarmstadt/ukp/dkpro/core/io/bincas/SerializedCasWriter.java

On 13.05.2014, at 18:39, Brian Dolan <bu...@yahoo.com> wrote:

> We struggled with this as well.  The key is to provide the TypeSystem
> along with the CAS, especially when serializing.
> 
> Here we are writing it out:
> 
> // Serialziation with type system
>            CASMgr casMgr = jCas.getCasImpl();
>            CASCompleteSerializer casCompleteSerializer =
> Serialization.serializeCASComplete(casMgr);
> 
>            outputObjectStream.writeObject(casCompleteSerializer);
> 
> 
> 
> Here we are reading it in:
> 
>            // deSerialization with type system
>            Object inputObj = inputObjectStream.readObject();
>            CASCompleteSerializer casCompleteSerializer = null;
>            if (inputObj instanceof CASCompleteSerializer) {
>                casCompleteSerializer = (CASCompleteSerializer) inputObj;
>            } else {
>                throw new IOException("Deserialized Object is not an
> instance of CASCompleteSerializer");
>            }
> 
>            JCas jCas = JCasFactory.createJCas();
>            CASMgr casMgr = jCas.getCasImpl();
>            Serialization.deserializeCASComplete(casCompleteSerializer,
> casMgr);
> 
> 
> Hope this helps!
> b
> 
> 
> 
> 
> On 5/13/14 8:23 AM, "Alexandre Patry" <al...@keatext.com> wrote:
> 
>> Hi Tiziano,
>> 
>> On 13/05/2014 09:55, Tiziano Lorenzetti wrote:
>>> Dear all,
>>> I'm new to UIMA and I'm trying to develope an annotator that creates
>>> dinamically a type system with serveral feature structure.
>>> To accomplish this, the annotator does:
>>> 
>>> ...
>>> TypeSystemDescription tsd =
>>> TypeSystemDescriptionFactory.createTypeSystemDescription(new String[0]);
>>> tsd.addType("it.uniroma2.art.ExcelAnnotation", "",
>>> "uima.tcas.Annotation");
>>> TypeDescription type = tsd.getType("it.uniroma2.art.ExcelAnnotation");
>>> type.addFeature("newUIMAFeature", "", "uima.cas.String");
>>> ...
>>> 
>>> In another annotator, I try to access this type system and its features
>>> in
>>> this way:
>>> 
>>> TypeSystem ts = aCAS.getTypeSystem();
>>> Iterator<Type> types = ts.getTypeIterator();
>>> Iterator<Feature> features = ts.getFeatures();
>>> 
>>> but neither the type system and its features are present. How could I
>>> reach
>>> my goal?
>> How do you create your CAS? I guess the types should be found if you
>> create it using:
>> 
>> CAS aCAS = CasCreationUtils.createCas(typeSystemDescription, null, null);
>> 
>> Hope this help,
>> 
>> Alexandre
>> 
>> -- 
>> Alexandre Patry, Ph.D
>> Chercheur / Researcher
>> http://KeaText.com


Re: dinamically type system creation

Posted by Brian Dolan <bu...@yahoo.com>.
We struggled with this as well.  The key is to provide the TypeSystem
along with the CAS, especially when serializing.

Here we are writing it out:

 // Serialziation with type system
            CASMgr casMgr = jCas.getCasImpl();
            CASCompleteSerializer casCompleteSerializer =
Serialization.serializeCASComplete(casMgr);

            outputObjectStream.writeObject(casCompleteSerializer);



Here we are reading it in:

            // deSerialization with type system
            Object inputObj = inputObjectStream.readObject();
            CASCompleteSerializer casCompleteSerializer = null;
            if (inputObj instanceof CASCompleteSerializer) {
                casCompleteSerializer = (CASCompleteSerializer) inputObj;
            } else {
                throw new IOException("Deserialized Object is not an
instance of CASCompleteSerializer");
            }

            JCas jCas = JCasFactory.createJCas();
            CASMgr casMgr = jCas.getCasImpl();
            Serialization.deserializeCASComplete(casCompleteSerializer,
casMgr);


Hope this helps!
b




On 5/13/14 8:23 AM, "Alexandre Patry" <al...@keatext.com> wrote:

>Hi Tiziano,
>
>On 13/05/2014 09:55, Tiziano Lorenzetti wrote:
>> Dear all,
>> I'm new to UIMA and I'm trying to develope an annotator that creates
>> dinamically a type system with serveral feature structure.
>> To accomplish this, the annotator does:
>>
>> ...
>> TypeSystemDescription tsd =
>> TypeSystemDescriptionFactory.createTypeSystemDescription(new String[0]);
>> tsd.addType("it.uniroma2.art.ExcelAnnotation", "",
>>"uima.tcas.Annotation");
>> TypeDescription type = tsd.getType("it.uniroma2.art.ExcelAnnotation");
>> type.addFeature("newUIMAFeature", "", "uima.cas.String");
>> ...
>>
>> In another annotator, I try to access this type system and its features
>>in
>> this way:
>>
>> TypeSystem ts = aCAS.getTypeSystem();
>> Iterator<Type> types = ts.getTypeIterator();
>> Iterator<Feature> features = ts.getFeatures();
>>
>> but neither the type system and its features are present. How could I
>>reach
>> my goal?
>How do you create your CAS? I guess the types should be found if you
>create it using:
>
>CAS aCAS = CasCreationUtils.createCas(typeSystemDescription, null, null);
>
>Hope this help,
>
>Alexandre
>
>-- 
>Alexandre Patry, Ph.D
>Chercheur / Researcher
>http://KeaText.com
>



Re: dinamically type system creation

Posted by Alexandre Patry <al...@keatext.com>.
Hi Tiziano,

On 13/05/2014 09:55, Tiziano Lorenzetti wrote:
> Dear all,
> I'm new to UIMA and I'm trying to develope an annotator that creates
> dinamically a type system with serveral feature structure.
> To accomplish this, the annotator does:
>
> ...
> TypeSystemDescription tsd =
> TypeSystemDescriptionFactory.createTypeSystemDescription(new String[0]);
> tsd.addType("it.uniroma2.art.ExcelAnnotation", "", "uima.tcas.Annotation");
> TypeDescription type = tsd.getType("it.uniroma2.art.ExcelAnnotation");
> type.addFeature("newUIMAFeature", "", "uima.cas.String");
> ...
>
> In another annotator, I try to access this type system and its features in
> this way:
>
> TypeSystem ts = aCAS.getTypeSystem();
> Iterator<Type> types = ts.getTypeIterator();
> Iterator<Feature> features = ts.getFeatures();
>
> but neither the type system and its features are present. How could I reach
> my goal?
How do you create your CAS? I guess the types should be found if you 
create it using:

CAS aCAS = CasCreationUtils.createCas(typeSystemDescription, null, null);

Hope this help,

Alexandre

-- 
Alexandre Patry, Ph.D
Chercheur / Researcher
http://KeaText.com