CLIPS 的基本用法

Basic CLIPS usage

我想用 CLIPS 解决以下非常基本的问题:

给出了一份餐厅列表和这些餐厅提供的食物类型,并且还给出了对食物的渴望,请给我一个关于去哪家餐厅的建议。

到目前为止,我所拥有的是非常基础的。我可以为具有不同食物可能性的餐厅创建模板:

;;;*************
;;;* EATERIES  *
;;;*************

(deftemplate restaurant
   (slot name
      (type SYMBOL)
      (default ?NONE))
   (slot food-served
      (type SYMBOL)
      (allowed-symbols salad coffee vegan breakfast burgers)
  (default blank)))

然后我将如何定义特定餐厅的食物选择?

我如何指定我想吃的食物?

我将如何定义规则,例如:

IF craving-salad THEN go-to-salad-bar

我建议您创建一个包含餐厅和人员模板的模型,并添加一些规则来管理您所需的逻辑。 你可以找到很多 CLIPS 的例子。我花了一些时间才明白 CLIPS 是如何工作的。阅读手册是一个很好的起点,查看示例是基础。 这是我为您测试的一个小脚本。 运行 它在 CLIPS 中。

(deftemplate restaurant
   (slot name
      (type SYMBOL))
   (slot food-served
      (type SYMBOL)
      (allowed-symbols salad coffee vegan breakfast burgers)))

(deftemplate person
   (slot name
      (type STRING))
   (slot craving
      (type SYMBOL)
      (allowed-symbols salad coffee vegan breakfast burgers)))

(defrule suggestion
   (restaurant (food-served ?food) (name ?restaurantName))
   (person (name ?personName) (craving ?craving))
   (test (eq ?food ?craving))
   =>
   (bind ?message (format nil "It seems that %s is craving %s. I suggest him to go to %s!" ?personName ?food ?restaurantName))
   (printout t ?message crlf))          


 (assert (restaurant (name McDonalds) (food-served burgers)))
 (assert (restaurant (name Dannys) (food-served breakfast)))
 (assert (restaurant (name KingOfSalads) (food-served salad)))
 (assert (restaurant (name CoffeeParadise) (food-served coffee)))

 (assert (person (name "Nicola") (craving burgers)))
 (assert (person (name "Rebecca") (craving salad)))
 (assert (person (name "James") (craving breakfast)))

 (run) 
 (exit)

再见 尼古拉