See inline annotations.<br><br><div class="gmail_quote">On 13 August 2010 04:34, Manav <span dir="ltr"><<a href="mailto:manav7574@yahoo.com">manav7574@yahoo.com</a>></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 "then"<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 "when" clause the score has not been updated .<br>
<br>
-- however if i do the same check in the "then" 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>
"lock-on-active true" property . However it seemed to work well for only the<br>
first user object and doesn'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'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's for the same User (if there'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 "JapaneseScore" <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 "Japanese", $j_score :<br>
language["Japanese"])<br></blockquote><div><br>I prefer to add a binding of User'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 "Japanese" )<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("Japanese", $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 "FrenchScore" <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 "French", $f_score : language["French"])<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 "French" )<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("French", $_score); <br>
update ($usrlt);<br>
end<br>
<br>
salience 25<br>
when<br>
UserResult (score > 4) // does not work<br>
then<br>
// if ($usr_rslt.getScore() > 4) --> 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( "Japanese" ) ); <br>insert( new Language( "French" ) ); <br>
// more of the same<br><br>rule "PolyglottScore" <br>salience 100<br>when<br><div> Language( $name : name ) <br> User ($id : id, language.keySet contains $name", $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 <<a href="mailto:greg_barton@yahoo.com">greg_barton@yahoo.com</a>><br>
To: Manav <<a href="mailto:manav7574@yahoo.com">manav7574@yahoo.com</a>>; Rules Users List <<a href="mailto:rules-users@lists.jboss.org">rules-users@lists.jboss.org</a>><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's how rules communicate with each other.<br>
<br>
GreG<br>
<br>
On Aug 12, 2010, at 10:31 AM, Manav <<a href="mailto:manav7574@yahoo.com">manav7574@yahoo.com</a>> 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 "Japanese", $j_score : language["Japanese"])<br>
then<br>
// do something<br>
end<br>
<br>
salience 50<br>
when<br>
User (language.keySet contains "French", $f_score : language["French"])<br>
then<br>
// do something<br>
end<br>
<br>
salience 25<br>
when<br>
eval (($j_score + $f_score) > 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>