问题
I'm trying to create a diagnosis expert system. I have managed to create the menu and submenu but after inputting my choice(e.g 1). The question that supposed to be asked after the submenu does not appear. Hence not being able to continue. I would like to ask whether is there anything wrong with what I did? If there is, what is the proper way to do it?
Here's a part of the code for reference:
CLIPS> ;; MainMenu
(defrule Menu
(not (iffoundChoice ?))
=>
(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: ")
(assert (iffoundChoice (read))))
CLIPS> ;; submenu1
(defrule subMenu1
(not (iffoundChoice1 ?))
=>
(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
" 4.) END SYSTEM. "crlf crlf crlf
" Enter no. of your choice: ")
(assert (iffoundChoice1 (read))))
CLIPS> ;; Rule 1 based on choice 1
(defrule car_pulls_one_side_when_braking
(iffoundChoice1)
?retractCh1 <- (iffoundChoice1)
(not (ifYesNochoice ?))
=>
(retract ?retractCh1)
(printout t crlf crlf crlf
" Was your tyre uneven? (yes|no) "crlf crlf
" Your answer: ")
(assert (ifYesNochoice (read))))
CLIPS> ;;Rule 2 based on Yes answer in Rule 1
(defrule car_pulls_one_side_when_braking1
(ifYesNochoice yes)
?retractChy <- (ifYesNochoice yes)
(not (ifYesNochoice1 ?))
=>
(retract ?retractChy)
(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)))))
CLIPS> ;;Rule 3 based on Yes answer in Rule 2
(defrule car_pulls_one_side_when_braking2
(ifYesNochoice1 yes)
?retract <- (ifYesNochoice1)
(not (ifYesNochoise2 ?))
=>
(retract ?retract Chy)
(printout t crlf crlf crlf
" Then your car should be no problem. " crlf crlf
" Thanks for using Vehicle Diagnosis Failure System. " crlf crlf))
CLIPS> ;; Rule 4 based on NO answer in Rule 2
(defrule car_pulls_one_side_when_braking3
(ifYesNochoice1 no)
?retract <- (ifYesNochoice1)
(not (ifYesNochoice3 ?))
=>
(retract ?retract Chy)
(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))
CLIPS> (reset)
CLIPS> (run)
回答1:
Change the patterns for iffoundChoice and iffoundChoice1 to include the user selection.
(defrule car_pulls_one_side_when_braking
(iffoundChoice 1) ; <--
?retractCh1 <- (iffoundChoice1 1) ; <--
(not (ifYesNochoice ?))
=>
(retract ?retractCh1)
(printout t crlf crlf crlf
" Was your tyre uneven? (yes|no) "crlf crlf
" Your answer: ")
(assert (ifYesNochoice (read))))
来源:https://stackoverflow.com/questions/40969068/clips-unable-to-proceed-after-inputting-choice