<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. I modified my drl as per your suggestions and it's just been completely transformed. Just one question regarding one suggestion below :</DIV>
<DIV> </DIV>
<DIV>-- is this something like a for each loop in java . This is the first example i have seen in 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> 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 rel=nofollow><FONT color=#0000ff>id</FONT></A>, langScore.keySet not contains $name )<BR></DIV>then<BR> modify( $usrlt ){<BR> setLangScore($name, $_score)<BR> }<BR>end<BR></DIV>
<DIV style="FONT-SIZE: 12pt; FONT-FAMILY: times new roman, new york, times, serif"> </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 <wolfgang.laun@gmail.com><BR><B><SPAN style="FONT-WEIGHT: bold">To:</SPAN></B> Manav <manav7574@yahoo.com>; Rules Users List <rules-users@lists.jboss.org><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><<A href="mailto:manav7574@yahoo.com" target=_blank rel=nofollow ymailto="mailto:manav7574@yahoo.com">manav7574@yahoo.com</A>></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 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="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"> <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> $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="PADDING-LEFT: 1ex; MARGIN: 0pt 0pt 0pt 0.8ex; BORDER-LEFT: rgb(204,204,204) 1px solid"> $urslt : 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> $urslt : USerResult( id == $id, langScore.keySet not contains "Japanese" )<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> $usrlt.setLangScore("Japanese", $j_score); <BR></BLOCKQUOTE>
<DIV> 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> <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 </BLOCKQUOTE>
<DIV>not necessary now<BR> </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> User (language.keySet contains "French", $f_score : language["French"])<BR> $urslt : UserResult (id == $<A href="http://usr.id/" target=_blank rel=nofollow>usr.id</A>)<BR></BLOCKQUOTE>
<DIV>Same as before:<BR> $urslt : 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> $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 rel=nofollow>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="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 <<A href="mailto:greg_barton@yahoo.com" target=_blank rel=nofollow ymailto="mailto:greg_barton@yahoo.com">greg_barton@yahoo.com</A>><BR>To: Manav <<A href="mailto:manav7574@yahoo.com" target=_blank rel=nofollow ymailto="mailto:manav7574@yahoo.com">manav7574@yahoo.com</A>>; Rules Users List <<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>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" target=_blank rel=nofollow ymailto="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" 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>