Checking the input to match fact in Clips

懵懂的女人 提交于 2019-12-13 21:26:08

问题


I have a problem with trying to get an input and fact-check it with symptoms in the asserted facts.

(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))

So basically you input a symptom and Clips returns the disease that matches that symptom. Problem is, that after Loading the file as Batch and running it, nothing happens. The Facts are asserted but no input is required. Nothing even touches the first rule.

If anyone can help me in this issue, I would be dully grateful!

Thanks!


回答1:


You've defined symptom as a multifield slot (a slot containing zero or more fields), but your patterns matching those slots will only match if the slot contains a single field. Use a multifield variable such as $?symptom1 instead of a single field variable such as ?symptom1 to retrieve multiple values.

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>


来源:https://stackoverflow.com/questions/27362356/checking-the-input-to-match-fact-in-clips

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!