You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@uima.apache.org by Wolf-Dietrich Materna <wo...@empolis.com> on 2017/05/09 06:08:28 UTC

Variables in Ruta scripts are not initialized properly by RutaEngine if their script is called by others

Hello,
Variables in Ruta scripts are not initialized properly by RutaEngine if their
script is called by others.

We found this issue in Ruta 2.3.1, but it's still in Ruta 2.6.0.
I attached the sample project TestVariable.zip to this mail.

Example: script3.ruta
----
DECLARE Value(STRING value);
STRING value;
W{-> CREATE(Value, "value" = value), ASSIGN(value, W.ct)};
----
Creates an annotation "Value" with an empty feature "value".
The variable "value" stores the word (and is evaluated by other rules - the real use case doesn't matters here).

Input testfiles:
input-01.txt: snark
input-02.txt: cat

Output after running Ruta with script3.ruta:
input-01.txt.xmi: Value annotation for "snark" with an empty value (nil)
input-02.txt.xmi: Value annotation for "cat" with an empty value (nil)
=> works as expected.

We added two scripts to call finally script3.ruta in the order
  script1 calls script2 => script2 calls script3 => scripts3
to creates Value annotation.
(our real project is complex - uses packages ...)

Now we call script1.ruta on the same input, but the output annotation Value
contains a wrong value feature for all documents after the first.
input-01.txt.xmi: Value annotation for "snark" with an empty value (nil)
input-02.txt.xmi: Value annotation  "cat" with value feature "snark" (instead
of nil as before).
It seems the variable is not initialized properly if it is defined in a sub-script, which is called by other scripts.

It doesn't help to initialized the variable in script3, e.g:
STRING value = "dog"
----
The output is unchanged the Value annotation return the stored variable,
which was set by script3.ruta while processing the first input file.

One of my colleguage examined the issue and proposed to patch RutaEngine class to solve this issue.
We added the following lines to:
private void resetEnvironment(RutaModule module, CAS cas):
---
641a642,646
>     final Collection<RutaModule> scripts = module.getScripts().values();
>     for (final RutaModule subModule : scripts) {
>       resetEnvironment(subModule, cas);
>     }
---

This solves the issue in our applications which integrates Ruta.
Known workaround: clear or initialize the variables at the end of the script.
But I prefer if the issue is fixed in the RutaEngine class.

Regards,
Wolf-Dietrich Materna


Re: Variables in Ruta scripts are not initialized properly by RutaEngine if their script is called by others

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


either an NPE is throw or you get a string with starting with "null".

I think we keep it as it is now.


Best,


Peter




Am 11.05.2017 um 16:33 schrieb Wolf-Dietrich Materna:
> @Peter: Thank you for creating and fixing UIMA-5423.
> If we switch to null as default value: what happens if we use the variable without explicit initialization?
> Example:
> STRING name, fullname;
> Name {-> MATCHEDTEXT(name, 1),
> 	ASSIGN(fullname, fullname  + " " + name), // append string and space to "fullname" without initialization.
> 	...}
> In general using fullname without initialization can be considered as bad style. But I'm afraid, that many users writes similar code.
>   Wolf
>
> -----Ursprüngliche Nachricht-----
> Von: Peter Klügl [mailto:peter.kluegl@averbis.com] 
> Gesendet: Mittwoch, 10. Mai 2017 11:10
> An: dev@uima.apache.org
> Betreff: Re: Variables in Ruta scripts are not initialized properly by RutaEngine if their script is called by others
>
> btw, the intial value "" (empty string) of string variables has historical reasons. Maybe we should switch it to null?
>
>
> Peter
>
>
> Am 09.05.2017 um 09:03 schrieb Peter Klügl:
>> Hi,
>>
>>
>> thanks. I've taken the liberty of creating a jira issue for this. I 
>> will fix it soon.
>>
>>
>> Best,
>>
>>
>> Peter
>>


AW: Variables in Ruta scripts are not initialized properly by RutaEngine if their script is called by others

Posted by Wolf-Dietrich Materna <wo...@empolis.com>.
@Peter: Thank you for creating and fixing UIMA-5423.
If we switch to null as default value: what happens if we use the variable without explicit initialization?
Example:
STRING name, fullname;
Name {-> MATCHEDTEXT(name, 1),
	ASSIGN(fullname, fullname  + " " + name), // append string and space to "fullname" without initialization.
	...}
In general using fullname without initialization can be considered as bad style. But I'm afraid, that many users writes similar code.
  Wolf

-----Ursprüngliche Nachricht-----
Von: Peter Klügl [mailto:peter.kluegl@averbis.com] 
Gesendet: Mittwoch, 10. Mai 2017 11:10
An: dev@uima.apache.org
Betreff: Re: Variables in Ruta scripts are not initialized properly by RutaEngine if their script is called by others

btw, the intial value "" (empty string) of string variables has historical reasons. Maybe we should switch it to null?


Peter


Am 09.05.2017 um 09:03 schrieb Peter Klügl:
> Hi,
>
>
> thanks. I've taken the liberty of creating a jira issue for this. I 
> will fix it soon.
>
>
> Best,
>
>
> Peter
>

Re: Variables in Ruta scripts are not initialized properly by RutaEngine if their script is called by others

Posted by Peter Klügl <pe...@averbis.com>.
btw, the intial value "" (empty string) of string variables has
historical reasons. Maybe we should switch it to null?


Peter


Am 09.05.2017 um 09:03 schrieb Peter Klügl:
> Hi,
>
>
> thanks. I've taken the liberty of creating a jira issue for this. I will
> fix it soon.
>
>
> Best,
>
>
> Peter
>
>
> Am 09.05.2017 um 08:08 schrieb Wolf-Dietrich Materna:
>> Hello,
>>
>> Variables in Ruta scripts are not initialized properly by RutaEngine
>> if their
>>
>> script is called by others.
>>
>>  
>>
>> We found this issue in Ruta 2.3.1, but it’s still in Ruta 2.6.0.
>>
>> I attached the sample project TestVariable.zip to this mail.
>>
>>  
>>
>> Example: script3.ruta
>>
>> ----
>>
>> DECLARE Value(STRING value);
>>
>> STRING value;
>>
>> W{-> CREATE(Value, "value" = value), ASSIGN(value, W.ct)};
>>
>> ----
>>
>> Creates an annotation "Value" with an empty feature "value".
>>
>> The variable "value" stores the word (and is evaluated by other rules
>> – the real use case doesn't matters here).
>>
>>  
>>
>> Input testfiles:
>>
>> input-01.txt: snark
>>
>> input-02.txt: cat
>>
>>  
>>
>> Output after running Ruta with script3.ruta:
>>
>> input-01.txt.xmi: Value annotation for "snark" with an empty value (nil)
>>
>> input-02.txt.xmi: Value annotation for "cat" with an empty value (nil)
>>
>> => works as expected.
>>
>>  
>>
>> We added two scripts to call finally script3.ruta in the order
>>
>>   script1 calls script2 => script2 calls script3 => scripts3
>>
>> to creates Value annotation.
>>
>> (our real project is complex - uses packages ...)
>>
>>  
>>
>> Now we call script1.ruta on the same input, but the output annotation
>> Value
>>
>> contains a wrong value feature for all documents after the first.
>>
>> input-01.txt.xmi: Value annotation for "snark" with an empty value (nil)
>>
>> input-02.txt.xmi: Value annotation  "cat" with value feature "snark"
>> (instead
>>
>> of nil as before).
>>
>> It seems the variable is not initialized properly if it is defined in
>> a sub-script, which is called by other scripts.
>>
>>  
>>
>> It doesn't help to initialized the variable in script3, e.g:
>>
>> STRING value = "dog"
>>
>> ----
>>
>> The output is unchanged the Value annotation return the stored variable,
>>
>> which was set by script3.ruta while processing the first input file.
>>
>>  
>>
>> One of my colleguage examined the issue and proposed to patch
>> RutaEngine class to solve this issue.
>>
>> We added the following lines to:
>>
>> private void resetEnvironment(RutaModule module, CAS cas):
>>
>> ---
>>
>> 641a642,646
>>
>>>     final Collection<RutaModule> scripts = module.getScripts().values();
>>>     for (final RutaModule subModule : scripts) {
>>>       resetEnvironment(subModule, cas);
>>>     }
>> ---
>>
>>  
>>
>> This solves the issue in our applications which integrates Ruta.
>>
>> Known workaround: clear or initialize the variables at the end of the
>> script.
>>
>> But I prefer if the issue is fixed in the RutaEngine class.
>>
>>  
>>
>> Regards,
>>
>> Wolf-Dietrich Materna
>>
>>  
>>
>


Re: Variables in Ruta scripts are not initialized properly by RutaEngine if their script is called by others

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


it's fixed in the current trunk.


Thanks aghain for reporting this.


Best,


Peter


Am 09.05.2017 um 09:03 schrieb Peter Klügl:
> Hi,
>
>
> thanks. I've taken the liberty of creating a jira issue for this. I will
> fix it soon.
>
>
> Best,
>
>
> Peter
>
>
> Am 09.05.2017 um 08:08 schrieb Wolf-Dietrich Materna:
>> Hello,
>>
>> Variables in Ruta scripts are not initialized properly by RutaEngine
>> if their
>>
>> script is called by others.
>>
>>  
>>
>> We found this issue in Ruta 2.3.1, but it’s still in Ruta 2.6.0.
>>
>> I attached the sample project TestVariable.zip to this mail.
>>
>>  
>>
>> Example: script3.ruta
>>
>> ----
>>
>> DECLARE Value(STRING value);
>>
>> STRING value;
>>
>> W{-> CREATE(Value, "value" = value), ASSIGN(value, W.ct)};
>>
>> ----
>>
>> Creates an annotation "Value" with an empty feature "value".
>>
>> The variable "value" stores the word (and is evaluated by other rules
>> – the real use case doesn't matters here).
>>
>>  
>>
>> Input testfiles:
>>
>> input-01.txt: snark
>>
>> input-02.txt: cat
>>
>>  
>>
>> Output after running Ruta with script3.ruta:
>>
>> input-01.txt.xmi: Value annotation for "snark" with an empty value (nil)
>>
>> input-02.txt.xmi: Value annotation for "cat" with an empty value (nil)
>>
>> => works as expected.
>>
>>  
>>
>> We added two scripts to call finally script3.ruta in the order
>>
>>   script1 calls script2 => script2 calls script3 => scripts3
>>
>> to creates Value annotation.
>>
>> (our real project is complex - uses packages ...)
>>
>>  
>>
>> Now we call script1.ruta on the same input, but the output annotation
>> Value
>>
>> contains a wrong value feature for all documents after the first.
>>
>> input-01.txt.xmi: Value annotation for "snark" with an empty value (nil)
>>
>> input-02.txt.xmi: Value annotation  "cat" with value feature "snark"
>> (instead
>>
>> of nil as before).
>>
>> It seems the variable is not initialized properly if it is defined in
>> a sub-script, which is called by other scripts.
>>
>>  
>>
>> It doesn't help to initialized the variable in script3, e.g:
>>
>> STRING value = "dog"
>>
>> ----
>>
>> The output is unchanged the Value annotation return the stored variable,
>>
>> which was set by script3.ruta while processing the first input file.
>>
>>  
>>
>> One of my colleguage examined the issue and proposed to patch
>> RutaEngine class to solve this issue.
>>
>> We added the following lines to:
>>
>> private void resetEnvironment(RutaModule module, CAS cas):
>>
>> ---
>>
>> 641a642,646
>>
>>>     final Collection<RutaModule> scripts = module.getScripts().values();
>>>     for (final RutaModule subModule : scripts) {
>>>       resetEnvironment(subModule, cas);
>>>     }
>> ---
>>
>>  
>>
>> This solves the issue in our applications which integrates Ruta.
>>
>> Known workaround: clear or initialize the variables at the end of the
>> script.
>>
>> But I prefer if the issue is fixed in the RutaEngine class.
>>
>>  
>>
>> Regards,
>>
>> Wolf-Dietrich Materna
>>
>>  
>>
>


Re: Variables in Ruta scripts are not initialized properly by RutaEngine if their script is called by others

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


thanks. I've taken the liberty of creating a jira issue for this. I will
fix it soon.


Best,


Peter


Am 09.05.2017 um 08:08 schrieb Wolf-Dietrich Materna:
>
> Hello,
>
> Variables in Ruta scripts are not initialized properly by RutaEngine
> if their
>
> script is called by others.
>
>  
>
> We found this issue in Ruta 2.3.1, but it’s still in Ruta 2.6.0.
>
> I attached the sample project TestVariable.zip to this mail.
>
>  
>
> Example: script3.ruta
>
> ----
>
> DECLARE Value(STRING value);
>
> STRING value;
>
> W{-> CREATE(Value, "value" = value), ASSIGN(value, W.ct)};
>
> ----
>
> Creates an annotation "Value" with an empty feature "value".
>
> The variable "value" stores the word (and is evaluated by other rules
> – the real use case doesn't matters here).
>
>  
>
> Input testfiles:
>
> input-01.txt: snark
>
> input-02.txt: cat
>
>  
>
> Output after running Ruta with script3.ruta:
>
> input-01.txt.xmi: Value annotation for "snark" with an empty value (nil)
>
> input-02.txt.xmi: Value annotation for "cat" with an empty value (nil)
>
> => works as expected.
>
>  
>
> We added two scripts to call finally script3.ruta in the order
>
>   script1 calls script2 => script2 calls script3 => scripts3
>
> to creates Value annotation.
>
> (our real project is complex - uses packages ...)
>
>  
>
> Now we call script1.ruta on the same input, but the output annotation
> Value
>
> contains a wrong value feature for all documents after the first.
>
> input-01.txt.xmi: Value annotation for "snark" with an empty value (nil)
>
> input-02.txt.xmi: Value annotation  "cat" with value feature "snark"
> (instead
>
> of nil as before).
>
> It seems the variable is not initialized properly if it is defined in
> a sub-script, which is called by other scripts.
>
>  
>
> It doesn't help to initialized the variable in script3, e.g:
>
> STRING value = "dog"
>
> ----
>
> The output is unchanged the Value annotation return the stored variable,
>
> which was set by script3.ruta while processing the first input file.
>
>  
>
> One of my colleguage examined the issue and proposed to patch
> RutaEngine class to solve this issue.
>
> We added the following lines to:
>
> private void resetEnvironment(RutaModule module, CAS cas):
>
> ---
>
> 641a642,646
>
> >     final Collection<RutaModule> scripts = module.getScripts().values();
>
> >     for (final RutaModule subModule : scripts) {
>
> >       resetEnvironment(subModule, cas);
>
> >     }
>
> ---
>
>  
>
> This solves the issue in our applications which integrates Ruta.
>
> Known workaround: clear or initialize the variables at the end of the
> script.
>
> But I prefer if the issue is fixed in the RutaEngine class.
>
>  
>
> Regards,
>
> Wolf-Dietrich Materna
>
>  
>