You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@uima.apache.org by Aaron Kaplan <Aa...@xrce.xerox.com> on 2008/03/31 18:34:33 UTC

Copying feature structures between views

I have a CAS with two views, and I want to copy certain annotations from 
one view to the other, adjusting their offsets in the process.  I looked 
at org.apache.uima.util.CasCopier, but it doesn't quite do what I 
want--it will only copy from a view in one base CAS to a view with the 
same name in another base CAS.  Using the source of CasCopier as a 
model, I could easily write my own copying method, but I hesitate to do 
so because it uses low-level methods that the javadocs warn are for 
internal use only.  Is there a better way to do this?

-Aaron

Re: Copying feature structures between views

Posted by Eddie Epstein <ea...@gmail.com>.
On Tue, Apr 1, 2008 at 3:33 AM, Aaron Kaplan <Aa...@xrce.xerox.com>
wrote:

> OK, I figured it out, with help from an archived mailing list message
> from Matthew Cammpbell.  A FeatureStructure's sofa is just a feature
> like any other, and can be set with setFeatureValue().  The reason I
> missed this the first time around is that there's no convenience method
> setSofa(), as there is for other features.
>


Right, this feature is automatically set during Annotation creation. We have
done more work with the casCopier that makes things easier, but haven't had
a chance to formalize them. Your scenario could inspire more convenience
methods too.

Eddie

Re: Copying feature structures between views

Posted by Aaron Kaplan <Aa...@xrce.xerox.com>.
OK, I figured it out, with help from an archived mailing list message 
from Matthew Cammpbell.  A FeatureStructure's sofa is just a feature 
like any other, and can be set with setFeatureValue().  The reason I 
missed this the first time around is that there's no convenience method 
setSofa(), as there is for other features.

-Aaron

Aaron Kaplan wrote:
> Hi Eddie.
> 
> Eddie Epstein wrote:
> 
>> For a class that just copies from one view to another, you should be 
>> able to easily avoid the use of low-level methods.
> 
> Great, but how? I tried using the clone() method of the feature 
> structure I wanted to copy, but that creates a feature structure that's 
> associated with the original view, and I can't see how to modify it to 
> be associated with the new one.  Say I'm copying from view1 to view2. If 
> call setBegin() and setEnd() on the cloned FeatureStructure, and then 
> call addToIndexes() with no arguments, that adds it to the index of 
> view1, which is not what I want.  If I call addToIndexes(view2), I get: 
> org.apache.uima.cas.CASRuntimeException: Error - the Annotation "Token 
> ..." is over view "view1" and cannot be added to indexes associated with 
> the different view "view2".
> 
>> Note that one of the main features of this method, supporting deep 
>> copies with shared FS (FS that are referenced multiple times) may not
>> be needed in your case. An FS in the CAS can be referenced from any view.
> 
> Agreed.  If CasCopier had worked I would have lived with its behavior, 
> but in fact it would be preferable to share non-Annotation 
> FeatureStructures between views rather than copying them from one to the 
> other.
> 
> -Aaron
> 


Re: Copying feature structures between views

Posted by Aaron Kaplan <Aa...@xrce.xerox.com>.
Hi Eddie.

Eddie Epstein wrote:

> For a class that just copies from one view to another, you should be 
> able to easily avoid the use of low-level methods.

Great, but how? I tried using the clone() method of the feature 
structure I wanted to copy, but that creates a feature structure that's 
associated with the original view, and I can't see how to modify it to 
be associated with the new one.  Say I'm copying from view1 to view2. 
If call setBegin() and setEnd() on the cloned FeatureStructure, and then 
call addToIndexes() with no arguments, that adds it to the index of 
view1, which is not what I want.  If I call addToIndexes(view2), I get: 
org.apache.uima.cas.CASRuntimeException: Error - the Annotation "Token 
..." is over view "view1" and cannot be added to indexes associated with 
the different view "view2".

> Note that one of the main features of this method, supporting deep 
> copies with shared FS (FS that are referenced multiple times) may not
> be needed in your case. An FS in the CAS can be referenced from any 
> view.

Agreed.  If CasCopier had worked I would have lived with its behavior, 
but in fact it would be preferable to share non-Annotation 
FeatureStructures between views rather than copying them from one to the 
other.

-Aaron


Re: Copying feature structures between views

Posted by Eddie Epstein <ea...@gmail.com>.
Hi Aaron,

The low-level methods are used in CasCopier to allow all operations to
proceed from the baseCAS. I agree with the recommendation to avoid using
them to avoid having the code go bad in some future release. For a class
that just copies from one view to another, you should be able to easily
avoid the use of low-level methods.

Note that one of the main features of this method, supporting deep copies
with shared FS (FS that are referenced multiple times) may not be needed in
your case. An FS in the CAS can be referenced from any view.

Regards,
Eddie

On Mon, Mar 31, 2008 at 12:34 PM, Aaron Kaplan <Aa...@xrce.xerox.com>
wrote:

> I have a CAS with two views, and I want to copy certain annotations from
> one view to the other, adjusting their offsets in the process.  I looked
> at org.apache.uima.util.CasCopier, but it doesn't quite do what I
> want--it will only copy from a view in one base CAS to a view with the
> same name in another base CAS.  Using the source of CasCopier as a
> model, I could easily write my own copying method, but I hesitate to do
> so because it uses low-level methods that the javadocs warn are for
> internal use only.  Is there a better way to do this?
>
> -Aaron
>