You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@uima.apache.org by Alexander Klenner <al...@scai.fraunhofer.de> on 2011/08/23 15:54:16 UTC

iterate over annotations

Greetings,

I am still working on my image processing. As suggested I stored the image by using .setSofaDataArray and a ByteArrayFS. I also have an ImageArea Type with Features for x,y,width and height describing an actual image area (similar to the .getSubimage(x,y,width,height) method from java awt). ImageArea extends AnnotationBase instead of Annotation to get rid of all the text-specific stuff, which doesn't make much sense in this case. I also have the equivalent for getCoveredText implemented, returning the annotated ImageArea as a bufferedImage. 

Serialising and Deserialising works fine, the XCAS file gets quite large in comparison to the original image file but that is expected. All the found ImageAreas are annotated inside the XCAS with their Features set correctly. That looks like this inside the XCAS.xml file: 

[...]<de.types.ImageArea _indexed="1" _id="11" _ref_sofa="4" x="16" y="153" width="10" heigth="10"/><de.types.ImageArea _indexed="1" _id="17" _ref_sofa="4" x="16" y="164" width="10" heigth="10"/>[...]

Now here is my problem: I wanted to save the actual ImageAreas as images using a different consumer. I just cannot find the annotations in my CAS object. But the annotations are there, otherwise they would not appear inside the XCAS.xml file, right? Here is what I tried:
...............
Iterator iter = myJCas.getAnnotationIndex().iterator();
		  
while (iter.hasNext()) {
//do something
}
...............
But iter is always empty, hence the while condition is never met.  

Isn't this the supposed approach to iterate over the annotations that were made before? I don't get any error messages, I just cannot find my annotations. 

Probably the solution is very easy but I just don't see it, again thanks for any help, it's really appreciated, I have no one else to talk to about UIMA but you guys on the mailing list.

Thank you!

Alex

--
Dipl. Bioinformatiker Alexander G. Klenner
Fraunhofer-Institute for Algorithms and Scientific Computing (SCAI)
Schloss Birlinghoven, D-53754 Sankt Augustin
Tel.: +49 - 2241 - 14 - 2736
E-mail: alexander.garvin.klenner@scai.fraunhofer.de
Internet: http://www.scai.fraunhofer.de



Re: iterate over annotations

Posted by Thilo Götz <tw...@gmx.de>.
On 23/08/11 16:13, Richard Eckart de Castilho wrote:
> Hello Alex,
> 
> you'll probably have to use cas.getIndexRepository().getAllIndexedFS(type) to get to your custom annotations. You can also define a custom index and then use cas.getIndexRepository().getIndex(label).

What Richard says.  The reason is that your custom type
is not an annotation in the CAS sense, because it doesn't
inherit from uima.AnnotationFS (or whatever it's called
again exactly, I forget).  So your feature structures are
not in the annotation index.

--Thilo

> 
> Cheers,
> 
> Richard
> 
> Am 23.08.2011 um 15:54 schrieb Alexander Klenner:
> 
>> Greetings,
>>
>> I am still working on my image processing. As suggested I stored the image by using .setSofaDataArray and a ByteArrayFS. I also have an ImageArea Type with Features for x,y,width and height describing an actual image area (similar to the .getSubimage(x,y,width,height) method from java awt). ImageArea extends AnnotationBase instead of Annotation to get rid of all the text-specific stuff, which doesn't make much sense in this case. I also have the equivalent for getCoveredText implemented, returning the annotated ImageArea as a bufferedImage. 
>>
>> Serialising and Deserialising works fine, the XCAS file gets quite large in comparison to the original image file but that is expected. All the found ImageAreas are annotated inside the XCAS with their Features set correctly. That looks like this inside the XCAS.xml file: 
>>
>> [...]<de.types.ImageArea _indexed="1" _id="11" _ref_sofa="4" x="16" y="153" width="10" heigth="10"/><de.types.ImageArea _indexed="1" _id="17" _ref_sofa="4" x="16" y="164" width="10" heigth="10"/>[...]
>>
>> Now here is my problem: I wanted to save the actual ImageAreas as images using a different consumer. I just cannot find the annotations in my CAS object. But the annotations are there, otherwise they would not appear inside the XCAS.xml file, right? Here is what I tried:
>> ...............
>> Iterator iter = myJCas.getAnnotationIndex().iterator();
>> 		  
>> while (iter.hasNext()) {
>> //do something
>> }
>> ...............
>> But iter is always empty, hence the while condition is never met.  
>>
>> Isn't this the supposed approach to iterate over the annotations that were made before? I don't get any error messages, I just cannot find my annotations. 
>>
>> Probably the solution is very easy but I just don't see it, again thanks for any help, it's really appreciated, I have no one else to talk to about UIMA but you guys on the mailing list.
>>
>> Thank you!
>>
>> Alex
> 

