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 2010/09/03 21:28:37 UTC
handling of context saving in annotators
A recent "bug" in the Snowball annotator arose as follows:
1) It didn't implement the full annotator set of methods, but instead, depended
on the implementation skeleton done by a "base" implementation class.
2) That base implementation class included an implementation of reconfigure()
which is implemented as:
public void reconfigure() throws ResourceConfigurationException,
ResourceInitializationException {
destroy();
initialize(mContext);
}
where "mContext" is a field which might or might not be set (it isn't set by the
framework).
It is set by the base implementation class's implementation of the
"initialize(uimaContext)" method. If the user has their own initialize method,
and doesn't set this variable (which he would not normally be aware of) himself,
he can set it by calling "super.initialize(uimaContext)".
The bug that arose happened when the annotator writer didn't call
"super.initialize", and then the application writer (different people, different
roles) called "reconfigure", which the framework eventually passed down to the
annotator.
The user didn't implement this, but instead depended on the base implementation
class. This referenced the null value for mContext, which caused the error.
========
There are different kinds of things one could do here. One would be to add some
more notes to the manual(s) (I didn't check, the notes might actually already be
there, but we could in that case make them stand out more :-) ) saying that if
you use the base implementation classes as superclasses of your annotator
implementation, you *must* call super.initialize.
Another would be to add some support in the getContext() default method which
checks for null, and if found, issues a longer error message stating that the in
user's implementations of initialize which extend xyz base class, the user
*must* call super.initialize..., before calling getContext() or other framework
methods that call getContext() (such as getEmptyCAS - used in CAS multipliers),
or words to that effect.
Another thing that could be done is to have the framework examine the annotator
class before it calls its initialize method, to see if it is extending one of
the base impl classes which has this field and makes use of it in the
getContext() method, and if it finds that to be true, the framework could set
this field itself. This would eliminate the possible error from happening, but
maybe it's overkill for what is a simple thing for users to do.
========
Are there other approaches to this, and which kind of fix do you think we should
do for this?
-Marshall
P.S., the Snowball Annotator in our sandbox has been fixed
(https://issues.apache.org/jira/browse/UIMA-1861). The other annotators in our
sandbox and our examples haven't been "reviewed" as yet to see if they have this
issue.
Re: handling of context saving in annotators
Posted by Marshall Schor <ms...@schor.com>.
On 9/8/2010 10:40 AM, Adam Lally wrote:
> On Fri, Sep 3, 2010 at 3:28 PM, Marshall Schor <ms...@schor.com> wrote:
>
>> There are different kinds of things one could do here. One would be to add
>> some
>> more notes to the manual(s) (I didn't check, the notes might actually
>> already be
>> there, but we could in that case make them stand out more :-) ) saying that
>> if
>> you use the base implementation classes as superclasses of your annotator
>> implementation, you *must* call super.initialize.
>>
> Another would be to add some support in the getContext() default method
>> which
>> checks for null, and if found, issues a longer error message stating that
>> the in
>> user's implementations of initialize which extend xyz base class, the user
>> *must* call super.initialize..., before calling getContext() or other
>> framework
>> methods that call getContext() (such as getEmptyCAS - used in CAS
>> multipliers),
>> or words to that effect.
>>
>> I agree with doing the above - better documentation and error messages are
> always good.
>
>
>
>> Another thing that could be done is to have the framework examine the
>> annotator
>> class before it calls its initialize method, to see if it is extending one
>> of
>> the base impl classes which has this field and makes use of it in the
>> getContext() method, and if it finds that to be true, the framework could
>> set
>> this field itself. This would eliminate the possible error from happening,
>> but
>> maybe it's overkill for what is a simple thing for users to do.
>>
>>
> My thinking on this is that this adds additional complication that's not
> worth it. Currently we follow a straightfoward and often-used convention:
>
> * The annotator interface defines the API between framework and the user's
> component
> * The abstract base class provides default implementations of the methods,
> as a convenience
>
> Your suggestion breaks this convention, basically by having the abstract
> base class expose additional functionality (like a setContext() method) that
> the framework knows about and calls. In my experience things are not
> normally done that way, so developers may be confused by what is happening.
> It's kind of a "back door" way of accessing the annotator.
>
> I also do not think that calling super.initialize() is that unusual of a
> requirement when overriding a method.
>
> I admit that the current annotator interface is not ideal. If I had it to
> do over again, I would have the UimaContext be a parameter to the
> reconfigure method. But that is not really feasible at this point. IMO, the
> proposed patches for this problem all seem to have more downsides (in added
> complexity) than upsides.
>
> -Adam
>
Re: handling of context saving in annotators
Posted by Marshall Schor <ms...@schor.com>.
Sorry for the previous reply, pressed send before writing :-( ...
On 9/8/2010 10:40 AM, Adam Lally wrote:
> On Fri, Sep 3, 2010 at 3:28 PM, Marshall Schor <ms...@schor.com> wrote:
>
>> There are different kinds of things one could do here. One would be to add
>> some
>> more notes to the manual(s) (I didn't check, the notes might actually
>> already be
>> there, but we could in that case make them stand out more :-) ) saying that
>> if
>> you use the base implementation classes as superclasses of your annotator
>> implementation, you *must* call super.initialize.
>>
> Another would be to add some support in the getContext() default method
>> which
>> checks for null, and if found, issues a longer error message stating that
>> the in
>> user's implementations of initialize which extend xyz base class, the user
>> *must* call super.initialize..., before calling getContext() or other
>> framework
>> methods that call getContext() (such as getEmptyCAS - used in CAS
>> multipliers),
>> or words to that effect.
>>
>> I agree with doing the above - better documentation and error messages are
> always good.
>
>
>
>> Another thing that could be done is to have the framework examine the
>> annotator
>> class before it calls its initialize method, to see if it is extending one
>> of
>> the base impl classes which has this field and makes use of it in the
>> getContext() method, and if it finds that to be true, the framework could
>> set
>> this field itself. This would eliminate the possible error from happening,
>> but
>> maybe it's overkill for what is a simple thing for users to do.
>>
>>
> My thinking on this is that this adds additional complication that's not
> worth it. Currently we follow a straightfoward and often-used convention:
>
> * The annotator interface defines the API between framework and the user's
> component
> * The abstract base class provides default implementations of the methods,
> as a convenience
>
> Your suggestion breaks this convention, basically by having the abstract
> base class expose additional functionality (like a setContext() method) that
> the framework knows about and calls. In my experience things are not
> normally done that way, so developers may be confused by what is happening.
> It's kind of a "back door" way of accessing the annotator.
>
I agree it's kind of a back door, not normally done thing.
> I also do not think that calling super.initialize() is that unusual of a
> requirement when overriding a method.
We also would need to have any user who implements their own
setResultSpecification() implementation, call super.setResourceSpecification(...).
> I admit that the current annotator interface is not ideal. If I had it to
> do over again, I would have the UimaContext be a parameter to the
> reconfigure method. But that is not really feasible at this point. IMO, the
> proposed patches for this problem all seem to have more downsides (in added
> complexity) than upsides.
The added complexity seems completely hidden from the annotator writers unless
they are reading the source for the superclasses; we could name methods for
doing this something that indicates its a call that the framework uses, and is
not for user use (and also document in a javadoc about it). And these framework
helper methods could be marked "final" to prevent users from accidentally
overriding them.
Is the complexity you're concerned about something affects UIMA Framework
developers or do you believe it would affect the UIMA Annotator developers? My
sense is that most annotator developers don't read the super-class source code
at all; they just follow the quick-start instructions on the website, or the
tutorials, or someone else's skeleton implementation.
The documentation we have shows a call to super.initialize(...) in most
initialize(...) examples, but not always. And it doesn't say it's required,
although theoretically it's not required if you don't extend from the provided,
built-in base classes.
The sandbox has several examples where the writer forgot or didn't know they
needed to call super.initialize(...). We can of course fix those.
The javadocs for the initialize() interface/methods and the
setResultSpecification methods that are user-code overridable I think should
mention that other parts of the framework-supplied code depend on these being
called, so any overriding method should call the super.
I guess for me it's a trade off of writing more documentation that we hope users
read and follow, vs. having framework code (that uses a "back-door" approach)
that just makes things work (in the vast majority of actual use cases).
-Marshall
> -Adam
>
Re: handling of context saving in annotators
Posted by Adam Lally <al...@alum.rpi.edu>.
On Fri, Sep 3, 2010 at 3:28 PM, Marshall Schor <ms...@schor.com> wrote:
> There are different kinds of things one could do here. One would be to add
> some
> more notes to the manual(s) (I didn't check, the notes might actually
> already be
> there, but we could in that case make them stand out more :-) ) saying that
> if
> you use the base implementation classes as superclasses of your annotator
> implementation, you *must* call super.initialize.
>
Another would be to add some support in the getContext() default method
> which
> checks for null, and if found, issues a longer error message stating that
> the in
> user's implementations of initialize which extend xyz base class, the user
> *must* call super.initialize..., before calling getContext() or other
> framework
> methods that call getContext() (such as getEmptyCAS - used in CAS
> multipliers),
> or words to that effect.
>
> I agree with doing the above - better documentation and error messages are
always good.
> Another thing that could be done is to have the framework examine the
> annotator
> class before it calls its initialize method, to see if it is extending one
> of
> the base impl classes which has this field and makes use of it in the
> getContext() method, and if it finds that to be true, the framework could
> set
> this field itself. This would eliminate the possible error from happening,
> but
> maybe it's overkill for what is a simple thing for users to do.
>
>
My thinking on this is that this adds additional complication that's not
worth it. Currently we follow a straightfoward and often-used convention:
* The annotator interface defines the API between framework and the user's
component
* The abstract base class provides default implementations of the methods,
as a convenience
Your suggestion breaks this convention, basically by having the abstract
base class expose additional functionality (like a setContext() method) that
the framework knows about and calls. In my experience things are not
normally done that way, so developers may be confused by what is happening.
It's kind of a "back door" way of accessing the annotator.
I also do not think that calling super.initialize() is that unusual of a
requirement when overriding a method.
I admit that the current annotator interface is not ideal. If I had it to
do over again, I would have the UimaContext be a parameter to the
reconfigure method. But that is not really feasible at this point. IMO, the
proposed patches for this problem all seem to have more downsides (in added
complexity) than upsides.
-Adam
Re: handling of context saving in annotators
Posted by Marshall Schor <ms...@schor.com>.
On 9/6/2010 4:04 AM, Tommaso Teofili wrote:
> Hi all,
> I had a look at:
> http://uima.apache.org/doc-uima-annotator.html
> and the initialize() method does not appear to be overridden so the
> super.initialize() call is not mentioned.
>
> If we go for the option of better documenting the super.initialize() need,
> maybe a good choice would be to put it here :
> http://uima.apache.org/downloads/releaseDocs/2.3.0-incubating/docs/html/tutorials_and_users_guides/tutorials_and_users_guides.html#ugr.tug.aae.developing_annotator_code
>
> or here:
> http://uima.apache.org/downloads/releaseDocs/2.3.0-incubating/docs/html/tutorials_and_users_guides/tutorials_and_users_guides.html#ugr.tug.aae.accessing_parameter_values_from_annotator
>
> Despite this, my opinion is that having not to write the
> "super.initialize();" inside a method overriding initialize() would be much
> better.
I agree, because then we can avoid the error, rather than report it to the user
who may then need to contact the annotator writer (maybe a different person) and
have them correct their code.
I always like to avoid errors rather than report them, where feasible.
Also, I realize that there is another field that could cause similar problems
for annotator writers - the one that holds the result specification, and is
returned by the default implementation of getResultSpecification().
Our examples (e.g., the PersonTitleAnnotator) use this method. If an annotator
write was to include his own setResultSpecification method, and neglect to call
the super for that, and then use the getResultSpecification() method, it would
return null.
So, both of these could be set by the framework, if the framework determines the
analysis component is extending one of the default super classes, and thus,
avoid these errors.
-Marshall
> I will take a look at other sandbox annotators and check for the
> super.initialize() issue.
Thanks.
> Regards,
> Tommaso
>
>
>
>
> 2010/9/3 Marshall Schor <ms...@schor.com>
>
>> A recent "bug" in the Snowball annotator arose as follows:
>>
>> 1) It didn't implement the full annotator set of methods, but instead,
>> depended
>> on the implementation skeleton done by a "base" implementation class.
>> 2) That base implementation class included an implementation of
>> reconfigure()
>> which is implemented as:
>>
>> public void reconfigure() throws ResourceConfigurationException,
>> ResourceInitializationException {
>> destroy();
>> initialize(mContext);
>> }
>>
>> where "mContext" is a field which might or might not be set (it isn't set
>> by the
>> framework).
>>
>> It is set by the base implementation class's implementation of the
>> "initialize(uimaContext)" method. If the user has their own initialize
>> method,
>> and doesn't set this variable (which he would not normally be aware of)
>> himself,
>> he can set it by calling "super.initialize(uimaContext)".
>>
>> The bug that arose happened when the annotator writer didn't call
>> "super.initialize", and then the application writer (different people,
>> different
>> roles) called "reconfigure", which the framework eventually passed down to
>> the
>> annotator.
>>
>> The user didn't implement this, but instead depended on the base
>> implementation
>> class. This referenced the null value for mContext, which caused the
>> error.
>>
>> ========
>>
>> There are different kinds of things one could do here. One would be to add
>> some
>> more notes to the manual(s) (I didn't check, the notes might actually
>> already be
>> there, but we could in that case make them stand out more :-) ) saying that
>> if
>> you use the base implementation classes as superclasses of your annotator
>> implementation, you *must* call super.initialize.
>>
>> Another would be to add some support in the getContext() default method
>> which
>> checks for null, and if found, issues a longer error message stating that
>> the in
>> user's implementations of initialize which extend xyz base class, the user
>> *must* call super.initialize..., before calling getContext() or other
>> framework
>> methods that call getContext() (such as getEmptyCAS - used in CAS
>> multipliers),
>> or words to that effect.
>>
>> Another thing that could be done is to have the framework examine the
>> annotator
>> class before it calls its initialize method, to see if it is extending one
>> of
>> the base impl classes which has this field and makes use of it in the
>> getContext() method, and if it finds that to be true, the framework could
>> set
>> this field itself. This would eliminate the possible error from happening,
>> but
>> maybe it's overkill for what is a simple thing for users to do.
>>
>> ========
>>
>> Are there other approaches to this, and which kind of fix do you think we
>> should
>> do for this?
>>
>> -Marshall
>>
>> P.S., the Snowball Annotator in our sandbox has been fixed
>> (https://issues.apache.org/jira/browse/UIMA-1861). The other annotators
>> in our
>> sandbox and our examples haven't been "reviewed" as yet to see if they have
>> this
>> issue.
>>
Re: handling of context saving in annotators
Posted by Tommaso Teofili <to...@gmail.com>.
Hi all,
I had a look at:
http://uima.apache.org/doc-uima-annotator.html
and the initialize() method does not appear to be overridden so the
super.initialize() call is not mentioned.
If we go for the option of better documenting the super.initialize() need,
maybe a good choice would be to put it here :
http://uima.apache.org/downloads/releaseDocs/2.3.0-incubating/docs/html/tutorials_and_users_guides/tutorials_and_users_guides.html#ugr.tug.aae.developing_annotator_code
or here:
http://uima.apache.org/downloads/releaseDocs/2.3.0-incubating/docs/html/tutorials_and_users_guides/tutorials_and_users_guides.html#ugr.tug.aae.accessing_parameter_values_from_annotator
Despite this, my opinion is that having not to write the
"super.initialize();" inside a method overriding initialize() would be much
better.
I will take a look at other sandbox annotators and check for the
super.initialize() issue.
Regards,
Tommaso
2010/9/3 Marshall Schor <ms...@schor.com>
> A recent "bug" in the Snowball annotator arose as follows:
>
> 1) It didn't implement the full annotator set of methods, but instead,
> depended
> on the implementation skeleton done by a "base" implementation class.
> 2) That base implementation class included an implementation of
> reconfigure()
> which is implemented as:
>
> public void reconfigure() throws ResourceConfigurationException,
> ResourceInitializationException {
> destroy();
> initialize(mContext);
> }
>
> where "mContext" is a field which might or might not be set (it isn't set
> by the
> framework).
>
> It is set by the base implementation class's implementation of the
> "initialize(uimaContext)" method. If the user has their own initialize
> method,
> and doesn't set this variable (which he would not normally be aware of)
> himself,
> he can set it by calling "super.initialize(uimaContext)".
>
> The bug that arose happened when the annotator writer didn't call
> "super.initialize", and then the application writer (different people,
> different
> roles) called "reconfigure", which the framework eventually passed down to
> the
> annotator.
>
> The user didn't implement this, but instead depended on the base
> implementation
> class. This referenced the null value for mContext, which caused the
> error.
>
> ========
>
> There are different kinds of things one could do here. One would be to add
> some
> more notes to the manual(s) (I didn't check, the notes might actually
> already be
> there, but we could in that case make them stand out more :-) ) saying that
> if
> you use the base implementation classes as superclasses of your annotator
> implementation, you *must* call super.initialize.
>
> Another would be to add some support in the getContext() default method
> which
> checks for null, and if found, issues a longer error message stating that
> the in
> user's implementations of initialize which extend xyz base class, the user
> *must* call super.initialize..., before calling getContext() or other
> framework
> methods that call getContext() (such as getEmptyCAS - used in CAS
> multipliers),
> or words to that effect.
>
> Another thing that could be done is to have the framework examine the
> annotator
> class before it calls its initialize method, to see if it is extending one
> of
> the base impl classes which has this field and makes use of it in the
> getContext() method, and if it finds that to be true, the framework could
> set
> this field itself. This would eliminate the possible error from happening,
> but
> maybe it's overkill for what is a simple thing for users to do.
>
> ========
>
> Are there other approaches to this, and which kind of fix do you think we
> should
> do for this?
>
> -Marshall
>
> P.S., the Snowball Annotator in our sandbox has been fixed
> (https://issues.apache.org/jira/browse/UIMA-1861). The other annotators
> in our
> sandbox and our examples haven't been "reviewed" as yet to see if they have
> this
> issue.
>
Re: handling of context saving in annotators
Posted by Marshall Schor <ms...@schor.com>.
I created https://issues.apache.org/jira/browse/UIMA-1874.
I'm adopting the approach of keeping the "requirement" that users call
super.initialize() if they use the standard base classes. Note that they don't
*have* to use these base classes...
-Marshall
On 9/3/2010 3:28 PM, Marshall Schor wrote:
> A recent "bug" in the Snowball annotator arose as follows:
>
> 1) It didn't implement the full annotator set of methods, but instead, depended
> on the implementation skeleton done by a "base" implementation class.
> 2) That base implementation class included an implementation of reconfigure()
> which is implemented as:
>
> public void reconfigure() throws ResourceConfigurationException,
> ResourceInitializationException {
> destroy();
> initialize(mContext);
> }
>
> where "mContext" is a field which might or might not be set (it isn't set by the
> framework).
>
> It is set by the base implementation class's implementation of the
> "initialize(uimaContext)" method. If the user has their own initialize method,
> and doesn't set this variable (which he would not normally be aware of) himself,
> he can set it by calling "super.initialize(uimaContext)".
>
> The bug that arose happened when the annotator writer didn't call
> "super.initialize", and then the application writer (different people, different
> roles) called "reconfigure", which the framework eventually passed down to the
> annotator.
>
> The user didn't implement this, but instead depended on the base implementation
> class. This referenced the null value for mContext, which caused the error.
>
> ========
>
> There are different kinds of things one could do here. One would be to add some
> more notes to the manual(s) (I didn't check, the notes might actually already be
> there, but we could in that case make them stand out more :-) ) saying that if
> you use the base implementation classes as superclasses of your annotator
> implementation, you *must* call super.initialize.
>
> Another would be to add some support in the getContext() default method which
> checks for null, and if found, issues a longer error message stating that the in
> user's implementations of initialize which extend xyz base class, the user
> *must* call super.initialize..., before calling getContext() or other framework
> methods that call getContext() (such as getEmptyCAS - used in CAS multipliers),
> or words to that effect.
>
> Another thing that could be done is to have the framework examine the annotator
> class before it calls its initialize method, to see if it is extending one of
> the base impl classes which has this field and makes use of it in the
> getContext() method, and if it finds that to be true, the framework could set
> this field itself. This would eliminate the possible error from happening, but
> maybe it's overkill for what is a simple thing for users to do.
>
> ========
>
> Are there other approaches to this, and which kind of fix do you think we should
> do for this?
>
> -Marshall
>
> P.S., the Snowball Annotator in our sandbox has been fixed
> (https://issues.apache.org/jira/browse/UIMA-1861). The other annotators in our
> sandbox and our examples haven't been "reviewed" as yet to see if they have this
> issue.
>
>