Thanks a lot W. That worked like a charm. Just one more twist to the same issue .
Along with the total score for the certifications i also want to take a count of those certifications where the user scores are greater than the required scores for those certifications. I believe i won't be able to use count and sum in the same function as didn't work for me. However was having issues with figuring out how to do that. I was thinking along the below lines but it obviously didn't work out rule "Count test" when $rb : Certifications($reqCertificationKeys : requiredCertifications.keySet, $reqCertifications : requiredCertifications) $user : User( $userCertifications : userCertifications ) Number( $i : intValue ) from accumulate( $key: String( this memberOf ($userCertifications.keySet()) ) from $reqCertificationKeys, count( ($userCertifications.get( $key ) > || == $reqCertifications.get($key) ) ? 1 : 0) ) then System.out.println( "COUNT is " + $i ); end wonder if there's a better way out. regards, Manav ----- Original Message ----- From: Wolfgang Laun <wolfgang.l...@gmail.com> To: Manav <manav7...@yahoo.com>; Rules Users List <rules-users@lists.jboss.org> Cc: Sent: Thursday, August 16, 2012 2:45 PM Subject: Re: [rules-users] Handling maps in Drools This rule works with 5.1.1: rule "Map test" when $rb : Certifications($reqCertificationKeys : requiredCertifications.keySet) $user : User( $userCertifications : userCertifications ) Number( $score : intValue ) from accumulate( $key: String( this memberOf ($userCertifications.keySet()) ) from $reqCertificationKeys, sum( $userCertifications.get( $key ) ) ) then System.out.println( "score is " + $score ); end -W On 16/08/2012, Manav <manav7...@yahoo.com> wrote: > Hi, > > I am facing an issue with handling maps in LHS of drools. Appreciate your > help with the same. > > I am using Drools version 5.1. > > > I have two maps where one is a reference map that contains certifications > (key) and scores(value) required and other is map of user's actual > certifications and scores. Objective is to find the certifications from > users map based on keys in the reference map . Then for these certifications > sum the score values and check if they cross the threshold. > > While trying to do the first step i am facing an issue . My rule looks like > this :- > > rule "Map test" > when > $rb : Certifications($reqCertificationKeys : > requiredCertifications.keySet) > $user : User($userCertifications : userCertifications) > $arg : String() from $reqCertificationKeys > HashMap ($value : this[$arg] != null) from $userCertifications // Does > not work > then > System.out.println ("Hash Map" + $arg); > end > > However if i change the above line that has issues with below > > HashMap ($value : this["Java"] != null) from $userCertifications // > Works > > Is there a way to replace the key with a variable than with a fixed value ? > Is it possible to iterate the second map with the key values that we get > from the reference map ? > > Regards, > Manav > > _______________________________________________ > rules-users mailing list > rules-users@lists.jboss.org > https://lists.jboss.org/mailman/listinfo/rules-users > _______________________________________________ rules-users mailing list rules-users@lists.jboss.org https://lists.jboss.org/mailman/listinfo/rules-users