You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@uima.apache.org by James Jichun Zhu <ji...@gmail.com> on 2011/07/22 21:24:44 UTC

XmiCasDeserializer problem with multi-views

Hi, I am trying to develop a simple analysis engine component where it 
would take two XMI files and use XmiCasDeserializer to extract the 
objects in the XMI files into two collections, and then I can compare 
the two sets of objects in memory for evaluation purpose.

What I am thinking right now is to create two views, and pass each 
view's underlying CAS to the XmiCasDeserializer so it can populate the 
CAS with objects extracted from the XMI file.

However, I am having trouble to get it to work. It works if I use the 
"_InitialView" but it does not work with the two new views that I 
created on the spot. I wonder if anybody here has some experience or 
advice on how to get this done. I would really appreciate that.

More details:

Here is how I created the views.

         JCas defaultView = null;
         JCas goldView = null;
         JCas engineView = null;

         try {
             defaultView = aJCas.getView("_InitialView");
             goldView = aJCas.createView("goldTokens");
             engineView = aJCas.createView("engineTokens");

         } catch (CASException e) {
             e.printStackTrace();
         }

Here is how I used XmiCasDeserializer to extract objects from XMI file 
and populate the CASes.

         try {
             goldInputStream = new FileInputStream(goldXmiFile);
             engineInputStream = new FileInputStream(engineXmiFile);
             XmiCasDeserializer.deserialize(goldInputStream,
                     goldView.getCas(), false);
             XmiCasDeserializer.deserialize(engineInputStream,
                     engineView.getCas(), false);
         } catch (FileNotFoundException fnfe) {
             fnfe.printStackTrace();
             return;
         } catch (SAXException saxe) {
             saxe.printStackTrace();
         } catch (IOException ioe) {
             ioe.printStackTrace();
         } finally {
             try {
                 goldInputStream.close();
                 engineInputStream.close();
             } catch (IOException ioe) {
                 ioe.printStackTrace();
             }
         }

-- 
James


Re: XmiCasDeserializer problem with multi-views

Posted by James Jichun Zhu <ji...@gmail.com>.
Thanks, Burn. That's a great suggestion. I think it would work. I will 
give it a try. Thanks again.

James


On 7/26/11 7:58 AM, Burn Lewis wrote:
> James,
>
> Deserialization can only be done into an empty CAS, and from within an 
> annotator that means one passed by the framework in the getNext method 
> of a Collection Reader or acquired by the GetEmptyCAS() method in a 
> CAS Multiplier.
>
> If for each text file you have two XMI files each containing the text 
> as their Sofas, I'd think the simplest solution would be to implement 
> A) by modifying the XmiCollectionReader in the examples folder to 
> alternatively read the XMI files from the two types of annotators and 
> make your comparison annotator act like a CAS Consumer and save the 
> results from the odd-numbered CASes to compare with the even-numbered 
> ones.
>
> ~Burn
>

Re: XmiCasDeserializer problem with multi-views

Posted by Burn Lewis <bu...@gmail.com>.
James,

Deserialization can only be done into an empty CAS, and from within an
annotator that means one passed by the framework in the getNext method of a
Collection Reader or acquired by the GetEmptyCAS() method in a CAS
Multiplier.

If for each text file you have two XMI files each containing the text as
their Sofas, I'd think the simplest solution would be to implement A) by
modifying the XmiCollectionReader in the examples folder to alternatively
read the XMI files from the two types of annotators and make your comparison
annotator act like a CAS Consumer and save the results from the odd-numbered
CASes to compare with the even-numbered ones.

~Burn

Re: XmiCasDeserializer problem with multi-views

Posted by James Jichun Zhu <ji...@gmail.com>.
It is more the scenario A) you described.

I have a number of input text files (could be a large number), for each 
I have two XMI files that contain the annotation objects, one from our 
analysis engine pipeline and the other from the human annotator. So for 
each input text file, I will need to load them both in memory and 
compare them. My output will be any differences that I can find between 
each pair of such XMI files.

Now, the challenge is that both of the XMI files were generated with the 
"_InitialView" as the sofa ID. So when I try to load them into two 
separate view's underlying CASes, it does not work mostly because of the 
identical sofa IDs embedded in the XMI files. Then I try to use one CAS 
to deserialize the 2 XMI files sequentially. But I am having trouble 
emptying the CAS after loading the first XMI file with CAS.reset() method.

James


On 7/25/2011 11:50 AM, Burn Lewis wrote:
> I'm not clear on how you'd like this pipeline to work, e.g. what are the
> inputs&  outputs to this annotator?
>
> A) Are you feeding it a stream of CASes created from the pairs of XMI files
> to be compared? e.g. X1 Y1 X2 Y2 X3 Y3 ...
> where X1&  Y1 are to be compared, then X2 Y2 etc.  If so then your annotator
> could extract the information from the 1st and save it locally to compare
> with the information in the 2nd member of the pair when it arrives.
>
> B} Or does the input CAS merely contain the names of the two XMI files to be
> compared, in which case you should follow Eddie's suggestion and implement
> it as a CAS Multiplier so that it can create a couple of empty CASes to
> deserialize into.
>
> Since the deserialize calls reconstruct a complete CAS they can only be
> applied to empty CASes so are usually made in Collection Readers or CAS
> Multipliers.
>
> ~Burn
>

