I'm building a simple expert system for illness diagnosis. I have collected the symptoms of a patient and stored them in lists like so:
(patient_symptoms headache)
(patient_symptoms temperature)
(patient_symptoms cough)
I've also defined a template:
(deftemplate illness_matching
(multislot symptom_names (type SYMBOL))
)
I'm trying to convert the values from "patient_symptoms" to a single instance of "illness_matching" template.
I have tried this:
(defrule convert_to_template
(patient_symptoms $?all)
=>
(assert (illness_matching (symptom_names ?all)))
)
The result:
(illness_matching (symptom_names headache))
(illness_matching (symptom_names temperature))
(illness_matching (symptom_names cough))
The result I'm expecting:
(illness_matching (symptom_names headache temperature cough))
Assuming your list of symptoms to be ordered facts which you assert one by one, you will need to persist the information of the current state of the illness in your rule so you can append the new symptoms.
The
modify
statement allows you to change the value of an existing fact. Then you simply change thesymptom_name
slot with a new one which is the result of the old one (which you get via thefact-slot-value
function) with the new symptom added at the beginning through theinsert$
function.Example: