You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@uima.apache.org by Kai Schlamp <sc...@gmx.de> on 2009/05/28 14:40:54 UTC
Associate document object with CAS
Hello.
I am using the UIMA (or better to say the CPE) to analyze some text within my application.
My application uses a class, let's name it my MyDocument, whose objects store the text to analyze
(MyDocument.text).
When the text of MyDocument object was analyzed, the result should be stored back to the MyDocument
object.
What would be the best way to find out from which MyDocument object the text comes from?
I could check if "cas.getDocumentText.equals(myDocument.getText())", but this is not a clean
solution as there could be multiple MyDocument objects with the same text.
Another thing that won't work is to assoiate the CAS with the MyDocument object in the collection
reader by doint myDocument.setCas(aCas). But a CAS is reused this will fail too.
So the only possible solution seems to be to associate the MyDocument object with the CAS like
(aCas.setSource(myDocument). But I am not sure if there is some way to do this.
Any suggestions?
Best regards,
Kai
Re: Associate document object with CAS
Posted by Burn Lewis <bu...@gmail.com>.
At runtime you can discover the available Types and their Features from the
TypeSystem in the CAS, but you cannot modify it. So just add the new Type
or Feature to your Type System descriptor. If you really need to create it
dynamically then you can use the TypeSystemDescription class to create or
modify a Type System, but I think it must be done before creating the
Analysis Engine (using the UIMAFramework class). The restriction arises
because for efficient access the Types and Features are converted to integer
codes when the CAS pool is created so any changes must be committed earlier.
Re: Associate document object with CAS
Posted by Jörn Kottmann <ko...@gmail.com>.
Kai Schlamp wrote:
> It seems I misunderstood something.
> The createFS method seems to use an already defined (in a type system
> descriptor) type.
> The thing I wanted to do is to create a new type programmatically
> (that is how I interpreted "specification of types" in the CAS
> reference documentation).
> But I guess that this is not possible.
I think that can be done with he TypeSystemDescription class, but never
did it.
BTW, if you think something in the documentation should be clarified
just open a jira
issue for it.
Jörn
Re: Associate document object with CAS
Posted by Kai Schlamp <sc...@gmx.de>.
It seems I misunderstood something.
The createFS method seems to use an already defined (in a type system descriptor) type.
The thing I wanted to do is to create a new type programmatically
(that is how I interpreted "specification of types" in the CAS reference documentation).
But I guess that this is not possible.
Jörn Kottmann wrote:
> Kai Schlamp wrote:
>> Jörn, thanks for your help.
>> I trying now to add a new feature structure to my CAS. In the CAS
>> Reference guide it says
>> that a "specification of types and features at run time" is possible.
>> But I can't figure out how to do it.
>> It seems cas.createFS(type) is the way to go, but I can't find any
>> example code.
>> Espcially how to create that type that is needed (how do I instantiate
>> a TOP_TYPE?).
>> Do you have a short example for me somewhere around?
> You should have a look at the CAS refeence documentation:
> http://incubator.apache.org/uima/downloads/releaseDocs/2.2.2-incubating/docs/html/references/references.html#ugr.ref.cas
>
>
> To your question, first you have to obtain the Type object describing
> your Feature Structure.
> I assume that you already have a reference to a CAS object, then you can
> call cas.getTypeSystem().getType("com.xxx.FeatureStructureName") to get it.
> The type object you pass into CAS.createFS and then you have to add the
> FS to the index with CAS.addFsToIndexes
>
> Jörn
>
>
Re: Associate document object with CAS
Posted by Jörn Kottmann <ko...@gmail.com>.
Kai Schlamp wrote:
> Jörn, thanks for your help.
> I trying now to add a new feature structure to my CAS. In the CAS
> Reference guide it says
> that a "specification of types and features at run time" is possible.
> But I can't figure out how to do it.
> It seems cas.createFS(type) is the way to go, but I can't find any
> example code.
> Espcially how to create that type that is needed (how do I instantiate
> a TOP_TYPE?).
> Do you have a short example for me somewhere around?
You should have a look at the CAS refeence documentation:
http://incubator.apache.org/uima/downloads/releaseDocs/2.2.2-incubating/docs/html/references/references.html#ugr.ref.cas
To your question, first you have to obtain the Type object describing
your Feature Structure.
I assume that you already have a reference to a CAS object, then you can
call cas.getTypeSystem().getType("com.xxx.FeatureStructureName") to get it.
The type object you pass into CAS.createFS and then you have to add the
FS to the index with CAS.addFsToIndexes
Jörn
Re: Associate document object with CAS
Posted by Kai Schlamp <sc...@gmx.de>.
Jörn, thanks for your help.
I trying now to add a new feature structure to my CAS. In the CAS Reference guide it says
that a "specification of types and features at run time" is possible.
But I can't figure out how to do it.
It seems cas.createFS(type) is the way to go, but I can't find any example code.
Espcially how to create that type that is needed (how do I instantiate a TOP_TYPE?).
Do you have a short example for me somewhere around?
Jörn Kottmann wrote:
> Kai Schlamp wrote:
>> So the only possible solution seems to be to associate the MyDocument
>> object with the CAS like (aCas.setSource(myDocument). But I am not
>> sure if there is some way to do this.
>> Any suggestions?
> You can define a Feature Structure type which has an id feature, with an
> id you can easily map a CAS object
> to on of your document objects using a map.
>
> Here are the necessary steps:
> - Put text and id Feature Structure into a CAS from your document object
> - Register id and your document object in an intermediate map
> - When CAS was processed lookup your document object based on the id
> from the CAS
> - Copy processing results into your document object
>
> Hope that helps,
> Jörn
>
Re: Associate document object with CAS
Posted by Jörn Kottmann <ko...@gmail.com>.
Kai Schlamp wrote:
> So the only possible solution seems to be to associate the MyDocument
> object with the CAS like (aCas.setSource(myDocument). But I am not
> sure if there is some way to do this.
> Any suggestions?
You can define a Feature Structure type which has an id feature, with an
id you can easily map a CAS object
to on of your document objects using a map.
Here are the necessary steps:
- Put text and id Feature Structure into a CAS from your document object
- Register id and your document object in an intermediate map
- When CAS was processed lookup your document object based on the id
from the CAS
- Copy processing results into your document object
Hope that helps,
Jörn