Я новичок в CLIPS, и парадигма отката вызывает у меня головную боль.
Мне задают вопрос, в котором мне нужно получить следующий результат.
Q: Is the patient's temperature more than 39? [yes/no]: yes
The patient has fever
Q: Does the patient sick over a month? [yes/no]: yes
We suspect the patient has bacterial infection
Q: How about sore throat? [yes/no]: yes
We believe the patient has strep throat
При необходимости я определил несколько правил, чтобы заставить его работать.
(defrule rule_1
(THE-PATIENT-HAS-A-SORE-THROAT)
(WE-SUSPECT-A-BACTERIAL-INFECTION) =>
(assert(WE-BELIEVE-THE-PATIENT-HAS-STREP-THROAT))
(printout t "We believe the patient has strep throat" crlf))
(defrule rule_2
(THE-PATIENT-TEMPERATURE-IS-40C) =>
(assert(THE-PATIENT-HAS-A-FEVER)))
(defrule rule_3
(THE-PATIENT-HAS-BEEN-SICK-OVER-A-MONTH)
(THE-PATIENT-HAS-A-FEVER) =>
(assert(WE-SUSPECT-A-BACTERIAL-INFECTION)))
(defrule ask-sick
(start-question) =>
(printout t "Q: Is the patient's temperature more than 39? [yes/no]: ")
(bind ?input (readline))
(if (neq ?input "no")
then
(assert (THE-PATIENT-TEMPERATURE-IS-40C))
(printout t "The patient has fever" crlf)
(printout t "Q: Does the patient sick over a month? [yes/no]: ")
(bind ?input2 (readline))
(if (neq ?input2 "no")
then
(assert (THE-PATIENT-HAS-BEEN-SICK-OVER-A-MONTH))
(printout t "We suspect the patient has bacterial infection" crlf)
(printout t "Q: How about sore throat? [yes/no]: ")
(bind ?input3 (readline))
(if (neq ?input3 "no")
then
(assert (THE-PATIENT-HAS-A-SORE-THROAT))
)
)
)
)
(deffacts start
(start-question)
)
В конце концов я заставил программу жить.
Проблема в том, что в соответствии с правилом, о котором вы спрашиваете, мне пришлось включить кучу if-then-else, чтобы заставить программу работать там, где она не очень соответствует парадигме поиска с возвратом.
Может ли кто-нибудь сказать мне, как мне его оптимизировать, поскольку он знает, с чего действовать, rule1 -> rule2 / rule3 и т. Д.