Клипы: "факт-X" появляется при запуске, и выбор цикла
Я делаю экспертную систему диагностики транспортных средств на основе ссылки. Мне удалось запустить мою систему и она работает успешно, но в конце она отображает "Fact-x"(X - число фактов). Вот дерево решений и код для справки:
;; initialize
(deffacts init (start))
;;Main Menu
(defrule Menu
?ml <- (start)
=>
(printout t crlf crlf crlf
"Choose one of the problem areas listed below" crlf crlf
" 1- Brake Pedal System. "crlf crlf
" 2- Gearbox. "crlf crlf
" 3- ." crlf crlf
" 4- END SYSTEM. "crlf crlf crlf
" Enter no. of your choice: ")
(bind ?response (read))
(switch ?response
(case 1 then (assert (type 0-1)))
(case 2 then (assert (type 0-2)))
(case 3 then (assert (type 0-3)))
(case 4 then (assert (type quit))))
(printout t crlf)
(retract ?ml)))
;; submenu1
(defrule subMenu1
?ml <- (type 0-1)
=>
(printout t crlf crlf crlf
"Choose which topic best relates to your problem? "crlf crlf
" 1-1 Car Pulls One Side When Braking. "crlf crlf
" 1-2 Rear Brake Drag. "crlf crlf
" 1-3 Brake squeal. "crlf crlf
" 1-4 END SYSTEM. "crlf crlf crlf
" Enter no. of your choice: ")
(bind ?response (read))
(switch ?response
(case 1-1 then (assert (type 1-1)))
(case 1-2 then (assert (type 1-2)))
(case 1-3 then (assert (type 1-3)))
(case 1-4 then (assert (type quit))))
(printout t crlf)
(retract ?ml)))
;; END System
(defrule user-quits
(type quit)
=>
(printout t "You have EXIT the System." crlf)
(halt))
;; Rule 1 based on choice 1-1
(defrule car_pulls_one_side_when_braking
?ml <- (type 1-1)
=>
(printout t crlf crlf crlf
" Was your tyre uneven? (yes|no) "crlf crlf
" Your answer: ")
(assert (ifYesNochoice (read))))
(printout t crlf)
(retract ?ml)))
;;Rule 2 based on Yes answer in Rule 1
(defrule car_pulls_one_side_when_braking1
?ml <- (ifYesNochoice yes)
=>
(printout t crlf crlf crlf
" Please check your tyre pressure "crlf crlf
" Is it in good condition? (yes|no) "crlf crlf
" Your answer: "
(assert (ifYesNochoice1 (read)))))
(printout t crlf)
(retract ?ml)))
;;Rule 3 based on Yes answer in Rule 2
(defrule car_pulls_one_side_when_braking2
?ml <- (ifYesNochoice1 yes)
=>
(printout t crlf crlf crlf
" Then your car should be no problem. " crlf crlf
" Thanks for using Vehicle Diagnosis Failure System. " crlf crlf))
(printout t crlf)
(retract ?ml)
(halt)))
;; Rule 4 based on NO answer in Rule 2
(defrule car_pulls_one_side_when_braking3
?ml <- (ifYesNochoice1 no)
=>
(printout t crlf crlf crlf
" Please inflate all the tyres according to the tyre plycard. "crlf crlf
" Please check again with your technician if problem is solved. "crlf crlf
" Thanks for using Vehicle Diagnosis Failure System. "crlf crlf))
(printout t crlf)
(retract ?ml)
(halt)))
;; Rule 5 based on NO answer in Rule 1
(defrule car_pulls_one_side_when_braking4
?ml <- (ifYesNochoice no)
=>
(printout t crlf crlf crlf
" Do you feel a stuck calliper? (yes|no) "crlf crlf
" Your answer: ")
(assert (ifYesNochoice2 (read))))
(printout t crlf)
(retract ?ml)))
;; Rule 6 based on NO answer to Rule 5
(defrule car_pulls_one_side_when_braking5
?ml <- (ifYesNochoice2 no)
=>
(assert (type1-1))
(printout t crlf)
(retract ?ml))
;; Rule 7 based on yes answer in Rule 6
(defrule car_pulls_one_side_when_braking6
?ml <- (ifYesNochoice2 yes)
=>
(printout t crlf crlf crlf
" Did you service your brake calliper? (yes|no) "crlf crlf
" Your answer: ")
(assert (ifYesNochoice3 (read))))
(printout t crlf)
(retract ?ml)))
Мой вопрос заключается в следующем:
1) Как мне НЕ отображать факты-X после запуска системы. Показанные результаты являются следующими: (Обратите внимание на факт-X)
2) Если я хочу сделать цикл для моего вопроса на основе НЕТ для Правила 1 в выборе 1-1. (Например, если для Правила 1 запускается NO, он переходит к следующей проблеме (Правило 6), как показано в дереве решений. Однако, если для Правила 6 не запускается Нет, он не возвращается к Правилу 1.) Как их зациклить?
1 ответ
Ваш код полон неправильно сбалансированных скобок. При загрузке кода генерируется несколько предупреждений:
CLIPS> (clear)
CLIPS> (load "rules.clp")
$*
[CSTRCPSR1] Expected the beginning of a construct.
*
[CSTRCPSR1] Expected the beginning of a construct.
**
[CSTRCPSR1] Expected the beginning of a construct.
*
[CSTRCPSR1] Expected the beginning of a construct.
*
[CSTRCPSR1] Expected the beginning of a construct.
*
[CSTRCPSR1] Expected the beginning of a construct.
*
[CSTRCPSR1] Expected the beginning of a construct.
**
[CSTRCPSR1] Expected the beginning of a construct.
FALSE
CLIPS>
Вот правило, которое заставляет печатать Факт 5:
(defrule car_pulls_one_side_when_braking1
?ml <- (ifYesNochoice yes)
=>
(printout t
crlf crlf crlf
" Please check your tyre pressure "crlf crlf
" Is it in good condition? (yes|no) "crlf crlf
" Your answer: "
(assert (ifYesNochoice1 (read)))
)
)
(printout t crlf)
(retract ?ml)))
Я отступил в коде, чтобы проиллюстрировать баланс открывающих и закрывающих скобок. Утверждение assert включено в качестве аргумента в первую команду printout, поэтому вы видите напечатанный Fact-5. Вторые команды printout и retract не включены в тело правила, поэтому они не будут выполняться при выполнении правила.
Исправленные правила:
;; initialize
(deffacts init (start))
;; Main Menu
(defrule Menu
?ml <- (start)
=>
(printout t crlf crlf crlf
"Choose one of the problem areas listed below" crlf crlf
" 1- Brake Pedal System. "crlf crlf
" 2- Gearbox. "crlf crlf
" 3- ." crlf crlf
" 4- END SYSTEM. "crlf crlf crlf
" Enter no. of your choice: ")
(bind ?response (read))
(switch ?response
(case 1 then (assert (type 0-1)))
(case 2 then (assert (type 0-2)))
(case 3 then (assert (type 0-3)))
(case 4 then (assert (type quit))))
(printout t crlf)
(retract ?ml))
;; submenu1
(defrule subMenu1
?ml <- (type 0-1)
=>
(printout t crlf crlf crlf
"Choose which topic best relates to your problem? "crlf crlf
" 1-1 Car Pulls One Side When Braking. "crlf crlf
" 1-2 Rear Brake Drag. "crlf crlf
" 1-3 Brake squeal. "crlf crlf
" 1-4 END SYSTEM. "crlf crlf crlf
" Enter no. of your choice: ")
(bind ?response (read))
(switch ?response
(case 1-1 then (assert (type 1-1)))
(case 1-2 then (assert (type 1-2)))
(case 1-3 then (assert (type 1-3)))
(case 1-4 then (assert (type quit))))
(printout t crlf)
(retract ?ml))
;; END System
(defrule user-quits
(type quit)
=>
(printout t "You have EXIT the System." crlf)
(halt))
;; Rule 1 based on choice 1-1
(defrule car_pulls_one_side_when_braking
?ml <- (type 1-1)
=>
(printout t crlf crlf crlf
" Was your tyre uneven? (yes|no) "crlf crlf
" Your answer: ")
(assert (ifYesNochoice (read)))
(printout t crlf)
(retract ?ml))
;; Rule 2 based on Yes answer in Rule 1
(defrule car_pulls_one_side_when_braking1
?ml <- (ifYesNochoice yes)
=>
(printout t crlf crlf crlf
" Please check your tyre pressure "crlf crlf
" Is it in good condition? (yes|no) "crlf crlf
" Your answer: ")
(assert (ifYesNochoice1 (read)))
(printout t crlf)
(retract ?ml))
;; Rule 3 based on Yes answer in Rule 2
(defrule car_pulls_one_side_when_braking2
?ml <- (ifYesNochoice1 yes)
=>
(printout t crlf crlf crlf
" Then your car should be no problem. " crlf crlf
" Thanks for using Vehicle Diagnosis Failure System. " crlf crlf)
(printout t crlf)
(retract ?ml)
(halt))
;; Rule 4 based on NO answer in Rule 2
(defrule car_pulls_one_side_when_braking3
?ml <- (ifYesNochoice1 no)
=>
(printout t crlf crlf crlf
" Please inflate all the tyres according to the tyre plycard. "crlf crlf
" Please check again with your technician if problem is solved. "crlf crlf
" Thanks for using Vehicle Diagnosis Failure System. "crlf crlf)
(printout t crlf)
(retract ?ml)
(halt))
;; Rule 5 based on NO answer in Rule 1
(defrule car_pulls_one_side_when_braking4
?ml <- (ifYesNochoice no)
=>
(printout t crlf crlf crlf
" Do you feel a stuck calliper? (yes|no) "crlf crlf
" Your answer: ")
(assert (ifYesNochoice2 (read)))
(printout t crlf)
(retract ?ml))
;; Rule 6 based on NO answer to Rule 5
(defrule car_pulls_one_side_when_braking5
?ml <- (ifYesNochoice2 no)
=>
(assert (type 1-1))
(printout t crlf)
(retract ?ml))
;; Rule 7 based on yes answer in Rule 6
(defrule car_pulls_one_side_when_braking6
?ml <- (ifYesNochoice2 yes)
=>
(printout t crlf crlf crlf
" Did you service your brake calliper? (yes|no) "crlf crlf
" Your answer: ")
(assert (ifYesNochoice3 (read)))
(printout t crlf)
(retract ?ml))