0
votes

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

1 Answers

1
votes

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>