Re: XmiCasDeserializer problem with multi-views

Posted by Burn Lewis <bu...@gmail.com>.
I'm not clear on how you'd like this pipeline to work, e.g. what are the
inputs & outputs to this annotator?

A) Are you feeding it a stream of CASes created from the pairs of XMI files
to be compared? e.g. X1 Y1 X2 Y2 X3 Y3 ...
where X1 & Y1 are to be compared, then X2 Y2 etc.  If so then your annotator
could extract the information from the 1st and save it locally to compare
with the information in the 2nd member of the pair when it arrives.

B} Or does the input CAS merely contain the names of the two XMI files to be
compared, in which case you should follow Eddie's suggestion and implement
it as a CAS Multiplier so that it can create a couple of empty CASes to
deserialize into.

Since the deserialize calls reconstruct a complete CAS they can only be
applied to empty CASes so are usually made in Collection Readers or CAS
Multipliers.

~Burn

Re: XmiCasDeserializer problem with multi-views

Posted by Eddie Epstein <ea...@gmail.com>.
A CasMultiplier component has a CasPool from which empty CASes can be
checked out and returned to the pool when finished. See
http://uima.apache.org/d/uimaj-2.3.1/tutorials_and_users_guides.html#ugr.tug.cm

Eddie

On Mon, Jul 25, 2011 at 1:38 PM, James Jichun Zhu <ji...@gmail.com> wrote:
> I am implementing my work as an analysis engine component so that it can be
> plugged in a CPE for processing multiple input files. If I am to do my work
> as an application, then I imagine I will have to handle looping through the
> individual input files. Maybe there are some other things I have to worry
> about. I have not tried it that way. Maybe I should. But if there is
> something similar to CAS.reset() that I can use to clear the CAS within my
> AE component, that would save me from a lot of trouble. Is there such a
> thing?
>
> James
>
>
> On 7/25/2011 10:12 AM, Marshall Schor wrote:
>>
>> Yes, you are right, the CAS Reset is for an application, not for an
>> annotator.
>>
>> Is there any reason you can't do your work as an application?  It would
>> seem to
>> "fit" there, better.
>>
>> -Marshall
>>
>> On 7/25/2011 11:32 AM, James Jichun Zhu wrote:
>>>
>>> Thanks, Burn. What I found was that the XMI files previous generated
>>> bears the
>>> sofa ID "_InitialView", and when I manually change it to a specific view
>>> name,
>>> I am able to extract the objects from the XMI file into the CAS
>>> underlying
>>> that specific view. So, you are probably right about "it re-creates a
>>> complete
>>> CAS matching the one that had been serialized".
>>>
>>> In reality, because I need to load objects from two XMI files into two
>>> separate collections, I cannot always manually update the XMI's sofa ID
>>> to two
>>> separate view names in order for them to be loaded into two separate
>>> CASes. So
>>> you are right again about loading them into the same CAS in two separate
>>> steps.
>>>
>>> However, I ran into trouble on how to clear the CAS after deserializing
>>> the
>>> first XMI file. I tried the reset() method but it seems to be intended
>>> for
>>> application (not 100% sure what it means), not for being used internally
>>> within an analysis engine component. Any other ways to get it done?
>>>
>>> Really appreciate all the help here.
>>>
>>> James
>>>
>>>
>>> On 7/22/11 2:19 PM, Burn Lewis wrote:
>>>>
>>>> XmiCasDeserialize operates on a CAS, not a View.  It re-creates a
>>>> complete
>>>> CAS matching the one that had been serialized.  If you want to compare
>>>> the
>>>> contents of two CASes (two XMI files) you'll have to deserialize them
>>>> one-by-one.  You could extract the information of interest from the 1st
>>>> before deserializing the 2nd file into the same CAS.
>>>>
>>>> Burn.
>>>>
>

Re: XmiCasDeserializer problem with multi-views

Posted by James Jichun Zhu <ji...@gmail.com>.
I am implementing my work as an analysis engine component so that it can 
be plugged in a CPE for processing multiple input files. If I am to do 
my work as an application, then I imagine I will have to handle looping 
through the individual input files. Maybe there are some other things I 
have to worry about. I have not tried it that way. Maybe I should. But 
if there is something similar to CAS.reset() that I can use to clear the 
CAS within my AE component, that would save me from a lot of trouble. Is 
there such a thing?

James


