CLIPS控制事实

时间:2018-09-12 19:28:00

标签: clips

我有这个剪辑程序,该程序使用显着性来获取消息“欢迎使用建议系统”。总是首先出现,但是我想知道如何使用控制事实而不使用显着性来做到这一点。

  1  (deffacts prerequisites
  2  (after COP1000 take COP2000)
  3  (after COP1001 take COP2001)
  4  (after MAC1000 take MAC2000)
  5  (after MAC1001 take MAC2001)
  6  (after ENG1000 and ENG1001 take ENG2000))
  7 
  8  (defrule welcome
  9  (declare (salience 10000))
 10   =>
 11   (printout t "Welcome to the advising system." crlf))
 12   
 13  (defrule rule2
 14   (after ?course1 take ?course2)
 15   (student ?name $? ?course1 $?)
 16   =>
 17   (printout t "Since " ?name " has taken " ?course1 " , I suggest taking " ?course2 "." crlf))

2 个答案:

答案 0 :(得分:1)

CLIPS> 
(deffacts prerequisites
   (after COP1000 take COP2000)
   (after COP1001 take COP2001)
   (after MAC1000 take MAC2000)
   (after MAC1001 take MAC2001)
   (after ENG1000 and ENG1001 take ENG2000)
   (student Cindy COP1000 MAC1001)
   (phase welcome))
CLIPS>   
(defrule welcome
   ?f <- (phase welcome)
   =>
   (retract ?f)
   (assert (phase process))
   (printout t "Welcome to the advising system." crlf))
CLIPS>   
(defrule rule2
   (phase process)
   (after ?course1 take ?course2)
   (student ?name $? ?course1 $?)
   =>
   (printout t "Since " ?name " has taken " ?course1 " , I suggest taking " ?course2 "." crlf))
CLIPS> (reset)
CLIPS> (watch facts)
CLIPS> (watch activations)
CLIPS> (watch rules)
CLIPS> (run)
FIRE    1 welcome: f-7
<== f-7     (phase welcome)
==> f-8     (phase process)
==> Activation 0      rule2: f-8,f-1,f-6
==> Activation 0      rule2: f-8,f-4,f-6
Welcome to the advising system.
FIRE    2 rule2: f-8,f-4,f-6
Since Cindy has taken MAC1001 , I suggest taking MAC2001.
FIRE    3 rule2: f-8,f-1,f-6
Since Cindy has taken COP1000 , I suggest taking COP2000.
CLIPS>

答案 1 :(得分:1)

如果您想要多个阶段(比如说两个以上),我会坚持使用Gary Riley的方法。但是,如果您的愿望是一条简单的预决规则,我建议根据控制标记对事实进行初始声明。

(defrule prerequisites
  (preinit-done)
  =>
  (assert
    (after COP1000 take COP2000)
    (after COP1001 take COP2001)
    (after MAC1000 take MAC2000)
    (after MAC1001 take MAC2001)
    (after ENG1000 and ENG1001 take ENG2000))
)

(defrule welcome
  (not (preinit-done))
  =>
  (printout t "Welcome to the advising system." crlf)
  (assert (preinit-done))
)

(defrule rule2
   (after ?course1 take ?course2)
   (student ?name $? ?course1 $?)
   =>
   (printout t "Since " ?name " has taken " ?course1 " , I suggest taking " ?course2 "." crlf)
)

这样,您就不必在每个规则中都添加阶段事实,只要它们以某种方式取决于您的初始事实即可。