基本CLIPS用法

时间:2017-01-27 22:19:00

标签: clips

我想用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

1 个答案:

答案 0 :(得分:0)

我建议您创建一个包含餐厅和人员模板的模型,并添加一些规则来管理您所需的逻辑。 你可以在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)

再见 尼古拉