我正在尝试使用 CLIPSPY 从 python 修改事实模板。它的行为很奇怪,因为它确实第一次修改了一个插槽,但是对于下一个插槽,它不会甚至将先前修改的插槽值重新修改为其他内容!
这是python文件。
# run.py
import clips
clips_env = clips.Environment()
def py_modify_s1(p):
p.retract()
p["s_1"] = clips.Symbol("ABC")
p.assertit()
def py_modify_s2(p):
p.retract()
p["s_2"] = clips.Symbol("DEF")
p.assertit()
clips_env.define_function(py_modify_s1)
clips_env.define_function(py_modify_s2)
clips_env.load("KB.clp")
clips_env.reset()
clips_env.run()
这是 clp 文件。
(deftemplate t
(slot s_1 (type SYMBOL) (default none))
(slot s_2 (type SYMBOL) (default none))
)
(defrule rule_0
(initial-fact)
=>
(assert (t))
)
(defrule rule_1
?p<-(t (s_1 none) (s_2 none))
=>
(py_modify_s1 ?p)
(facts)
)
(defrule rule_2
?p <- (t (s_1 ?x&~none) (s_2 none))
=>
(py_modify_s2 ?p)
(facts)
)
(defrule rule_3
?p <- (t (s_1 ?x&~none) (s_2 ?y&~none))
=>
(printout t "All set")
(facts)
)
在 CLIPS shell 中运行相同的剪辑文件(将 py_modify 替换为(modify ?p (s_1,ABC))
)会产生预期的结果。但是从 clipspy 运行我得到:
f-0 (initial-fact)
f-2 (t (s_1 ABC) (s_2 none))
For a total of 2 facts.
f-0 (initial-fact)
f-2 (t (s_1 ▒▒▒3wU) (s_2 none))
For a total of 2 facts.
请注意在触发后如何s_1
包含一些垃圾值rule_2
并且s_2
不只修改。结果,rule_3
永远不会被解雇。