Re: iterate over annotations

Posted by Alexander Klenner <al...@scai.fraunhofer.de>.
As always, seconds after sending the email I finally found my Type inside the CAS object:

myJCas.getRequiredType("de.fhg.scai.bio.uima.types.ImageArea");

(I was only looking up "ImageArea", that didn't work, but printing the TypeSystem finally revealed what I needed )

Now it does work, with your suggested method.

Thanks,

Alex

--
Dipl. Bioinformatiker Alexander G. Klenner
Fraunhofer-Institute for Algorithms and Scientific Computing (SCAI)
Schloss Birlinghoven, D-53754 Sankt Augustin
Tel.: +49 - 2241 - 14 - 2736
E-mail: alexander.garvin.klenner@scai.fraunhofer.de
Internet: http://www.scai.fraunhofer.de


----- Original Message -----
From: "Alexander Klenner" <al...@scai.fraunhofer.de>
To: user@uima.apache.org
Sent: Wednesday, August 24, 2011 11:22:01 AM
Subject: Re: iterate over annotations

Hi Richard,

I found something similar in one of your posts in the mailing list archive before:

[...]Digging into the API again, I believe the fix should be this:

		MetaData metaData = (MetaData) jcas.getIndexRepository().getAllIndexedFS(MetaData.type).next()
[...]

If I get this right, in my example, ImageArea corresponds to MetaData? But ImageArea.type returns an Integer, where .getAllIndexedFS(Type arg0) needs a Type parameter. Now I am stuck with a similar problem, I cannot find anything in my CAS object that allows me to reference my ImageArea as a type. I'll try to figure out how to define a custom index as a next step.

Best regards,

Alex






--
Dipl. Bioinformatiker Alexander G. Klenner
Fraunhofer-Institute for Algorithms and Scientific Computing (SCAI)
Schloss Birlinghoven, D-53754 Sankt Augustin
Tel.: +49 - 2241 - 14 - 2736
E-mail: alexander.garvin.klenner@scai.fraunhofer.de
Internet: http://www.scai.fraunhofer.de


----- Original Message -----
From: "Richard Eckart de Castilho" <ec...@tk.informatik.tu-darmstadt.de>
To: user@uima.apache.org
Sent: Tuesday, August 23, 2011 4:13:34 PM
Subject: Re: iterate over annotations

Hello Alex,

you'll probably have to use cas.getIndexRepository().getAllIndexedFS(type) to get to your custom annotations. You can also define a custom index and then use cas.getIndexRepository().getIndex(label).

Cheers,

Richard

Am 23.08.2011 um 15:54 schrieb Alexander Klenner:

> Greetings,
>
> I am still working on my image processing. As suggested I stored the image by using .setSofaDataArray and a ByteArrayFS. I also have an ImageArea Type with Features for x,y,width and height describing an actual image area (similar to the .getSubimage(x,y,width,height) method from java awt). ImageArea extends AnnotationBase instead of Annotation to get rid of all the text-specific stuff, which doesn't make much sense in this case. I also have the equivalent for getCoveredText implemented, returning the annotated ImageArea as a bufferedImage.
>
> Serialising and Deserialising works fine, the XCAS file gets quite large in comparison to the original image file but that is expected. All the found ImageAreas are annotated inside the XCAS with their Features set correctly. That looks like this inside the XCAS.xml file:
>
> [...]<de.types.ImageArea _indexed="1" _id="11" _ref_sofa="4" x="16" y="153" width="10" heigth="10"/><de.types.ImageArea _indexed="1" _id="17" _ref_sofa="4" x="16" y="164" width="10" heigth="10"/>[...]
>
> Now here is my problem: I wanted to save the actual ImageAreas as images using a different consumer. I just cannot find the annotations in my CAS object. But the annotations are there, otherwise they would not appear inside the XCAS.xml file, right? Here is what I tried:
> ...............
> Iterator iter = myJCas.getAnnotationIndex().iterator();
>
> while (iter.hasNext()) {
> //do something
> }
> ...............
> But iter is always empty, hence the while condition is never met.
>
> Isn't this the supposed approach to iterate over the annotations that were made before? I don't get any error messages, I just cannot find my annotations.
>
> Probably the solution is very easy but I just don't see it, again thanks for any help, it's really appreciated, I have no one else to talk to about UIMA but you guys on the mailing list.
>
> Thank you!
>
> Alex

--
-------------------------------------------------------------------
Richard Eckart de Castilho
Technical Lead
Ubiquitous Knowledge Processing Lab
FB 20 Computer Science Department
Technische Universität Darmstadt
Hochschulstr. 10, D-64289 Darmstadt, Germany
phone [+49] (0)6151 16-7477, fax -5455, room S2/02/B117
eckartde@tk.informatik.tu-darmstadt.de
www.ukp.tu-darmstadt.de
Web Research at TU Darmstadt (WeRC) www.werc.tu-darmstadt.de
-------------------------------------------------------------------





Re: iterate over annotations

Posted by Alexander Klenner <al...@scai.fraunhofer.de>.
Hi Richard,

I found something similar in one of your posts in the mailing list archive before: 

[...]Digging into the API again, I believe the fix should be this:

		MetaData metaData = (MetaData) jcas.getIndexRepository().getAllIndexedFS(MetaData.type).next()
[...]

If I get this right, in my example, ImageArea corresponds to MetaData? But ImageArea.type returns an Integer, where .getAllIndexedFS(Type arg0) needs a Type parameter. Now I am stuck with a similar problem, I cannot find anything in my CAS object that allows me to reference my ImageArea as a type. I'll try to figure out how to define a custom index as a next step.

Best regards,

Alex






--
Dipl. Bioinformatiker Alexander G. Klenner
Fraunhofer-Institute for Algorithms and Scientific Computing (SCAI)
Schloss Birlinghoven, D-53754 Sankt Augustin
Tel.: +49 - 2241 - 14 - 2736
E-mail: alexander.garvin.klenner@scai.fraunhofer.de
Internet: http://www.scai.fraunhofer.de


----- Original Message -----
From: "Richard Eckart de Castilho" <ec...@tk.informatik.tu-darmstadt.de>
To: user@uima.apache.org
Sent: Tuesday, August 23, 2011 4:13:34 PM
Subject: Re: iterate over annotations

Hello Alex,

you'll probably have to use cas.getIndexRepository().getAllIndexedFS(type) to get to your custom annotations. You can also define a custom index and then use cas.getIndexRepository().getIndex(label).

Cheers,

Richard

Am 23.08.2011 um 15:54 schrieb Alexander Klenner:

> Greetings,
> 
> I am still working on my image processing. As suggested I stored the image by using .setSofaDataArray and a ByteArrayFS. I also have an ImageArea Type with Features for x,y,width and height describing an actual image area (similar to the .getSubimage(x,y,width,height) method from java awt). ImageArea extends AnnotationBase instead of Annotation to get rid of all the text-specific stuff, which doesn't make much sense in this case. I also have the equivalent for getCoveredText implemented, returning the annotated ImageArea as a bufferedImage. 
> 
> Serialising and Deserialising works fine, the XCAS file gets quite large in comparison to the original image file but that is expected. All the found ImageAreas are annotated inside the XCAS with their Features set correctly. That looks like this inside the XCAS.xml file: 
> 
> [...]<de.types.ImageArea _indexed="1" _id="11" _ref_sofa="4" x="16" y="153" width="10" heigth="10"/><de.types.ImageArea _indexed="1" _id="17" _ref_sofa="4" x="16" y="164" width="10" heigth="10"/>[...]
> 
> Now here is my problem: I wanted to save the actual ImageAreas as images using a different consumer. I just cannot find the annotations in my CAS object. But the annotations are there, otherwise they would not appear inside the XCAS.xml file, right? Here is what I tried:
> ...............
> Iterator iter = myJCas.getAnnotationIndex().iterator();
> 		  
> while (iter.hasNext()) {
> //do something
> }
> ...............
> But iter is always empty, hence the while condition is never met.  
> 
> Isn't this the supposed approach to iterate over the annotations that were made before? I don't get any error messages, I just cannot find my annotations. 
> 
> Probably the solution is very easy but I just don't see it, again thanks for any help, it's really appreciated, I have no one else to talk to about UIMA but you guys on the mailing list.
> 
> Thank you!
> 
> Alex

-- 
------------------------------------------------------------------- 
Richard Eckart de Castilho
Technical Lead
Ubiquitous Knowledge Processing Lab 
FB 20 Computer Science Department      
Technische Universität Darmstadt 
Hochschulstr. 10, D-64289 Darmstadt, Germany 
phone [+49] (0)6151 16-7477, fax -5455, room S2/02/B117
eckartde@tk.informatik.tu-darmstadt.de 
www.ukp.tu-darmstadt.de 
Web Research at TU Darmstadt (WeRC) www.werc.tu-darmstadt.de
------------------------------------------------------------------- 





Re: iterate over annotations

Posted by Richard Eckart de Castilho <ec...@tk.informatik.tu-darmstadt.de>.
Hello Alex,

you'll probably have to use cas.getIndexRepository().getAllIndexedFS(type) to get to your custom annotations. You can also define a custom index and then use cas.getIndexRepository().getIndex(label).

Cheers,

Richard

Am 23.08.2011 um 15:54 schrieb Alexander Klenner:

> Greetings,
> 
> I am still working on my image processing. As suggested I stored the image by using .setSofaDataArray and a ByteArrayFS. I also have an ImageArea Type with Features for x,y,width and height describing an actual image area (similar to the .getSubimage(x,y,width,height) method from java awt). ImageArea extends AnnotationBase instead of Annotation to get rid of all the text-specific stuff, which doesn't make much sense in this case. I also have the equivalent for getCoveredText implemented, returning the annotated ImageArea as a bufferedImage. 
> 
> Serialising and Deserialising works fine, the XCAS file gets quite large in comparison to the original image file but that is expected. All the found ImageAreas are annotated inside the XCAS with their Features set correctly. That looks like this inside the XCAS.xml file: 
> 
> [...]<de.types.ImageArea _indexed="1" _id="11" _ref_sofa="4" x="16" y="153" width="10" heigth="10"/><de.types.ImageArea _indexed="1" _id="17" _ref_sofa="4" x="16" y="164" width="10" heigth="10"/>[...]
> 
> Now here is my problem: I wanted to save the actual ImageAreas as images using a different consumer. I just cannot find the annotations in my CAS object. But the annotations are there, otherwise they would not appear inside the XCAS.xml file, right? Here is what I tried:
> ...............
> Iterator iter = myJCas.getAnnotationIndex().iterator();
> 		  
> while (iter.hasNext()) {
> //do something
> }
> ...............
> But iter is always empty, hence the while condition is never met.  
> 
> Isn't this the supposed approach to iterate over the annotations that were made before? I don't get any error messages, I just cannot find my annotations. 
> 
> Probably the solution is very easy but I just don't see it, again thanks for any help, it's really appreciated, I have no one else to talk to about UIMA but you guys on the mailing list.
> 
> Thank you!
> 
> Alex

-- 
------------------------------------------------------------------- 
Richard Eckart de Castilho
Technical Lead
Ubiquitous Knowledge Processing Lab 
FB 20 Computer Science Department      
Technische Universität Darmstadt 
Hochschulstr. 10, D-64289 Darmstadt, Germany 
phone [+49] (0)6151 16-7477, fax -5455, room S2/02/B117
eckartde@tk.informatik.tu-darmstadt.de 
www.ukp.tu-darmstadt.de 
Web Research at TU Darmstadt (WeRC) www.werc.tu-darmstadt.de
-------------------------------------------------------------------