2016-12-05 59 views
0

我正在嘗試創建診斷專家系統。我已經設法創建了菜單和子菜單,但輸入了我的選擇後(例如1)。子菜單後應該詢問的問題沒有出現。因此無法繼續。我想問一下我所做的是否有什麼問題? 如果有,那麼正確的方法是什麼?CLIPS:輸入選項後無法繼續

下面的代碼的一部分以供參考:

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) 

回答

0

更改爲iffoundChoice和iffoundChoice1圖案以包括用戶選擇。

(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)))) 
+0

你好,很抱歉這麼晚纔回復,我設法得到它的工作使用參考類似另一個鏈接到我的[鏈接](http://stackoverflow.com/questions/34110980/expert-system-clips -code返回假值)。但不幸的是,後來的代碼中有一個小小的呃,我做了,我會在另一篇文章中發佈。但非常感謝您的幫助! :) – Isaac