Search code examples
if-statementclips

CLIPS conditional rule


How can I make conditional rule in CLIPS to find the output

For example

(deftemplate holiday
(slot hotel (allowed-symbols nice good poor))
(slot weather (allowed-symbols sunny raining))
)
(deftemplate output
(slot option (allowed-symbols go plan stay))
)

Whith this this, how do we create a rule like

if hotel = poor then stay
if hotel = poor and weather = raining then stay
if (hotel = poor and weather = sunny) or (hotel = good and weather = raining) then plan

Thanks


Solution

  •  (defrule hotel-rule1
           (holiday (hotel ?hotel&:(eq ?hotel poor)))
           =>
           (assert (output (option stay)))
        )
    
    (defrule hotel-rule2
           (holiday (hotel ?hotel&:(eq ?hotel poor)) (weather ?weather&:(eq ?weather raining)))
           =>
           (assert (output (option stay)))
        )
    

    I would split the "or" condition of your last rule in two different rules, similar to the examples I wrote.

    Bye Nic