You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@uima.apache.org by Reza Hay <re...@gmail.com> on 2017/06/14 12:34:05 UTC

Global variables containing types become null after their assignment scope.

Hi All,

It seems if a global variable does contain a type instead of a primitive value, its scope is limited to the current statement. Example:
STRING s;
TYPE rootGovernor;
(DEP_ROOT & VERB) {-> rootGovernor = DEP_ROOT.Governor, LOG("root: " + rootGovernor.ct)};
ANY{->LOG("root: " + rootGovernor.ct)};

The first statement prints the correct answer but the second statement prints null. However, in 
(DEP_ROOT & VERB) {-> s = DEP_ROOT.Governor.ct};
ANY{->LOG("root: " + s)};

the variable s has still its value and the second statement prints the expected value. Any idea?

Regards,
Reza



Re: Global variables containing types become null after their assignment scope.

Posted by Peter Klügl <pe...@averbis.com>.
Hi,


the difference is how the value of the variable is used. A type 
expression does not have a covered text, so the type is just some 
something that point to some annotation(s) in a local context. In the 
first example, the "rootGovernor" type variables is resolved against one 
annotation using different "lookup" strategies, e.g., first it looks for 
annotations of the given type with the same offsets as the matches rule 
element. It tries to guess which annotation you meant. So it all depends 
on the value of the variable. Without testing and looking at the code, 
I'd assume that the assignment is on the type of the feature value of 
the last DEP_ROOT annotation in the document. And only if the expression 
is correctly resolved as an AnnotationTypeExpression. It's hard to test 
it without an specific input example.

In the second example, nothing is resolved against the matched 
annotation, but only the value of the variable is logged. The value is 
determined by the last match of the previous rule.

Try to declare "rootGovernor" as ANNOTATION instead of TYPE to see the 
difference.


Best,


Peter


Am 14.06.2017 um 14:34 schrieb Reza Hay:
> Hi All,
>
> It seems if a global variable does contain a type instead of a primitive value, its scope is limited to the current statement. Example:
> STRING s;
> TYPE rootGovernor;
> (DEP_ROOT & VERB) {-> rootGovernor = DEP_ROOT.Governor, LOG("root: " + rootGovernor.ct)};
> ANY{->LOG("root: " + rootGovernor.ct)};
>
> The first statement prints the correct answer but the second statement prints null. However, in
> (DEP_ROOT & VERB) {-> s = DEP_ROOT.Governor.ct};
> ANY{->LOG("root: " + s)};
>
> the variable s has still its value and the second statement prints the expected value. Any idea?
>
> Regards,
> Reza
>
>