I have a question about how best to accomplish something with rules in
Jess.
Here is the scenario. Houses can hold boxes and boxes can be of
different colors. Whenever a box has a red color, a user is to be
notified of the house name and the name of the red box (we want a rule
to express this). In the example, we have two houses, h1 and h2 and
five boxes b1-b5. The red boxes are b1, b3 and b4.
(deftemplate house
"Houses"
(slot name)
(multislot contains)
)
(deftemplate box
"Different boxes"
(slot id)
(slot color)
(slot volume (default volume)))
(deftemplate notify-user
(slot house) (slot box))
(deffacts house-info
"comment"
(house (name h1) (contains b1 b2 b3))
(house (name h2) (contains b4 b5))
)
(deffacts box-info
(box (id b1) (color red))
(box (id b2) (color blue))
(box (id b3) (color red))
(box (id b4) (color red))
(box (id b5) (color blue))
)
I want to write a rule whose RHS can be used to assert the following
facts regarding red boxes in houses:
(notify-user (house h1) (box b1))
(notify-user (house h1) (box b3)) and
(notify-user (house h2) (box b4)), and use these facts to notify the user.
I tried with the following:
(defrule dowork
"comment"
(house (name ?housename) (contains $?boxes))
=>
(my-function ?housename ?boxes))
Now what is the best way to write my-function? Use defquery? Or is
there a better/cleaner way by doing the appropriate matching
on the LHS of the rule?
Thanks,
Kartha
--------------------------------------------------------------------
To unsubscribe, send the words 'unsubscribe jess-users [EMAIL PROTECTED]'
in the BODY of a message to [EMAIL PROTECTED], NOT to the list
(use your own address!) List problems? Notify [EMAIL PROTECTED]
--------------------------------------------------------------------