2016-12-05 34 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