On 7 July 2011 08:25, Felix Chan <chanfe...@gmail.com> 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

Reply via email to