检查输入以匹配剪辑中的事实

时间:2014-12-08 16:26:19

标签: input clips

我在尝试获取输入时遇到问题,并在断言的事实中对其进行事实检查。

(deftemplate disease
(slot name)
(multislot symptom ))

(assert (disease 
(name nitro-def) (symptom stunted-growth pale-yellow reddish-brown-leaf)))
(assert (disease 
(name phosphor-def) (symptom stunted-root-growth spindly-stalk purplish-colour)))
(assert (disease 
(name potassium-def) (symptom purple-colour weakened-stems shriveled-seeds)))

(defrule reading-input
(disease (name ?name1) (symptom ?symptom1))
=>
(printout t "Enter the symptom your plant exhibits: " )
(assert (var (read))))

(defrule checking-input
?vars <- (var)
(disease (name ?name1) (symptom ?symptom1))
(disease (symptom ?vars&:(eq ?vars ?symptom1)))
=>
(printout t "Disease is " ?name1 crlf))

所以基本上你输入了一个症状,而Clips会返回与该症状相匹配的疾病。问题是,在将文件作为批处理加载并运行后,没有任何反应。声明事实但不需要输入。什么都没有触及第一条规则。

如果有人能在这个问题上帮助我,我会非常感激!

谢谢!

1 个答案:

答案 0 :(得分:1)

您已将症状定义为多字段插槽(包含零个或多个字段的插槽),但匹配这些插槽的模式仅在插槽包含单个字段时才匹配。使用多字段变量(如$?symptom1)而不是单个字段变量(如?symptom1)来检索多个值。

CLIPS> 
(deftemplate disease
   (slot name)
   (multislot symptom))
CLIPS> 
(deffacts diseases
   (disease (name nitro-def) 
            (symptom stunted-growth pale-yellow reddish-brown-leaf))
   (disease (name phosphor-def) 
            (symptom stunted-root-growth spindly-stalk purplish-colour))
   (disease (name potassium-def) 
            (symptom purple-colour weakened-stems shriveled-seeds)))
CLIPS> 
(defrule reading-input
   =>
   (printout t "Enter the symptom your plant exhibits: " )
   (assert (var (read))))
CLIPS> 
(defrule checking-input
   (var ?symptom)
   (disease (name ?name1) (symptom $?symptom1))
   (test (member$ ?symptom ?symptom1)) 
   =>
   (printout t "Disease is " ?name1 crlf))
CLIPS> (reset)
CLIPS> (run)
Enter the symptom your plant exhibits: stunted-growth
Disease is nitro-def
CLIPS> (reset)
CLIPS> (run)
Enter the symptom your plant exhibits: purplish-colour
Disease is phosphor-def
CLIPS> (reset)
CLIPS> (run)
Enter the symptom your plant exhibits: spindly-stalk
Disease is phosphor-def
CLIPS>