如何知道在基于规则的系统的前端要问哪些问题
How to know which questions to ask on front end for rule based system
我正在开发一个基于简单诊断规则的专家系统。它应该提出问题并识别动物健康问题。我正在使用反向链接进行推理。我如何知道在前端提出哪些问题来断言新规则?假设我有一堆规则 IF A THEN B,IF B THEN C。知道如果 B 被断言它将检查 C,然后它将检查 A 是否被断言。现在因为 a 没有断言,我需要在前端问这个问题。是否有一些方法可以知道要问什么问题?
这在很大程度上取决于如何实现反向链接的细节。例如,您可以在 Jess 中执行此操作,其中引擎生成可按规则匹配的目标:
Jess>
(deftemplate symptom
(declare (backchain-reactive TRUE))
(slot name)
(slot value))
TRUE
Jess>
(deftemplate diagnosis
(slot name))
TRUE
Jess>
(deftemplate question
(slot name)
(slot string))
TRUE
Jess>
(deffacts questions
(question (name has-fever) (string "Does patient have a fever?"))
(question (name swollen-neck) (string "Does patient have a swollen neck?"))
(question (name skin-rash) (string "Does patient have a skin rash?")))
TRUE
Jess>
(defrule measles
(symptom (name has-fever) (value yes))
(symptom (name skin-rash) (value yes))
=>
(assert (diagnosis (name measles)))
(printout t "Patient has measles." crlf))
TRUE
Jess>
(defrule mumps
(symptom (name has-fever) (value yes))
(symptom (name swollen-neck) (value yes))
=>
(assert (diagnosis (name mumps)))
(printout t "Patient has mumps." crlf))
TRUE
Jess>
(defrule ask-question
(need-symptom (name ?name))
(question (name ?name) (string ?string))
(not (diagnosis))
=>
(printout t ?string " ")
(assert (symptom (name ?name) (value (read)))))
TRUE
Jess> (reset)
TRUE
Jess> (run)
Does patient have a fever? yes
Does patient have a swollen neck? yes
Patient has mumps.
3
Jess> (reset)
TRUE
Jess> (run)
Does patient have a fever? yes
Does patient have a swollen neck? no
Does patient have a skin rash? yes
Patient has measles.
4
Jess>
我正在开发一个基于简单诊断规则的专家系统。它应该提出问题并识别动物健康问题。我正在使用反向链接进行推理。我如何知道在前端提出哪些问题来断言新规则?假设我有一堆规则 IF A THEN B,IF B THEN C。知道如果 B 被断言它将检查 C,然后它将检查 A 是否被断言。现在因为 a 没有断言,我需要在前端问这个问题。是否有一些方法可以知道要问什么问题?
这在很大程度上取决于如何实现反向链接的细节。例如,您可以在 Jess 中执行此操作,其中引擎生成可按规则匹配的目标:
Jess>
(deftemplate symptom
(declare (backchain-reactive TRUE))
(slot name)
(slot value))
TRUE
Jess>
(deftemplate diagnosis
(slot name))
TRUE
Jess>
(deftemplate question
(slot name)
(slot string))
TRUE
Jess>
(deffacts questions
(question (name has-fever) (string "Does patient have a fever?"))
(question (name swollen-neck) (string "Does patient have a swollen neck?"))
(question (name skin-rash) (string "Does patient have a skin rash?")))
TRUE
Jess>
(defrule measles
(symptom (name has-fever) (value yes))
(symptom (name skin-rash) (value yes))
=>
(assert (diagnosis (name measles)))
(printout t "Patient has measles." crlf))
TRUE
Jess>
(defrule mumps
(symptom (name has-fever) (value yes))
(symptom (name swollen-neck) (value yes))
=>
(assert (diagnosis (name mumps)))
(printout t "Patient has mumps." crlf))
TRUE
Jess>
(defrule ask-question
(need-symptom (name ?name))
(question (name ?name) (string ?string))
(not (diagnosis))
=>
(printout t ?string " ")
(assert (symptom (name ?name) (value (read)))))
TRUE
Jess> (reset)
TRUE
Jess> (run)
Does patient have a fever? yes
Does patient have a swollen neck? yes
Patient has mumps.
3
Jess> (reset)
TRUE
Jess> (run)
Does patient have a fever? yes
Does patient have a swollen neck? no
Does patient have a skin rash? yes
Patient has measles.
4
Jess>