Re: JESS: question about writing rule that is based on comparing the number of one kind of facts and that of another
"Wolfgang Laun" <[email protected]> Thu, 7 Jul 2011 14:54:55 +0200
| Newsgroups | gmane.comp.java.jess |
|---|---|
| Message-ID | <24064_1310051712_p67FFCjK029340_CANaj1LdQGq=z23C80UEpcnBRQDDM6b6g9gdavv9sUkzHLCk2dg@mail.gmail.com> |
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