<html><head><style type="text/css"><!-- DIV {margin:0px;} --></style></head><body><div style="font-family:times new roman, new york, times, serif;font-size:12pt"><DIV>Your explanation is absolutely superb.&nbsp; I modified my drl as per your suggestions and it's just been completely transformed. Just one question regarding one suggestion below :</DIV>
<DIV>&nbsp;</DIV>
<DIV>-- is this something like a for each loop in java . This is the first example i have seen in&nbsp;drl </DIV>
<DIV>-- will this automatically iterate over as many languages as have been inserted ? </DIV>
<DIV>-- the inserts .. don't they have to be within a rule block ? or did you just omit other things to keep it simple<BR></DIV>
<DIV style="FONT-SIZE: 12pt; FONT-FAMILY: times new roman, new york, times, serif">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>&nbsp;&nbsp; Language( $name : name ) <BR>&nbsp;&nbsp; User ($id : id, language.keySet contains $name", $f_score : language[$name])<BR>&nbsp;&nbsp; $urslt :&nbsp; UserResult (id == $<A href="http://usr.id/" target=_blank rel=nofollow><FONT color=#0000ff>id</FONT></A>, langScore.keySet not contains $name )<BR></DIV>then<BR>&nbsp;&nbsp;&nbsp; modify( $usrlt ){<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; setLangScore($name, $_score)<BR>&nbsp;&nbsp;&nbsp; }<BR>end<BR></DIV>
<DIV style="FONT-SIZE: 12pt; FONT-FAMILY: times new roman, new york, times, serif">&nbsp;</DIV>
<DIV style="FONT-SIZE: 12pt; FONT-FAMILY: times new roman, new york, times, serif"><BR>
<DIV style="FONT-SIZE: 12pt; FONT-FAMILY: times new roman, new york, times, serif"><FONT face=Tahoma size=2>
<HR SIZE=1>
<B><SPAN style="FONT-WEIGHT: bold">From:</SPAN></B> Wolfgang Laun &lt;wolfgang.laun@gmail.com&gt;<BR><B><SPAN style="FONT-WEIGHT: bold">To:</SPAN></B> Manav &lt;manav7574@yahoo.com&gt;; Rules Users List &lt;rules-users@lists.jboss.org&gt;<BR><B><SPAN style="FONT-WEIGHT: bold">Sent:</SPAN></B> Fri, August 13, 2010 1:37:45 PM<BR><B><SPAN style="FONT-WEIGHT: bold">Subject:</SPAN></B> Re: [rules-users] Caching results in temperory variables<BR></FONT><BR>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" target=_blank rel=nofollow ymailto="mailto:manav7574@yahoo.com">manav7574@yahoo.com</A>&gt;</SPAN> wrote:<BR>
<BLOCKQUOTE class=gmail_quote style="PADDING-LEFT: 1ex; MARGIN: 0pt 0pt 0pt 0.8ex; BORDER-LEFT: rgb(204,204,204) 1px solid">Thanks for your response Greg. As you said this is what i&nbsp;tried&nbsp;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&nbsp; 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.&nbsp; 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>&nbsp;&nbsp;&nbsp; User ($id : id)<BR>then<BR>&nbsp;&nbsp;&nbsp; UserResult urslt = new UserResult ($id);<BR>&nbsp;&nbsp;&nbsp; insert ($id)<BR></BLOCKQUOTE>
<DIV><BR>Here I'd expect<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; insert( urslt );<BR><BR>Also, to be on the safe side, I always add a pattern<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 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="PADDING-LEFT: 1ex; MARGIN: 0pt 0pt 0pt 0.8ex; BORDER-LEFT: rgb(204,204,204) 1px solid">end<BR><BR></BLOCKQUOTE>
<DIV>rule "JapaneseScore" <BR></DIV>
<BLOCKQUOTE class=gmail_quote style="PADDING-LEFT: 1ex; MARGIN: 0pt 0pt 0pt 0.8ex; BORDER-LEFT: rgb(204,204,204) 1px solid">salience 100</BLOCKQUOTE>
<BLOCKQUOTE class=gmail_quote style="PADDING-LEFT: 1ex; MARGIN: 0pt 0pt 0pt 0.8ex; BORDER-LEFT: rgb(204,204,204) 1px solid">&nbsp; <BR></BLOCKQUOTE>
<BLOCKQUOTE class=gmail_quote style="PADDING-LEFT: 1ex; MARGIN: 0pt 0pt 0pt 0.8ex; BORDER-LEFT: rgb(204,204,204) 1px solid">lock-on-active truewhen<BR>&nbsp; &nbsp; $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:&nbsp; User( $id == id ) <BR></DIV>
<BLOCKQUOTE class=gmail_quote style="PADDING-LEFT: 1ex; MARGIN: 0pt 0pt 0pt 0.8ex; BORDER-LEFT: rgb(204,204,204) 1px solid">&nbsp;&nbsp;&nbsp; $urslt :&nbsp; UserResult (id == $<A href="http://usr.id/" target=_blank rel=nofollow>usr.id</A>)<BR></BLOCKQUOTE>
<DIV>so I can simplify this. Add a constraint to avoid looping:<BR><BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; $urslt : USerResult( id == $id, langScore.keySet not contains "Japanese" )<BR>&nbsp;</DIV>
<BLOCKQUOTE class=gmail_quote style="PADDING-LEFT: 1ex; MARGIN: 0pt 0pt 0pt 0.8ex; BORDER-LEFT: rgb(204,204,204) 1px solid">then<BR>&nbsp;&nbsp;&nbsp;&nbsp;$usrlt.setLangScore("Japanese", $j_score);&nbsp;<BR></BLOCKQUOTE>
<DIV>&nbsp; &nbsp; &nbsp; &nbsp; update( $usrlt );<BR></DIV>
<BLOCKQUOTE class=gmail_quote style="PADDING-LEFT: 1ex; MARGIN: 0pt 0pt 0pt 0.8ex; BORDER-LEFT: rgb(204,204,204) 1px solid">end<BR></BLOCKQUOTE>
<DIV><BR><BR>rule "FrenchScore" <BR></DIV>
<BLOCKQUOTE class=gmail_quote style="PADDING-LEFT: 1ex; MARGIN: 0pt 0pt 0pt 0.8ex; BORDER-LEFT: rgb(204,204,204) 1px solid">salience 50<BR></BLOCKQUOTE>
<DIV>Why not 100?<BR>&nbsp;<BR></DIV>
<BLOCKQUOTE class=gmail_quote style="PADDING-LEFT: 1ex; MARGIN: 0pt 0pt 0pt 0.8ex; BORDER-LEFT: rgb(204,204,204) 1px solid">lock-on-active true&nbsp;</BLOCKQUOTE>
<DIV>not necessary now<BR>&nbsp;</DIV>
<BLOCKQUOTE class=gmail_quote style="PADDING-LEFT: 1ex; MARGIN: 0pt 0pt 0pt 0.8ex; BORDER-LEFT: rgb(204,204,204) 1px solid">when<BR>&nbsp; &nbsp; User (language.keySet contains "French", $f_score : language["French"])<BR>&nbsp;&nbsp;&nbsp; $urslt :&nbsp; UserResult (id == $<A href="http://usr.id/" target=_blank rel=nofollow>usr.id</A>)<BR></BLOCKQUOTE>
<DIV>Same as before:<BR>&nbsp;$urslt :&nbsp; UserResult (id == $<A href="http://usr.id/" target=_blank rel=nofollow>id</A>, langScore.keySet not contains "French" )<BR><BR></DIV>
<BLOCKQUOTE class=gmail_quote style="PADDING-LEFT: 1ex; MARGIN: 0pt 0pt 0pt 0.8ex; BORDER-LEFT: rgb(204,204,204) 1px solid">then<BR>&nbsp;&nbsp;&nbsp; $usrlt.setLangScore("French", $_score);&nbsp;<BR>&nbsp;&nbsp;&nbsp; update ($usrlt);<BR>end<BR><BR>salience 25<BR>when<BR>&nbsp;&nbsp;&nbsp; UserResult (score &gt; 4) // does not work<BR>then<BR>&nbsp;&nbsp;&nbsp; // if ($usr_rslt.getScore() &gt; 4)&nbsp; --&gt; works well<BR>&nbsp;&nbsp;&nbsp; // 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>&nbsp;&nbsp; Language( $name : name ) <BR>&nbsp;&nbsp; User ($id : id, language.keySet contains $name", $f_score : language[$name])<BR>&nbsp;&nbsp; $urslt :&nbsp; UserResult (id == $<A href="http://usr.id/" target=_blank rel=nofollow>id</A>, langScore.keySet not contains $name )<BR></DIV>then<BR>&nbsp;&nbsp;&nbsp; modify( $usrlt ){<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; setLangScore($name, $_score)<BR>&nbsp;&nbsp;&nbsp; }<BR>end<BR><BR>HTH<BR>--W<BR><BR>&nbsp;</DIV>
<BLOCKQUOTE class=gmail_quote style="PADDING-LEFT: 1ex; MARGIN: 0pt 0pt 0pt 0.8ex; BORDER-LEFT: rgb(204,204,204) 1px solid"><BR><BR>----- Original Message ----<BR>From: Greg Barton &lt;<A href="mailto:greg_barton@yahoo.com" target=_blank rel=nofollow ymailto="mailto:greg_barton@yahoo.com">greg_barton@yahoo.com</A>&gt;<BR>To: Manav &lt;<A href="mailto:manav7574@yahoo.com" target=_blank rel=nofollow ymailto="mailto:manav7574@yahoo.com">manav7574@yahoo.com</A>&gt;; Rules Users List &lt;<A href="mailto:rules-users@lists.jboss.org" target=_blank rel=nofollow ymailto="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.&nbsp; That'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" target=_blank rel=nofollow ymailto="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>&nbsp; &nbsp; User (language.keySet contains "Japanese", $j_score : language["Japanese"])<BR>then<BR>&nbsp; &nbsp; // do something<BR>end<BR><BR>salience 50<BR>when<BR>&nbsp; &nbsp; User (language.keySet contains "French", $f_score : language["French"])<BR>then<BR>&nbsp; &nbsp; // do something<BR>end<BR><BR>salience 25<BR>when<BR>&nbsp; &nbsp; eval (($j_score + $f_score) &gt; 4)<BR>then<BR>&nbsp; &nbsp; // 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" target=_blank rel=nofollow ymailto="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 rel=nofollow>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" target=_blank rel=nofollow ymailto="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 rel=nofollow>https://lists.jboss.org/mailman/listinfo/rules-users</A><BR></DIV></DIV></BLOCKQUOTE></DIV><BR></DIV></DIV></div><br>

      </body></html>