片段:输入选项后无法继续 [英] CLIPS: Unable to proceed after inputting choice

查看:75
本文介绍了片段:输入选项后无法继续的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试创建诊断专家系统.输入了我的选择(例如1)后,我已经设法创建了菜单和子菜单.子菜单后应该出现的问题没有出现.因此无法继续.我想问一下我做的事是否有问题? 如果有的话,什么是正确的方法呢?

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)

推荐答案

更改iffoundChoice和iffoundChoice1的模式以包括用户选择.

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))))

这篇关于片段:输入选项后无法继续的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