📄 fix_computer.clp
字号:
;;;======================================================
;;; Fix Computer Expert System
;;;
;;; This expert system fix some simple
;;; problems with a computer.
;;;
;;; To execute, merely load, reset and run.
;;;======================================================
;;****************
;;* DEFFUNCTIONS *
;;****************
(deffunction ask-question (?question $?allowed-values)
(printout t ?question)
(bind ?answer (read))
(if (lexemep ?answer)
then (bind ?answer (lowcase ?answer)))
(while (not (member ?answer ?allowed-values)) do
(printout t ?question)
(bind ?answer (read))
(if (lexemep ?answer)
then (bind ?answer (lowcase ?answer))))
?answer)
(deffunction yes-or-no-p (?question)
(bind ?response (ask-question ?question yes no y n))
(if (or (eq ?response yes) (eq ?response y))
then TRUE
else FALSE))
;;;************************
;;;* PC System State Rules*
;;;************************
(defrule normal-pc-state-conclusions ""
(declare (salience 10))
(working-state pc normal)
=>
(assert (repair "No repair needed"))
(assert (power-state pc normal))
(assert (boot-state pc success))
(assert (monitor-state monitor on))
)
;;;***************
;;;* QUERY RULES *
;;;***************
(defrule determine-pc-state ""
(not (working-state pc ?))
(not (repair ?))
=>
(if (yes-or-no-p "Does the pc can start (yes/no)? ")
then
(if (yes-or-no-p "Does the pc can run normally(yes/no)? ")
then
(assert (working-state pc normal))
else
(assert (working-state pc does-not-start)))
else
(assert (working-state pc does-not-start))))
(defrule determin-power-state ""
(working-state pc does-not-start)
(not (power-state pc ?))
(not (repair ?))
=>
(if (yes-or-no-p "Does pc pass the power on self test(yes/no)? ")
then
(assert (power-state pc normal))
(assert (boot-state pc fail))
else
(assert (power-state pc irregular))
(assert (boot-state pc fail))))
(defrule determine-power-provider-state ""
(working-state pc does-not-start)
(power-state pc irregular)
(not (repair ?))
=>
(if (not (yes-or-no-p "Is the power indicator light on(yes/no)"))
then
(assert (power-state pc irregular))
(assert (repair "Check the power supply"))
else
(assert (power-state pc normal))))
(defrule determin-monitor-state ""
(working-state pc does-not-start)
(power-state pc normal)
(not (repair ?))
=>
(if (yes-or-no-p "Is there any click noises,but the screen is blank(yes/no)?")
then
(assert (repair "Check the monitor"))
else
(assert (monitor-state monitor on))
(assert (repair "Check the video card"))))
(defrule determin-motherboard-clean-state ""
(working-state pc does-not-start)
(monitor-state monitor on)
(power-state pc irregular)
(not (repair ?))
=>
(if (yes-or-no-p "Is the power supply is working but the indicator is off(yes/no)? ")
then
(assert (mother-board-state pc dirty))
(assert (repair "Pleas clean moterboard and the host so that the conductivity become normal"))
else
(assert (mother-board-state pc clean))))
(defrule determin-boot-state ""
(working-state pc does-not-start)
(monitor-state monitor on)
(power-state pc normal)
(boot-state pc fail)
(not (repair ?))
=>
(if (yes-or-no-p "Does pc can power up but it can boot to operating system(yes/no)? ")
then
(assert (boot-state pc fail))
(assert (repair "first step,you can insert a floppy disk to make a start up disk to boot the operating system"))
else
(assert (boot-state pc success))
(assert (working-state pc normal))))
(defrule determin-boot-mbr-state ""
(working-state pc does-not-start)
(power-state pc normal)
(monitor-state monitor on)
(boot-state pc fail)
(not (repair ?))
=>
(if (yes-or-no-p "Have you fixed the master boot record(yes/no)? ")
then
(assert (mbr-state mbr success))
else
(assert (mbr-state mbr fail))
(assert (repair "You can go to the safe mode to recover this corrupt"))))
(defrule determin-boot-ini-state ""
(working-state pc does-not-start)
(power-state pc normal)
(monitor-state monitor on)
(boot-state pc fail)
(mbr-state mbr success)
(not (repair ?))
=>
(if (yes-or-no-p "Have you fixed the boot.ini corrupt(yes/no)?")
then
(assert (boot-ini-state boot-ini normal))
else
(assert (boot-ini-state boot-ini fail))
(assert (repair "Please repair boot.ini file by insert the XP system dvd"))))
(defrule determin-in-place-upgrade-state ""
(working-state pc does-not-start)
(monitor-state monitor on)
(power-state pc normal)
(boot-state pc failed)
(mbr-state pc success)
(boot-ini-state pc normal)
(mother-board pc clean)
(not (repair ?))
=>
(if (yes-or-no-p "Do the suggesstion metion above work(yes/no) ?")
then
(assert (working-state pc normal))
else
(assert (repair "If you try all suggestion above but they don't work,you can reinstall your operation system by in place upgrade"))))
(defrule no-repairs ""
(declare (salience -10))
(not (repair ?))
=>
(assert (repair "Take your computer to a mechanic.")))
;;;****************************
;;;* STARTUP AND REPAIR RULES *
;;;****************************
(defrule system-banner ""
(declare (salience 10))
=>
(printout t crlf crlf)
(printout t "The PC Diagnosis Expert System")
(printout t crlf crlf))
(defrule print-repair ""
(declare (salience 10))
(repair ?item)
=>
(printout t crlf crlf)
(printout t "Suggested Repair:")
(printout t crlf crlf)
(format t " %s%n%n%n" ?item))
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -