Re: JESS: question about writing rule that is based on comparing the number of one kind of facts and that of another
"Felix Chan" <[email protected]> Sat, 9 Jul 2011 19:55:43 -0700
| Newsgroups | gmane.comp.java.jess |
|---|---|
| Message-ID | <28620_1310299452_p6AC4C7M001645_1B88DFF5-2AFA-4575-82E8-8BB2BD1ECCF6@gmail.com> |
Thanks Wolfgang. This is great. On Jul 7, 2011, at 5:54 AM, "Wolfgang Laun" <[email protected]> wrote: > On 7 July 2011 08:25, Felix Chan <[email protected]> wrote: > Hi, > > I am trying to find a way to write a rule that is based on comparing > the number of one kind of facts and the number of another kind. I am > sure experienced JESS users > > Actually, Ernest has seen it a long time ago, and therefore we have... > > must have seen this requirement before and > likely have a "standard", perhaps elegant way of dealing with it. But > I am sorry to say that I am still struggling with it after some time. > > ... the CE accumulate! > > (defrule getNumOfCars > ?p <- (policy (policyId ?pid)) > (car (policyId ?pid)) > ?c <- (accumulate (bind ?count 0) > (bind ?count (+ ?count 1)) > ?count > (car (policyId ?pid))) > => > (modify ?p (numOfCars ?c)) > ) > (defrule getNumOfDrivers > ?p <- (policy (policyId ?pid)) > ?c <- (accumulate (bind ?count 0) > (bind ?count (+ ?count 1)) > ?count > (driver (policyId ?pid))) > => > (modify ?p (numOfDrivers ?c)) > ) > > You can remove the queries. > -W