2016-11-22 96 views
0

我怎样才能使CLIPS条件规则来找到输出CLIPS条件规则

例如

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

蒙山这个这个,我们如何创建一个像

规则
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 

谢谢

回答

1
(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))) 
    ) 

我会用两条不同的规则将最后一条规则的“或”条件分开,类似于我写的例子。

再见 Nic

+0

感谢Nic。我收到一个错误:[EXPRNPSR3]缺少选项的函数声明。难道我做错了什么? – Selrac

+0

对不起,它正在工作。我没有正确复制你的代码。谢谢 – Selrac

+0

您可以直接匹配常量,而不是绑定变量并调用eq函数。例如,使用(假日(旅馆穷人)(天气下雨))(假日(旅馆?旅馆&:(旅馆穷人))(天气?天气&:(当然?天气下雨))) –