You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@uima.apache.org by Marshall Schor <ms...@schor.com> on 2007/05/10 18:04:02 UTC
changing the semantics (very slightly) for JCas objects with respect
to Views
While working on the class-loader switching code, we have revisited an
issue with the way JCas objects work with respect to views.
Currently, for each view, there is a separate set of xxx_Type objects, a
separate set of "cached" cover objects (which are identical to other
view's objects, except that their _Type ref points to the instance for
this view).
This is there only (as far as we can see) to support
aJCasObject.addToIndexes() and removeFromIndexes() which uses this
information to pick the right "view" to use (remember that indexes are
held per view).
Besides inefficiency (replication of objects per view), there is another
side-effect. JCas Objects can, themselves, be extended by users to hold
additional information, other than what's in the CAS. The current
design would create new versions of these objects per view, so that
iterators over different views would get different instances. So
information set into one JCas object in one view would not be "visible"
to instances obtained by iterating using a different view's index. This
could be a documented "feature", or it could be a "bug".
Because current users seem to often use the aJCasObject.addToIndexes()
method, I want to retain that method, while getting the efficiencies and
fixing the "bug" (if we consider it a bug) above. To do this, we could
make this work as before *for sofa-unaware annotators, only* as
follows: Change the impl of addToIndexes and removeFromIndexes to
reference the "current-view".
Where to get the current-view? First, it needs to be accessable in
several contexts, including the main one (JCas use in an annotator),
but also any other places JCas can be used - which includes
(top-level) application code, call-back routines (which include a
handle to a CAS), and code in flow controllers (which have access to
a CAS). One way I can see to do this is to stick an object
identifying the current-view onto thread-local. Any other
suggestions appreciated....
For *sofa-aware* annotators, we could use this same approach, but might
want to give warnings as well.
-Marshall
Re: changing the semantics (very slightly) for JCas objects with respect to Views
Posted by Adam Lally <al...@alum.rpi.edu>.
On 5/14/07, Marshall Schor <ms...@schor.com> wrote:
> Changes:
> 1) 1 map from CAS objects to JCas cover objects, shared by all views
> 2) The getters from the iterators would *update* the _Type ref to be the
> view associated with the iterator
> * this might be implemented by changing the generators, using
> reflection, or not - TBD
> 3) addto/removeFrom indexes for subtypes of Annotation_base use the sofa
> ptr to get the right view.
>
> These are not changed:
> 4) There is a set of _Type objects, one per view
>
> Please let me know if I've overlooked something
+1
-Adam
Re: changing the semantics (very slightly) for JCas objects with
respect to Views
Posted by Marshall Schor <ms...@schor.com>.
Marshall Schor wrote:
> Marshall Schor wrote:
>> Adam Lally wrote:
>>> On 5/13/07, Marshall Schor <ms...@schor.com> wrote:
>>>> Before:
>>>> ---------------------------------------------------
>>>> MyAnnotation x = new MyAnnotation(someView_1);
>>>> aView_1.addFsToIndexes(x);
>>>> aView_2.addFsToIndexes(x);
>>>>
>>>> // removes from view_1
>>>> aView_2.getAllIndexedFS(MyAnnotation.type).get().removeFromIndexes();
>>>> ----------------------------------------------------
>>>
>>> No, this currently removes from view 2. This is the same as the
>>> example I gave, more or less. I think your proposal does not change
>>> this behavior.
>>>
>>
>> oops, that's right. I had forgotten that each view in the "before"
>> case has its own map from
>> CAS objects to JCas cover objects, so it would get a different cover
>> object.
>>>
>>>> My current leaning is toward the "most savings" choices, with updating
>>>> the preferred view on "new", get/next from iterators, and getView().
>>>>
>>>
>>> Let me restate this to see if I get it right. Basically the idea is
>>> that when addToIndexes() or removeFromIndexes() are called on a
>>> non-annotation object, it would affect the most recently used view.
>>> (Where to "use" a view means any of: calling getView() for that view,
>>> creating a new FS instance off of that view, or accessing the
>>> iterators for that view.)
>>>
>>> Consequence of this: the following have different behavior:
>>>
>>> (1)
>>> JCas someView_1 = baseJCas.getView(name1);
>>> JCas someView_2 = baseJCas,getView(name2);
>>>
>>> MyType annot_1 = new MyType(someView_1);
>>> annot_1.addToIndexes(); //adds to someView_1
>>>
>>> MyType annot_2 = new MyType(someView_2);
>>> annot_2.addToIndexes(); //adds to someView_2
>>>
>>> (2)
>>> JCas someView_1 = baseJCas.getView(name1);
>>> JCas someView_2 = baseJCas,getView(name2);
>>>
>>> MyType annot_1 = new MyType(someView_1);
>>> MyType annot_2 = new MyType(someView_2);
>>>
>>> annot_1.addToIndexes(); //adds to someView_2 <<<<<< CHANGED
>>> annot_2.addToIndexes(); //adds to someView_2
>>>
>>>
>>> (In the current implementation, annot_1.addToIndexes() would add to
>>> someView_1 in both cases.)
>>>
>>>
>>> It seems strange to me that the call to annot_2 = new
>>> MyType(someView_2) would affect what happens to annot_1. I admit that
>>> this may just be a hypothetical example and that no annotators
>>> actually do something like this. But it just doesn't seem like the
>>> cleanest design. If we do decide to go with this I think I would want
>>> to deprecate the methods at the same time.
>>>
>>> I still prefer the semantics of my alternative suggestion to use
>>> separate _Type objects (but shared generators and instance map), with
>>> your idea of changing the _Type ref when an object is returned from an
>>> iterator. Then the above code example works in what I think is a more
>>> intuitive way.
>>
>> So, the view ref for a JCas instance is "sticky" with that particular
>> JCas instance, and
>> changes when it's retrieved from another iterator.
>>>
>>> I think the final decision comes down to: is the performance savings
>>> we expect from eliminating the duplicate _Type objects worth the risk
>>> that we might break an annotator.
>>>
>>
>> I don't think there is a significant performance savings. So I'm
>> willing to go with the following
>> (let's see if I get this right...)
>>
>> Changes:
>> 1) 1 map from CAS objects to JCas cover objects, shared by all views
>> 2) The getters from the iterators would *update* the _Type ref to be
>> the view associated with the iterator
>> * this might be implemented by changing the generators, using
>> reflection, or not - TBD
>> 3) addto/removeFrom indexes for subtypes of Annotation_base use the
>> sofa ptr to get the right view.
>>
>> These are not changed:
>> 4) There is a set of _Type objects, one per view
>>
>> Please let me know if I've overlooked something
>> -Marshall
>>
>>
> Here's one more thing overlooked: There are 3 ways to generate JCas
> cover objects: the 2 cited above (
> "new" and "obtain from iterator", plus a third: dereference from
> another object (follow a link from an FSRef value).
>
> For this third case, with this impl, the value of the "view" would be
> either the view it was created in, or the view it was
> obtained from via an iterator, which ever happens last. So the same
> code could return different behaviors depending on
> execution order, some of which could be "remote" from the reference.
> This is not ideal, to say the least. Some alternatives include
> specifying the view when dereferencing (for instance, making it the
> same view as the object it's being referred from (unless it's a
> subtype of base-annotation).
>
> Can people voice their opinions about this?
>
> -Marshall
>
>
>
One other approach for this third thing would be to set the View to be
the base view. This would make addtoIndexes() and removeFromIndexes()
fail, for objects obtained this way. This is likely better, in my view,
than having them operate in a manner where other things could change
which view these were operating on.
When I try and imagine real use cases involving following dereferencing
of things in the CAS, followed by an addToIndex/RemoveFromIndex, I don't
come up with too much - and this would allow users to update their code
to do
these operations in a robust way. The only downside (besides breaking
running code for some small number of instances) is the case where users
were not using views at all. In this case, I'd like this to work as
before. And maybe that could be done, too.
Re: changing the semantics (very slightly) for JCas objects with
respect to Views
Posted by Marshall Schor <ms...@schor.com>.
Marshall Schor wrote:
> Adam Lally wrote:
>> On 5/13/07, Marshall Schor <ms...@schor.com> wrote:
>>> Before:
>>> ---------------------------------------------------
>>> MyAnnotation x = new MyAnnotation(someView_1);
>>> aView_1.addFsToIndexes(x);
>>> aView_2.addFsToIndexes(x);
>>>
>>> // removes from view_1
>>> aView_2.getAllIndexedFS(MyAnnotation.type).get().removeFromIndexes();
>>> ----------------------------------------------------
>>
>> No, this currently removes from view 2. This is the same as the
>> example I gave, more or less. I think your proposal does not change
>> this behavior.
>>
>
> oops, that's right. I had forgotten that each view in the "before"
> case has its own map from
> CAS objects to JCas cover objects, so it would get a different cover
> object.
>>
>>> My current leaning is toward the "most savings" choices, with updating
>>> the preferred view on "new", get/next from iterators, and getView().
>>>
>>
>> Let me restate this to see if I get it right. Basically the idea is
>> that when addToIndexes() or removeFromIndexes() are called on a
>> non-annotation object, it would affect the most recently used view.
>> (Where to "use" a view means any of: calling getView() for that view,
>> creating a new FS instance off of that view, or accessing the
>> iterators for that view.)
>>
>> Consequence of this: the following have different behavior:
>>
>> (1)
>> JCas someView_1 = baseJCas.getView(name1);
>> JCas someView_2 = baseJCas,getView(name2);
>>
>> MyType annot_1 = new MyType(someView_1);
>> annot_1.addToIndexes(); //adds to someView_1
>>
>> MyType annot_2 = new MyType(someView_2);
>> annot_2.addToIndexes(); //adds to someView_2
>>
>> (2)
>> JCas someView_1 = baseJCas.getView(name1);
>> JCas someView_2 = baseJCas,getView(name2);
>>
>> MyType annot_1 = new MyType(someView_1);
>> MyType annot_2 = new MyType(someView_2);
>>
>> annot_1.addToIndexes(); //adds to someView_2 <<<<<< CHANGED
>> annot_2.addToIndexes(); //adds to someView_2
>>
>>
>> (In the current implementation, annot_1.addToIndexes() would add to
>> someView_1 in both cases.)
>>
>>
>> It seems strange to me that the call to annot_2 = new
>> MyType(someView_2) would affect what happens to annot_1. I admit that
>> this may just be a hypothetical example and that no annotators
>> actually do something like this. But it just doesn't seem like the
>> cleanest design. If we do decide to go with this I think I would want
>> to deprecate the methods at the same time.
>>
>> I still prefer the semantics of my alternative suggestion to use
>> separate _Type objects (but shared generators and instance map), with
>> your idea of changing the _Type ref when an object is returned from an
>> iterator. Then the above code example works in what I think is a more
>> intuitive way.
>
> So, the view ref for a JCas instance is "sticky" with that particular
> JCas instance, and
> changes when it's retrieved from another iterator.
>>
>> I think the final decision comes down to: is the performance savings
>> we expect from eliminating the duplicate _Type objects worth the risk
>> that we might break an annotator.
>>
>
> I don't think there is a significant performance savings. So I'm
> willing to go with the following
> (let's see if I get this right...)
>
> Changes:
> 1) 1 map from CAS objects to JCas cover objects, shared by all views
> 2) The getters from the iterators would *update* the _Type ref to be
> the view associated with the iterator
> * this might be implemented by changing the generators, using
> reflection, or not - TBD
> 3) addto/removeFrom indexes for subtypes of Annotation_base use the
> sofa ptr to get the right view.
>
> These are not changed:
> 4) There is a set of _Type objects, one per view
>
> Please let me know if I've overlooked something
> -Marshall
>
>
Here's one more thing overlooked: There are 3 ways to generate JCas
cover objects: the 2 cited above (
"new" and "obtain from iterator", plus a third: dereference from another
object (follow a link from an FSRef value).
For this third case, with this impl, the value of the "view" would be
either the view it was created in, or the view it was
obtained from via an iterator, which ever happens last. So the same
code could return different behaviors depending on
execution order, some of which could be "remote" from the reference.
This is not ideal, to say the least. Some alternatives include
specifying the view when dereferencing (for instance, making it the same
view as the object it's being referred from (unless it's a subtype of
base-annotation).
Can people voice their opinions about this?
-Marshall
Re: changing the semantics (very slightly) for JCas objects with
respect to Views
Posted by Marshall Schor <ms...@schor.com>.
Thilo Goetz wrote:
> Eddie Epstein wrote:
>
>> On 5/14/07, Adam Lally <al...@alum.rpi.edu> wrote:
>>
>>> I prefer that we deprecate addToIndexes() and removeFromIndexes() but
>>> take reasonable steps to make the methods behave is closely to the
>>> current behavior as possible. If Marshall is willing to implement
>>> something a little more complex that reduces the chance of breaking
>>> annotators, then I think that would be good.
>>>
>> There's no question that these methods should work for single view
>> annotators; that is a given. To have it work for some multi-view
>> annotators but not others does not seem like an advantage. A warning
>> should be given that these methods should not be used for a multi-view
>> annotator.
>>
>> Another thing to consider is non-JCas cover classes. Ideally all cover
>> classes would point at the base CAS, as all FS exist in the same heap,
>> shared for all views. Would be nice for both CAS and JCas cover
>> classes to have the same simple model.
>>
>> Eddie
>>
>
> Sorry, stupid question from a non-Sofa aware developer. I lost the
> thread of this discussion right at the start. Why does the JCas need
> to know about views? Why can't it just use the view information that's
> in the CAS? When I get to an annotation by dereferencing, that
> annotation already lives in some given view, known to the CAS. That's
> the one that needs to be used, right? I'm probably missing the point
> entirely here, so please enlighten me.
>
> --Thilo
Good questions. The only reason for JCas knowing about views are to be
able to implement methods like:
aJCasObject.addToIndexes() and aJCasObject.removeFromIndexes()
If you recall, there are 2 fields in aJCasObject: one is the "addr"
(int) of the object in the CAS array, the other is a ref to the CAS view
(it's really a ref to the instance of the _Type JCas object, which, in
turn, has a ref to the CAS view.)
The impl of addToIndexes() uses this information to determine which set
of indexes to add the fs to.
---------------------
"When you get to an annotation by dereferencing" - that's not the
issue. The issue is when you get to a *feature-structure*,
which is not an annotation. These things can be "living" in 0 or more
views, by which I mean, they can be "indexed" in 0 or
more views.
You are correct with respect to feature structures which are subtypes of
annotation-base - they can only be living (indexed)
in 0 or 1 view, and they have that extra field which can be used to
locate the view.
Please ask more questions :-)
-Marshall
Re: changing the semantics (very slightly) for JCas objects with
respect to Views
Posted by Thilo Goetz <tw...@gmx.de>.
Eddie Epstein wrote:
> On 5/14/07, Adam Lally <al...@alum.rpi.edu> wrote:
>> I prefer that we deprecate addToIndexes() and removeFromIndexes() but
>> take reasonable steps to make the methods behave is closely to the
>> current behavior as possible. If Marshall is willing to implement
>> something a little more complex that reduces the chance of breaking
>> annotators, then I think that would be good.
>
> There's no question that these methods should work for single view
> annotators; that is a given. To have it work for some multi-view
> annotators but not others does not seem like an advantage. A warning
> should be given that these methods should not be used for a multi-view
> annotator.
>
> Another thing to consider is non-JCas cover classes. Ideally all cover
> classes would point at the base CAS, as all FS exist in the same heap,
> shared for all views. Would be nice for both CAS and JCas cover
> classes to have the same simple model.
>
> Eddie
Sorry, stupid question from a non-Sofa aware developer. I lost the
thread of this discussion right at the start. Why does the JCas need
to know about views? Why can't it just use the view information that's
in the CAS? When I get to an annotation by dereferencing, that
annotation already lives in some given view, known to the CAS. That's
the one that needs to be used, right? I'm probably missing the point
entirely here, so please enlighten me.
--Thilo
Re: changing the semantics (very slightly) for JCas objects with respect to Views
Posted by Eddie Epstein <ea...@gmail.com>.
On 5/14/07, Adam Lally <al...@alum.rpi.edu> wrote:
> I prefer that we deprecate addToIndexes() and removeFromIndexes() but
> take reasonable steps to make the methods behave is closely to the
> current behavior as possible. If Marshall is willing to implement
> something a little more complex that reduces the chance of breaking
> annotators, then I think that would be good.
There's no question that these methods should work for single view
annotators; that is a given. To have it work for some multi-view
annotators but not others does not seem like an advantage. A warning
should be given that these methods should not be used for a multi-view
annotator.
Another thing to consider is non-JCas cover classes. Ideally all cover
classes would point at the base CAS, as all FS exist in the same heap,
shared for all views. Would be nice for both CAS and JCas cover
classes to have the same simple model.
Eddie
Re: changing the semantics (very slightly) for JCas objects with respect to Views
Posted by Adam Lally <al...@alum.rpi.edu>.
On 5/14/07, Eddie Epstein <ea...@gmail.com> wrote:
> JCas objects are broken if an FS instance can belong to multiple
> views, because 1) addToIndexes() is ambiguous and 2) hashed JCas
> instances are not shared across views. The suggestions above do not
> fix the situation for all scenarios, for example, situations where a
> JCas object is retrieved from a reference.
>
> Given that there is no complicated approach that always works, a
> simpler approach is called for: just have one set of xxx_Type objects,
> deprecate addToIndexes() and always map it to the current view.
>
I prefer that we deprecate addToIndexes() and removeFromIndexes() but
take reasonable steps to make the methods behave is closely to the
current behavior as possible. If Marshall is willing to implement
something a little more complex that reduces the chance of breaking
annotators, then I think that would be good.
The issues with obtaining a JCas object by a reference are not ideal,
but we're digging pretty deep to turn up these situations. Ideally
I'd like it if everything worked as before, but if we can't manage
that I think we're close enough.
-Adam
Re: changing the semantics (very slightly) for JCas objects with
respect to Views
Posted by Marshall Schor <ms...@schor.com>.
Eddie Epstein wrote:
> On 5/14/07, Marshall Schor <ms...@schor.com> wrote:
>> I don't think there is a significant performance savings. So I'm
>> willing to go with the following
>> (let's see if I get this right...)
>>
>> Changes:
>> 1) 1 map from CAS objects to JCas cover objects, shared by all views
>> 2) The getters from the iterators would *update* the _Type ref to be the
>> view associated with the iterator
>> * this might be implemented by changing the generators, using
>> reflection, or not - TBD
>> 3) addto/removeFrom indexes for subtypes of Annotation_base use the sofa
>> ptr to get the right view.
>>
>> These are not changed:
>> 4) There is a set of _Type objects, one per view
>>
>> Please let me know if I've overlooked something
>> -Marshall
>>
>
> JCas objects are broken if an FS instance can belong to multiple
> views, because 1) addToIndexes() is ambiguous and 2) hashed JCas
> instances are not shared across views. The suggestions above do not
> fix the situation for all scenarios, for example, situations where a
> JCas object is retrieved from a reference.
True; no *fix* is perfect for this, so far. The question is how trade
off simplicity
of implementation, simplicity of "explanation" to users, and making it
work the
way naive users would want it to in the largest number of use-cases.
Also -see other reply in this thread about the FSRef case.
>
> Given that there is no complicated approach that always works, a
> simpler approach is called for: just have one set of xxx_Type objects,
> deprecate addToIndexes() and always map it to the current view.
Is this suggestion is the same as the message
http://article.gmane.org/gmane.comp.apache.uima.devel/247
with possibly some simplification for setting *current-view*?
Is the suggestion is to have *current-view* be *fixed* for the duration
of user-code, and be
whatever the view was upon entry? That would seem to break a lot of
things, such as a sofa-aware
code doing the most basic use of this:
myView = aJCas.getView(....);
// next line trys to add to base view... fails always
(new MyJCasInstance(myView)).addToIndexes();
My preference, if we were to go down this path, would be to be guided by
the 80/20 rule - do 20 % of the effort that
covers maybe 80% of the cases, and is simple enough to be
explainable/documentable.
Can you be more specific about how "simple" you want to make things, and
how you would trade off
* simplicity of explanation to users
* % of more-likely-use-cases that would work
* simplicity of implementation
-Marshall
Re: changing the semantics (very slightly) for JCas objects with respect to Views
Posted by Eddie Epstein <ea...@gmail.com>.
On 5/14/07, Marshall Schor <ms...@schor.com> wrote:
> I don't think there is a significant performance savings. So I'm
> willing to go with the following
> (let's see if I get this right...)
>
> Changes:
> 1) 1 map from CAS objects to JCas cover objects, shared by all views
> 2) The getters from the iterators would *update* the _Type ref to be the
> view associated with the iterator
> * this might be implemented by changing the generators, using
> reflection, or not - TBD
> 3) addto/removeFrom indexes for subtypes of Annotation_base use the sofa
> ptr to get the right view.
>
> These are not changed:
> 4) There is a set of _Type objects, one per view
>
> Please let me know if I've overlooked something
> -Marshall
>
JCas objects are broken if an FS instance can belong to multiple
views, because 1) addToIndexes() is ambiguous and 2) hashed JCas
instances are not shared across views. The suggestions above do not
fix the situation for all scenarios, for example, situations where a
JCas object is retrieved from a reference.
Given that there is no complicated approach that always works, a
simpler approach is called for: just have one set of xxx_Type objects,
deprecate addToIndexes() and always map it to the current view.
Eddie
Re: changing the semantics (very slightly) for JCas objects with
respect to Views
Posted by Marshall Schor <ms...@schor.com>.
Adam Lally wrote:
> On 5/13/07, Marshall Schor <ms...@schor.com> wrote:
>> Before:
>> ---------------------------------------------------
>> MyAnnotation x = new MyAnnotation(someView_1);
>> aView_1.addFsToIndexes(x);
>> aView_2.addFsToIndexes(x);
>>
>> // removes from view_1
>> aView_2.getAllIndexedFS(MyAnnotation.type).get().removeFromIndexes();
>> ----------------------------------------------------
>
> No, this currently removes from view 2. This is the same as the
> example I gave, more or less. I think your proposal does not change
> this behavior.
>
oops, that's right. I had forgotten that each view in the "before" case
has its own map from
CAS objects to JCas cover objects, so it would get a different cover object.
>
>> My current leaning is toward the "most savings" choices, with updating
>> the preferred view on "new", get/next from iterators, and getView().
>>
>
> Let me restate this to see if I get it right. Basically the idea is
> that when addToIndexes() or removeFromIndexes() are called on a
> non-annotation object, it would affect the most recently used view.
> (Where to "use" a view means any of: calling getView() for that view,
> creating a new FS instance off of that view, or accessing the
> iterators for that view.)
>
> Consequence of this: the following have different behavior:
>
> (1)
> JCas someView_1 = baseJCas.getView(name1);
> JCas someView_2 = baseJCas,getView(name2);
>
> MyType annot_1 = new MyType(someView_1);
> annot_1.addToIndexes(); //adds to someView_1
>
> MyType annot_2 = new MyType(someView_2);
> annot_2.addToIndexes(); //adds to someView_2
>
> (2)
> JCas someView_1 = baseJCas.getView(name1);
> JCas someView_2 = baseJCas,getView(name2);
>
> MyType annot_1 = new MyType(someView_1);
> MyType annot_2 = new MyType(someView_2);
>
> annot_1.addToIndexes(); //adds to someView_2 <<<<<< CHANGED
> annot_2.addToIndexes(); //adds to someView_2
>
>
> (In the current implementation, annot_1.addToIndexes() would add to
> someView_1 in both cases.)
>
>
> It seems strange to me that the call to annot_2 = new
> MyType(someView_2) would affect what happens to annot_1. I admit that
> this may just be a hypothetical example and that no annotators
> actually do something like this. But it just doesn't seem like the
> cleanest design. If we do decide to go with this I think I would want
> to deprecate the methods at the same time.
>
> I still prefer the semantics of my alternative suggestion to use
> separate _Type objects (but shared generators and instance map), with
> your idea of changing the _Type ref when an object is returned from an
> iterator. Then the above code example works in what I think is a more
> intuitive way.
So, the view ref for a JCas instance is "sticky" with that particular
JCas instance, and
changes when it's retrieved from another iterator.
>
> I think the final decision comes down to: is the performance savings
> we expect from eliminating the duplicate _Type objects worth the risk
> that we might break an annotator.
>
I don't think there is a significant performance savings. So I'm
willing to go with the following
(let's see if I get this right...)
Changes:
1) 1 map from CAS objects to JCas cover objects, shared by all views
2) The getters from the iterators would *update* the _Type ref to be the
view associated with the iterator
* this might be implemented by changing the generators, using
reflection, or not - TBD
3) addto/removeFrom indexes for subtypes of Annotation_base use the sofa
ptr to get the right view.
These are not changed:
4) There is a set of _Type objects, one per view
Please let me know if I've overlooked something
-Marshall
Re: changing the semantics (very slightly) for JCas objects with respect to Views
Posted by Adam Lally <al...@alum.rpi.edu>.
On 5/13/07, Marshall Schor <ms...@schor.com> wrote:
> Before:
> ---------------------------------------------------
> MyAnnotation x = new MyAnnotation(someView_1);
> aView_1.addFsToIndexes(x);
> aView_2.addFsToIndexes(x);
>
> // removes from view_1
> aView_2.getAllIndexedFS(MyAnnotation.type).get().removeFromIndexes();
> ----------------------------------------------------
No, this currently removes from view 2. This is the same as the
example I gave, more or less. I think your proposal does not change
this behavior.
> My current leaning is toward the "most savings" choices, with updating
> the preferred view on "new", get/next from iterators, and getView().
>
Let me restate this to see if I get it right. Basically the idea is
that when addToIndexes() or removeFromIndexes() are called on a
non-annotation object, it would affect the most recently used view.
(Where to "use" a view means any of: calling getView() for that view,
creating a new FS instance off of that view, or accessing the
iterators for that view.)
Consequence of this: the following have different behavior:
(1)
JCas someView_1 = baseJCas.getView(name1);
JCas someView_2 = baseJCas,getView(name2);
MyType annot_1 = new MyType(someView_1);
annot_1.addToIndexes(); //adds to someView_1
MyType annot_2 = new MyType(someView_2);
annot_2.addToIndexes(); //adds to someView_2
(2)
JCas someView_1 = baseJCas.getView(name1);
JCas someView_2 = baseJCas,getView(name2);
MyType annot_1 = new MyType(someView_1);
MyType annot_2 = new MyType(someView_2);
annot_1.addToIndexes(); //adds to someView_2 <<<<<< CHANGED
annot_2.addToIndexes(); //adds to someView_2
(In the current implementation, annot_1.addToIndexes() would add to
someView_1 in both cases.)
It seems strange to me that the call to annot_2 = new
MyType(someView_2) would affect what happens to annot_1. I admit that
this may just be a hypothetical example and that no annotators
actually do something like this. But it just doesn't seem like the
cleanest design. If we do decide to go with this I think I would want
to deprecate the methods at the same time.
I still prefer the semantics of my alternative suggestion to use
separate _Type objects (but shared generators and instance map), with
your idea of changing the _Type ref when an object is returned from an
iterator. Then the above code example works in what I think is a more
intuitive way.
I think the final decision comes down to: is the performance savings
we expect from eliminating the duplicate _Type objects worth the risk
that we might break an annotator.
-Adam
Re: changing the semantics (very slightly) for JCas objects with
respect to Views
Posted by Marshall Schor <ms...@schor.com>.
Adam Lally wrote:
> On 5/11/07, Marshall Schor <ms...@schor.com> wrote:
>> Adam Lally wrote:
>> > Another thought: Is it possible to have separate instances of _Type
>> > for each view, but to have only one, shared, set of generators?
>> >
>> > The FSGenerator.createFS method is passed a CAS reference - is this a
>> > reference to the view? If so, it seems like only one generator is
>> > needed - it could look up the necessary _Type object from the view.
>> >
>> > -Adam
>> Yes, but :-)
>>
>> Downside - it requires regenerating all the jcas code... So older
>> versions wouldn't work...
>>
>
> Hmm. Why do we even need individual generator classes defined in the
> _Type objects? The only thing that changes in the different
> generators is the actual name of the class to construct, which is
> available by reflection anyway. So I think we could define just one
> JCasFsGenerator class that worked for all JCas types, and JCasGen
> could just stop generating the code for that. Old JCas-generated
> classes would still work, we'd just ignore the generator.
>
Cool... out of the box thinking ... This was originally not done
because of fears that reflection was slow, but maybe that's not true in
Java anymore.
>
>> Other downside is this still "breaks" the implied contract about there
>> being one JCas cover object per unique CAS instance.
>>
>
> True. So what if we change thing so we have a single
> CAS-addr-to-JCAS-instance-map? Then this code would still work:
>
> --------------
> JCas someView_1 = baseJCas.getView(name1);
> JCas someView_2 = baseJCas,getView(name2);
>
> (new MyAnnotation(someView_1)).addToIndexes();
> (new MyAnnotation(someView_2)).addToIndexes();
> ---------------
>
>
> Then what wouldn't work is something like:
>
> -------------
> MyAnnotation x = new MyAnnotation(someView_1);
> someView_1.addFsToIndexes(x);
> someView_2.addFsToIndexes(x);
>
> FSIterator iterator = someView_2.getAllIndexedFS(MyAnnotation.type);
> MyAnnotation y = iterator.get();
> y.removeFromIndexes();
> --------------
>
> Current behavior is that y != x, and y.removeFromIndexes() removes it
> from the indexes for someView_2.
>
> Behavior if we change this so y==x is that y.removeFromIndexes() would
> remove it from the indexes for someView_1.
We could make this work, even... by updating the JCasInstance - to -
view map when the iterater returns it, to always reflect the most recent
view it was "iterated" out of (sorry for that English...).
Here's a summary of this thread:
First - a universally good idea: for types which are subtypes of
Annotation, use the Sofa ref for the view (since this is the only
"legal" index to use).
Choice points:
One JCas object per Cas Object or multiple ones, one per view.
Having one makes the implied semantics of extra JCas fields work
better. Note that it is possible, when using get()/next() on an
iterator, to "update" the _Type ref to correspond to the view
associated with the iterator.
One set of _Type instances shared for all views, or one per View.
Having one per view lets the JCas instances "encode" a "preferred
view" for use in add-to/remove-from indexes, if that's desired.
The view used for addto/removeFrom indexes can be a value that is
specific to an instance, or one that is global, but changing,
according to actions such as "new" and get/next out of an iterator,
and (maybe) getView. If it specific, either we need one set of
_Type instances per View, or an extra Map from JCas Instances to views.
The most savings in space/time is acheived by
* one JCas object per CAS object
* one _Type instance shared by all views
* no map from JCas object to View (implies that the preferred view
is global, and not kept per instance)
Note that no JCasGen or Generator changes are needed with this choice,
and the generators can now be shared among views.
Backwards compatibility:
Single view things work. Multiple view things that don't have complex
interweaving probably work. The exact semantics change, perhaps for the
better. Example of better:
Before:
---------------------------------------------------
MyAnnotation x = new MyAnnotation(someView_1);
aView_1.addFsToIndexes(x);
aView_2.addFsToIndexes(x);
// removes from view_1
aView_2.getAllIndexedFS(MyAnnotation.type).get().removeFromIndexes();
----------------------------------------------------
After - removes from view_2, which actually might be better, because
users probably expect if they get a value from an iterator, and then
remove it, it should remove it from that index.
(Of course, if you then did a next() operation, you'd get a
ConcurrentModificationException - but that's another issue :-)
----------------------------------------------------
My current leaning is toward the "most savings" choices, with updating
the preferred view on "new", get/next from iterators, and getView().
What do you think?
-Marshall
Re: changing the semantics (very slightly) for JCas objects with respect to Views
Posted by Adam Lally <al...@alum.rpi.edu>.
On 5/11/07, Marshall Schor <ms...@schor.com> wrote:
> Adam Lally wrote:
> > Another thought: Is it possible to have separate instances of _Type
> > for each view, but to have only one, shared, set of generators?
> >
> > The FSGenerator.createFS method is passed a CAS reference - is this a
> > reference to the view? If so, it seems like only one generator is
> > needed - it could look up the necessary _Type object from the view.
> >
> > -Adam
> Yes, but :-)
>
> Downside - it requires regenerating all the jcas code... So older
> versions wouldn't work...
>
Hmm. Why do we even need individual generator classes defined in the
_Type objects? The only thing that changes in the different
generators is the actual name of the class to construct, which is
available by reflection anyway. So I think we could define just one
JCasFsGenerator class that worked for all JCas types, and JCasGen
could just stop generating the code for that. Old JCas-generated
classes would still work, we'd just ignore the generator.
> Other downside is this still "breaks" the implied contract about there
> being one JCas cover object per unique CAS instance.
>
True. So what if we change thing so we have a single
CAS-addr-to-JCAS-instance-map? Then this code would still work:
--------------
JCas someView_1 = baseJCas.getView(name1);
JCas someView_2 = baseJCas,getView(name2);
(new MyAnnotation(someView_1)).addToIndexes();
(new MyAnnotation(someView_2)).addToIndexes();
---------------
Then what wouldn't work is something like:
-------------
MyAnnotation x = new MyAnnotation(someView_1);
someView_1.addFsToIndexes(x);
someView_2.addFsToIndexes(x);
FSIterator iterator = someView_2.getAllIndexedFS(MyAnnotation.type);
MyAnnotation y = iterator.get();
y.removeFromIndexes();
--------------
Current behavior is that y != x, and y.removeFromIndexes() removes it
from the indexes for someView_2.
Behavior if we change this so y==x is that y.removeFromIndexes() would
remove it from the indexes for someView_1.
-Adam
Re: changing the semantics (very slightly) for JCas objects with
respect to Views
Posted by Marshall Schor <ms...@schor.com>.
Adam Lally wrote:
> Another thought: Is it possible to have separate instances of _Type
> for each view, but to have only one, shared, set of generators?
>
> The FSGenerator.createFS method is passed a CAS reference - is this a
> reference to the view? If so, it seems like only one generator is
> needed - it could look up the necessary _Type object from the view.
>
> -Adam
Yes, but :-)
Downside - it requires regenerating all the jcas code... So older
versions wouldn't work...
Other downside is this still "breaks" the implied contract about there
being one JCas cover object per unique CAS instance.
-Marshall
Re: changing the semantics (very slightly) for JCas objects with respect to Views
Posted by Adam Lally <al...@alum.rpi.edu>.
Another thought: Is it possible to have separate instances of _Type
for each view, but to have only one, shared, set of generators?
The FSGenerator.createFS method is passed a CAS reference - is this a
reference to the view? If so, it seems like only one generator is
needed - it could look up the necessary _Type object from the view.
-Adam
Re: changing the semantics (very slightly) for JCas objects with respect to Views
Posted by Adam Lally <al...@alum.rpi.edu>.
On 5/11/07, Marshall Schor <ms...@schor.com> wrote:
>> Adam wrote:
> > Next thought... what if instead of the separate _Type objects, you
> > maintained in the JCasImpl a map from JCas object to "home view". As
> > above you only need to do this for non-annotation objects that have
> > indexes defined for them (AND if the home view is not the initial
> > view, since that could be the default).
> >
> > That has different performance characteristics which may or may not
> > necessarily be better (it depends on how many instances get created I
> > think), but maybe it is a cleaner way to stay compatible.
> Not sure I follow this... Let's see - you would have one generator set,
> which iterators would use to generate a cover instance, for all the
> different views, . If a cover instance already existed, you would need
> to examine this map-to-home-view, and see if the home view was the right
> one. If not, you would generate an additional cover instance. The
> cache from key=CAS addr to value=cover-JCas-instance would need to map
> to a collection of cover-JCas-instances, possibly one per view in which
> it was indexed. Is this what you were thinking?
>
Not quite. I was imagining only one cover-JCas-instance per FS. The
idea was to move the information that associates a cover-JCas-instance
with a view out, taking it out of the instance and moving it into a
map that's stored in the JCas. The JCAS would store a map from the
cover-JCAS-instance to whichever view that instance was originally
created against, and addToIndexes() would always use that.
On further thought I don't think I like the performance implications
of that, though, since if someone creates many instances of the same
non-annotation type we'd have an entry in the map for all of them. So
maybe forget that idea.
-Adam
Re: changing the semantics (very slightly) for JCas objects with
respect to Views
Posted by Marshall Schor <ms...@schor.com>.
Adam Lally wrote:
> On 5/10/07, Marshall Schor <ms...@schor.com> wrote:
>> While working on the class-loader switching code, we have revisited an
>> issue with the way JCas objects work with respect to views.
>>
>> Currently, for each view, there is a separate set of xxx_Type objects, a
>> separate set of "cached" cover objects (which are identical to other
>> view's objects, except that their _Type ref points to the instance for
>> this view).
>>
>> This is there only (as far as we can see) to support
>> aJCasObject.addToIndexes() and removeFromIndexes() which uses this
>> information to pick the right "view" to use (remember that indexes are
>> held per view).
>>
>> Besides inefficiency (replication of objects per view), there is another
>> side-effect. JCas Objects can, themselves, be extended by users to hold
>> additional information, other than what's in the CAS. The current
>> design would create new versions of these objects per view, so that
>> iterators over different views would get different instances. So
>> information set into one JCas object in one view would not be "visible"
>> to instances obtained by iterating using a different view's index. This
>> could be a documented "feature", or it could be a "bug".
>>
>> Because current users seem to often use the aJCasObject.addToIndexes()
>> method, I want to retain that method, while getting the efficiencies and
>> fixing the "bug" (if we consider it a bug) above. To do this, we could
>> make this work as before *for sofa-unaware annotators, only* as
>> follows: Change the impl of addToIndexes and removeFromIndexes to
>> reference the "current-view".
>>
>
> It makes me very nervous to put in changes that intentionally break
> compatibility with existing annotators. One of UIMA's main goals is
> to make it easier to integrate analytics into applications. We don't
> want application developers to be concerned that if they update their
> UIMA version, suddently components that used to work will no longer
> work. Sometimes that means we're stuck with a suboptimal design for
> something, but that's life. If we *really* want to stop supporting
> this method, deprecate it first and then wait a few years for the 3.0
> release to come out, and think about doing it then. ;)
Right, but it depends on the likelyhood of breaking things - if we can
get it close enough to 0, maybe ...
>
> It seems the argument here is that there aren't very many multi-sofa
> annotators, so breaking them (the ones that use JCas anyway) is not
> that big a deal. I'm just not sure how to judge that.
>
> With that general comment out of the way, let me consider this
> specific issue. I think the code that would break is this:
>
> JCas someView = baseJCas.getView(name);
> MyAnnotation annot = new MyAnnotation(someView, begin, end);
> annot.addToIndexes();
>
We could make this code work: We could change the impl of getView(name)
to set the *current-view*. This isn't perfect. This breaks:
JCas someView_1 = baseJCas.getView(name1);
JCas someView_2 = baseJCas,getView(name2);
(new MyAnnotation(someView1)).addToIndexes(); // wrongly adds to view_2
(new MyAnnotation(someView2)).addToIndexes(); // adds to view_2
This could also be made to work; by setting the *current-view* when the
new operator is executed. Again, it isn't perfect..
But maybe we approach 0 breakage in practice :-) (or maybe not - hard
to tell...)
> But wait.. for types derived from annotations, we already know what
> view it should be indexed in. Just follow the annotation's Sofa
> reference and you will find the right view. It's not valid to index
> it in any other view, and in fact that results in an exception.
>
> So instead of indexing in the "current view" (which might fail), for
> annotations you could always index in the "correct view". :) This
> should not break any annotators.
>
Great idea - we should do perhaps in any case.
> That leaves non-annotation types (and only those with custom indexes
> defined for them matter). For those we could:
>
> (a) Decide we don't care about breaking this. At this point the
> number of affected annotators might be zero, but we can't be sure. I
> still don't like it on general principles.
>
> (b) Optimize what we can get away with. Only create extra _Type
> objects for non-annotation types for which custom indexes are defined.
> That has the downside of probably making the JCas code ugly and more
> prone to bugs.
>
> Next thought... what if instead of the separate _Type objects, you
> maintained in the JCasImpl a map from JCas object to "home view". As
> above you only need to do this for non-annotation objects that have
> indexes defined for them (AND if the home view is not the initial
> view, since that could be the default).
>
> That has different performance characteristics which may or may not
> necessarily be better (it depends on how many instances get created I
> think), but maybe it is a cleaner way to stay compatible.
Not sure I follow this... Let's see - you would have one generator set,
which iterators would use to generate a cover instance, for all the
different views, . If a cover instance already existed, you would need
to examine this map-to-home-view, and see if the home view was the right
one. If not, you would generate an additional cover instance. The
cache from key=CAS addr to value=cover-JCas-instance would need to map
to a collection of cover-JCas-instances, possibly one per view in which
it was indexed. Is this what you were thinking?
Other things to consider:
The (implicit) contract that co-located JCas things get the same
instance, so if the user added Java fields, they would be visible /
shared, breaks with the current design, but would be "fixed" with the
change to having only one JCas cover instance (and using *current-view*
as the implicit view to use with addToIndexes() etc.).
My feeling is with setting *current-view* on entry to user code being
passed a CAS, and on anything that returns a CAS (like getView(...)),
and fixing the subtypes of Annotation case, we cover enough of this
space to make breaking unlikely enough to make this worth doing, to
avoid breaking the (implicit) contract about use of JCas in co-located
components. We can document the workaround when you start having
annotators working with multiple views at the same time - to say users
should specify which view they want things indexed in (or things removed
from).
This change will potentially improve performance (space/time) also, for
multi-view applications using JCas, and impacts the design of the Class
Loader switching mechanism. Because we'd like to get that done this
month, I'd like to hear more comments about this, so we can decide
sooner rather than later which direction to go in...
>
> Hope that helped,
> -Adam
>
Yes, it did, thanks!
-Marshall
Re: changing the semantics (very slightly) for JCas objects with respect to Views
Posted by Adam Lally <al...@alum.rpi.edu>.
On 5/10/07, Marshall Schor <ms...@schor.com> wrote:
> While working on the class-loader switching code, we have revisited an
> issue with the way JCas objects work with respect to views.
>
> Currently, for each view, there is a separate set of xxx_Type objects, a
> separate set of "cached" cover objects (which are identical to other
> view's objects, except that their _Type ref points to the instance for
> this view).
>
> This is there only (as far as we can see) to support
> aJCasObject.addToIndexes() and removeFromIndexes() which uses this
> information to pick the right "view" to use (remember that indexes are
> held per view).
>
> Besides inefficiency (replication of objects per view), there is another
> side-effect. JCas Objects can, themselves, be extended by users to hold
> additional information, other than what's in the CAS. The current
> design would create new versions of these objects per view, so that
> iterators over different views would get different instances. So
> information set into one JCas object in one view would not be "visible"
> to instances obtained by iterating using a different view's index. This
> could be a documented "feature", or it could be a "bug".
>
> Because current users seem to often use the aJCasObject.addToIndexes()
> method, I want to retain that method, while getting the efficiencies and
> fixing the "bug" (if we consider it a bug) above. To do this, we could
> make this work as before *for sofa-unaware annotators, only* as
> follows: Change the impl of addToIndexes and removeFromIndexes to
> reference the "current-view".
>
It makes me very nervous to put in changes that intentionally break
compatibility with existing annotators. One of UIMA's main goals is
to make it easier to integrate analytics into applications. We don't
want application developers to be concerned that if they update their
UIMA version, suddently components that used to work will no longer
work. Sometimes that means we're stuck with a suboptimal design for
something, but that's life. If we *really* want to stop supporting
this method, deprecate it first and then wait a few years for the 3.0
release to come out, and think about doing it then. ;)
It seems the argument here is that there aren't very many multi-sofa
annotators, so breaking them (the ones that use JCas anyway) is not
that big a deal. I'm just not sure how to judge that.
With that general comment out of the way, let me consider this
specific issue. I think the code that would break is this:
JCas someView = baseJCas.getView(name);
MyAnnotation annot = new MyAnnotation(someView, begin, end);
annot.addToIndexes();
It would no longer add the annotation to someView. Instead it would
try to add it to the current view (which I think is the "initial view"
in this case).
But wait.. for types derived from annotations, we already know what
view it should be indexed in. Just follow the annotation's Sofa
reference and you will find the right view. It's not valid to index
it in any other view, and in fact that results in an exception.
So instead of indexing in the "current view" (which might fail), for
annotations you could always index in the "correct view". :) This
should not break any annotators.
That leaves non-annotation types (and only those with custom indexes
defined for them matter). For those we could:
(a) Decide we don't care about breaking this. At this point the
number of affected annotators might be zero, but we can't be sure. I
still don't like it on general principles.
(b) Optimize what we can get away with. Only create extra _Type
objects for non-annotation types for which custom indexes are defined.
That has the downside of probably making the JCas code ugly and more
prone to bugs.
Next thought... what if instead of the separate _Type objects, you
maintained in the JCasImpl a map from JCas object to "home view". As
above you only need to do this for non-annotation objects that have
indexes defined for them (AND if the home view is not the initial
view, since that could be the default).
That has different performance characteristics which may or may not
necessarily be better (it depends on how many instances get created I
think), but maybe it is a cleaner way to stay compatible.
Hope that helped,
-Adam
Re: changing the semantics (very slightly) for JCas objects with
respect to Views
Posted by Marshall Schor <ms...@schor.com>.
Marshall Schor wrote:
> While working on the class-loader switching code, we have revisited an
> issue with the way JCas objects work with respect to views.
>
> Currently, for each view, there is a separate set of xxx_Type objects,
> a separate set of "cached" cover objects (which are identical to other
> view's objects, except that their _Type ref points to the instance for
> this view).
>
> This is there only (as far as we can see) to support
> aJCasObject.addToIndexes() and removeFromIndexes() which uses this
> information to pick the right "view" to use (remember that indexes are
> held per view).
>
> Besides inefficiency (replication of objects per view), there is
> another side-effect. JCas Objects can, themselves, be extended by
> users to hold additional information, other than what's in the CAS.
> The current design would create new versions of these objects per
> view, so that iterators over different views would get different
> instances. So information set into one JCas object in one view would
> not be "visible" to instances obtained by iterating using a different
> view's index. This could be a documented "feature", or it could be a
> "bug".
>
> Because current users seem to often use the aJCasObject.addToIndexes()
> method, I want to retain that method, while getting the efficiencies
> and fixing the "bug" (if we consider it a bug) above. To do this, we
> could make this work as before *for sofa-unaware annotators, only* as
> follows: Change the impl of addToIndexes and removeFromIndexes to
> reference the "current-view".
> Where to get the current-view? First, it needs to be accessable in
> several contexts, including the main one (JCas use in an annotator),
> but also any other places JCas can be used - which includes
> (top-level) application code, call-back routines (which include a
> handle to a CAS), and code in flow controllers (which have access to
> a CAS). One way I can see to do this is to stick an object
> identifying the current-view onto thread-local. Any other
> suggestions appreciated....
I realized after thinking about it that we can get the current view from
the base CAS - we always have some CAS pointer in all these objects, and
we can get
to the base CAS, and there is a method getComponentInfo which could be
augmented to return the base CAS. This is probably better than using
thread-local.
-Marshall