On 7/25/2011 10:12 AM, Marshall Schor wrote:
> Yes, you are right, the CAS Reset is for an application, not for an annotator.
>
> Is there any reason you can't do your work as an application?  It would seem to
> "fit" there, better.
>
> -Marshall
>
> On 7/25/2011 11:32 AM, James Jichun Zhu wrote:
>> Thanks, Burn. What I found was that the XMI files previous generated bears the
>> sofa ID "_InitialView", and when I manually change it to a specific view name,
>> I am able to extract the objects from the XMI file into the CAS underlying
>> that specific view. So, you are probably right about "it re-creates a complete
>> CAS matching the one that had been serialized".
>>
>> In reality, because I need to load objects from two XMI files into two
>> separate collections, I cannot always manually update the XMI's sofa ID to two
>> separate view names in order for them to be loaded into two separate CASes. So
>> you are right again about loading them into the same CAS in two separate steps.
>>
>> However, I ran into trouble on how to clear the CAS after deserializing the
>> first XMI file. I tried the reset() method but it seems to be intended for
>> application (not 100% sure what it means), not for being used internally
>> within an analysis engine component. Any other ways to get it done?
>>
>> Really appreciate all the help here.
>>
>> James
>>
>>
>> On 7/22/11 2:19 PM, Burn Lewis wrote:
>>> XmiCasDeserialize operates on a CAS, not a View.  It re-creates a complete
>>> CAS matching the one that had been serialized.  If you want to compare the
>>> contents of two CASes (two XMI files) you'll have to deserialize them
>>> one-by-one.  You could extract the information of interest from the 1st
>>> before deserializing the 2nd file into the same CAS.
>>>
>>> Burn.
>>>

Re: XmiCasDeserializer problem with multi-views

Posted by Marshall Schor <ms...@schor.com>.
Yes, you are right, the CAS Reset is for an application, not for an annotator.

Is there any reason you can't do your work as an application?  It would seem to
"fit" there, better.

-Marshall

On 7/25/2011 11:32 AM, James Jichun Zhu wrote:
> Thanks, Burn. What I found was that the XMI files previous generated bears the
> sofa ID "_InitialView", and when I manually change it to a specific view name,
> I am able to extract the objects from the XMI file into the CAS underlying
> that specific view. So, you are probably right about "it re-creates a complete
> CAS matching the one that had been serialized".
>
> In reality, because I need to load objects from two XMI files into two
> separate collections, I cannot always manually update the XMI's sofa ID to two
> separate view names in order for them to be loaded into two separate CASes. So
> you are right again about loading them into the same CAS in two separate steps.
>
> However, I ran into trouble on how to clear the CAS after deserializing the
> first XMI file. I tried the reset() method but it seems to be intended for
> application (not 100% sure what it means), not for being used internally
> within an analysis engine component. Any other ways to get it done?
>
> Really appreciate all the help here.
>
> James
>
>
> On 7/22/11 2:19 PM, Burn Lewis wrote:
>> XmiCasDeserialize operates on a CAS, not a View.  It re-creates a complete
>> CAS matching the one that had been serialized.  If you want to compare the
>> contents of two CASes (two XMI files) you'll have to deserialize them
>> one-by-one.  You could extract the information of interest from the 1st
>> before deserializing the 2nd file into the same CAS.
>>
>> Burn.
>>
>

Re: XmiCasDeserializer problem with multi-views

Posted by James Jichun Zhu <ji...@gmail.com>.
Thanks, Burn. What I found was that the XMI files previous generated 
bears the sofa ID "_InitialView", and when I manually change it to a 
specific view name, I am able to extract the objects from the XMI file 
into the CAS underlying that specific view. So, you are probably right 
about "it re-creates a complete CAS matching the one that had been 
serialized".

In reality, because I need to load objects from two XMI files into two 
separate collections, I cannot always manually update the XMI's sofa ID 
to two separate view names in order for them to be loaded into two 
separate CASes. So you are right again about loading them into the same 
CAS in two separate steps.

However, I ran into trouble on how to clear the CAS after deserializing 
the first XMI file. I tried the reset() method but it seems to be 
intended for application (not 100% sure what it means), not for being 
used internally within an analysis engine component. Any other ways to 
get it done?

Really appreciate all the help here.

James


On 7/22/11 2:19 PM, Burn Lewis wrote:
> XmiCasDeserialize operates on a CAS, not a View.  It re-creates a 
> complete CAS matching the one that had been serialized.  If you want 
> to compare the contents of two CASes (two XMI files) you'll have to 
> deserialize them one-by-one.  You could extract the information of 
> interest from the 1st before deserializing the 2nd file into the same 
> CAS.
>
> Burn.
>

Re: XmiCasDeserializer problem with multi-views

Posted by Burn Lewis <bu...@gmail.com>.
XmiCasDeserialize operates on a CAS, not a View.  It re-creates a complete
CAS matching the one that had been serialized.  If you want to compare the
contents of two CASes (two XMI files) you'll have to deserialize them
one-by-one.  You could extract the information of interest from the 1st
before deserializing the 2nd file into the same CAS.

Burn.