See inline annotations.<br><br><div class="gmail_quote">On 13 August 2010 04:34, Manav <span dir="ltr">&lt;<a href="mailto:manav7574@yahoo.com">manav7574@yahoo.com</a>&gt;</span> wrote:<br><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
Thanks for your response Greg. As you said this is what i tried to fix the issue<br>
by creating a UserResult obj that has score as a property and inserting the same<br>
in working memory. I update the results in subsequent rules in the &quot;then&quot;<br>
clause. There are some issues that i faced in this as well :-<br>
<br>
-- In my last rule if i want to do a check on score property of  my result<br>
object in the &quot;when&quot; clause the score has not been updated .<br>
<br>
-- however if i do the same check in the &quot;then&quot; clause it seems to work<br>
properly.<br>
<br>
<br>
-- I tried to overcome by doing an update in one of my rules to check if that<br>
would work. That however went into an infinite loop.  So i used the<br>
&quot;lock-on-active true&quot; property . However it seemed to work well for only the<br>
first user object and doesn&#39;t work for other user objects that are loaded later.<br>
<br>
<br>
Below is the sample rule file . If the scenario is not clear pls do let me know<br>
and i will send across the different drls as attachments .<br>
<br>
<br>
<br>
salience 200<br>
when<br>
    User ($id : id)<br>
then<br>
    UserResult urslt = new UserResult ($id);<br>
    insert ($id)<br></blockquote><div><br>Here I&#39;d expect<br>       insert( urslt );<br><br>Also, to be on the safe side, I always add a pattern<br>       not( UserResult( id == $id ) )<br>to avoid the creation of multiple UserResult&#39;s for the same User (if there&#39;s a minimal chance it might be modified during the following fusillade).<br>
<br></div><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
end<br>
<br></blockquote><div>rule &quot;JapaneseScore&quot; <br></div><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
salience 100</blockquote><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">  <br></blockquote><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">

lock-on-active truewhen<br>
    $usr : User (language.keySet contains &quot;Japanese&quot;, $j_score :<br>
language[&quot;Japanese&quot;])<br></blockquote><div><br>I prefer to add a binding of User&#39;s id:  User( $id == id ) <br></div><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">

    $urslt :  UserResult (id == $<a href="http://usr.id" target="_blank">usr.id</a>)<br></blockquote><div>so I can simplify this. Add a constraint to avoid looping:<br><br>        $urslt : USerResult( id == $id, langScore.keySet not contains &quot;Japanese&quot; )<br>
 </div><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
then<br>
    $usrlt.setLangScore(&quot;Japanese&quot;, $j_score); <br></blockquote><div>        update( $usrlt );<br></div><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">

end<br></blockquote><div><br><br>rule &quot;FrenchScore&quot; <br></div><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
salience 50<br></blockquote><div>Why not 100?<br> <br></div><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
lock-on-active true </blockquote><div>not necessary now<br> </div><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">when<br>
    User (language.keySet contains &quot;French&quot;, $f_score : language[&quot;French&quot;])<br>
    $urslt :  UserResult (id == $<a href="http://usr.id" target="_blank">usr.id</a>)<br></blockquote><div>Same as before:<br> $urslt :  UserResult (id == $<a href="http://usr.id/" target="_blank">id</a>, langScore.keySet not contains &quot;French&quot; )<br>
<br></div><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
then<br>
    $usrlt.setLangScore(&quot;French&quot;, $_score); <br>
    update ($usrlt);<br>
end<br>
<br>
salience 25<br>
when<br>
    UserResult (score &gt; 4) // does not work<br>
then<br>
    // if ($usr_rslt.getScore() &gt; 4)  --&gt; works well<br>
    // update the db<br>
end<br>
<br>
Regards,<br>
Manav<br></blockquote><div><br><br>The repetition of rules JapanesScore and FrenchScore could be avoided by inserting static objects<br><br>insert( new Language( &quot;Japanese&quot; ) ); <br>insert( new Language( &quot;French&quot; ) ); <br>
// more of the same<br><br>rule &quot;PolyglottScore&quot; <br>salience 100<br>when<br><div>   Language( $name : name ) <br>   User ($id : id, language.keySet contains $name&quot;, $f_score : language[$name])<br>   $urslt :  UserResult (id == $<a href="http://usr.id/" target="_blank">id</a>, langScore.keySet not contains $name )<br>
</div>
then<br>    modify( $usrlt ){<br>
       setLangScore($name, $_score)<br>
    }<br>
end<br>
<br>HTH<br>--W<br><br> </div><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
<br>
<br>
----- Original Message ----<br>
From: Greg Barton &lt;<a href="mailto:greg_barton@yahoo.com">greg_barton@yahoo.com</a>&gt;<br>
To: Manav &lt;<a href="mailto:manav7574@yahoo.com">manav7574@yahoo.com</a>&gt;; Rules Users List &lt;<a href="mailto:rules-users@lists.jboss.org">rules-users@lists.jboss.org</a>&gt;<br>
Sent: Thu, August 12, 2010 9:29:28 PM<br>
Subject: Re: [rules-users] Caching results in temperory variables<br>
<br>
You must either update an existing working memory object or insert a new working<br>
memory object with the results.  That&#39;s how rules communicate with each other.<br>
<br>
GreG<br>
<br>
On Aug 12, 2010, at 10:31 AM, Manav &lt;<a href="mailto:manav7574@yahoo.com">manav7574@yahoo.com</a>&gt; wrote:<br>
<br>
Hi,<br>
<br>
I am using the version 5.x of drools and i have a scenario where i want to hold<br>
the result of<br>
<br>
a test in one rule to a temperory variable . This result will then be used in<br>
another rule that will be fired<br>
<br>
later in the sequence .<br>
<br>
For ex :<br>
<br>
salience 100<br>
when<br>
    User (language.keySet contains &quot;Japanese&quot;, $j_score : language[&quot;Japanese&quot;])<br>
then<br>
    // do something<br>
end<br>
<br>
salience 50<br>
when<br>
    User (language.keySet contains &quot;French&quot;, $f_score : language[&quot;French&quot;])<br>
then<br>
    // do something<br>
end<br>
<br>
salience 25<br>
when<br>
    eval (($j_score + $f_score) &gt; 4)<br>
then<br>
    // update the same to db<br>
end<br>
<br>
Is this possible in Drools 5.x ?<br>
<br>
Regards,<br>
<font color="#888888">Manav<br>
</font><div><div></div><div class="h5"><br>
<br>
<br>
<br>
_______________________________________________<br>
rules-users mailing list<br>
<a href="mailto:rules-users@lists.jboss.org">rules-users@lists.jboss.org</a><br>
<a href="https://lists.jboss.org/mailman/listinfo/rules-users" target="_blank">https://lists.jboss.org/mailman/listinfo/rules-users</a><br>
<br>
<br>
<br>
<br>
_______________________________________________<br>
rules-users mailing list<br>
<a href="mailto:rules-users@lists.jboss.org">rules-users@lists.jboss.org</a><br>
<a href="https://lists.jboss.org/mailman/listinfo/rules-users" target="_blank">https://lists.jboss.org/mailman/listinfo/rules-users</a><br>
</div></div></blockquote></div><br>