📄 computer.clp
字号:
;;;======================================================
;;; Computer Problem Identification Expert System
;;;
;;; A simple expert system which attempts to identify
;;; the problem about the computer.
;;;
;;; CLIPS Version 6.0 Example
;;;
;;; To execute, merely load, reset, and run.
;;; Answer questions yes or no.
;;;======================================================
;;;***************************
;;;* DEFTEMPLATE DEFINITIONS *
;;;***************************
(deftemplate rule
(multislot if)
(multislot then))
;;;**************************
;;;* INFERENCE ENGINE RULES *
;;;**************************
(defrule propagate-goal ""
(goal is ?goal)
(rule (if ?variable $?)
(then ?goal ? ?value))
=>
(assert (goal is ?variable)))
(defrule goal-satified ""
(declare (salience 30))
?f <- (goal is ?goal)
(variable ?goal ?value)
(answer ? ?text ?goal)
=>
(retract ?f)
(format t "%s%s%n" ?text ?value))
(defrule remove-rule-no-match ""
(declare (salience 20))
(variable ?variable ?value)
?f <- (rule (if ?variable ? ~?value $?))
=>
(retract ?f))
(defrule modify-rule-match ""
(declare (salience 20))
(variable ?variable ?value)
?f <- (rule (if ?variable ? ?value and $?rest))
=>
(modify ?f (if ?rest)))
(defrule rule-satisfied ""
(declare (salience 20))
(variable ?variable ?value)
?f <- (rule (if ?variable ? ?value)
(then ?goal ? ?goal-value))
=>
(retract ?f)
(assert (variable ?goal ?goal-value)))
(defrule ask-question-no-legalvalues ""
(declare (salience 10))
(not (legalanswers $?))
?f1 <- (goal is ?variable)
?f2 <- (question ?variable ? ?text)
=>
(retract ?f1 ?f2)
(format t "%s " ?text)
(assert (variable ?variable (read))))
(defrule ask-question-legalvalues ""
(declare (salience 10))
(legalanswers ? $?answers)
?f1 <- (goal is ?variable)
?f2 <- (question ?variable ? ?text)
=>
(retract ?f1)
(format t "%s " ?text)
(printout t ?answers " ")
(bind ?reply (read))
(if (member (lowcase ?reply) ?answers)
then (assert (variable ?variable ?reply))
(retract ?f2)
else (assert (goal is ?variable))))
;;;***************************
;;;* DEFFACTS KNOWLEDGE BASE *
;;;***************************
(deffacts knowledge-base
(goal is type.p)
(legalanswers are yes no)
(rule (if power is yes)
(then poweron is on))
(rule (if power is no)
(then type.p is " the power is off."))
(question power is "Does your computer have been turned on?")
(rule (if poweron is on and
outlet is yes)
(then outleton is on))
(rule (if poweron is on and
outlet is no)
(then type.p is "your outlet is out of power."))
(question outlet is "Check the wall outlet for power.If the outlet has power.?")
(rule (if outleton is on and
powercord is yes)
(then powercordok is ok))
(rule (if outleton is on and
powercord is no)
(then type.p is "the power cord is broken."))
(question powercord is "Check the power cord itself from wall to computer.If it is all right?")
(rule (if powercordok is ok and
sup is yes)
(then supok is ok))
(rule (if powercordok is ok and
sup is no)
(then type.p is "the power supply may be broken."))
(question sup is "Check the Power Supply inside the System Unit.Is it ok?")
(rule (if supok is ok and
repsup is yes)
(then type.p is " your power supply must be broken."))
(rule (if supok is ok and
repsup is no)
(then repsupok is ok))
(question repsup is "Replace the Power Supply rather than trying to repair it.Does it work?")
(rule (if repsupok is ok and
mon is yes)
(then monok is ok))
(rule (if repsupok is ok and
mon is no)
(then type.p is "your monitor needs repairing."))
(question mon is "If the system make those click noises,but the screen is blank, check the Monitor.Is it all right?")
(rule (if monok is ok and
vdc is yes)
(then vdcok is ok))
(rule (if monok is ok and
vdc is no)
(then type.p is "your Video card is not all right."))
(question vdc is "If the monitor proves to be good,check the Video Card,even in a new system.Is it ok?")
(rule (if vdcok is ok and
startd is yes)
(then type.p is "your systerm failed in the start stage.One of the first things you should reach for when troubleshooting a Windows XP boot problem is a Windows startup disk. This floppy disk can come in handy if the problem is being caused when either the startup record for the active partition or the files that the operating system uses to start Windows have become corrupted. To create a Windows startup disk, insert a floppy disk into the drive of a similarly configured, working Windows XP system, launch My Computer, right-click the floppy disk icon, and select the Format command from the context menu. When you see the Format dialog box, leave all the default settings as they are and click the Start button. Once the format operation is complete, close the Format dialog box to return to My Computer, double-click the drive C icon to access the root directory, and copy the following three files to the floppy disk.
"))
(rule (if vdcok is ok and
startd is no)
(then startdok is nok))
(question startd is "Use a windows startup disk.Does it work?")
(rule (if startdok is nok and
lkgc is yes)
(then type.p is "The last time you boot the computer incorrectly."))
(rule (if startdok is nok and
lkgc is no)
(then lkgcok is nok))
(question lkgc is "use last known good configuration.Does it work?")
(rule (if lkgcok is nok and
sysre is yes)
(then type.p is "The system is broken."))
(rule (if lkgcok is nok and
sysre is no)
(then sysok is nok))
(question sysre is "Use system restore.Does it work?")
(rule (if sysok is nok and
rec is yes)
(then type.p is "you need to recovery from something else"))
(rule (if sysok is nok and
rec is no)
(then recok is nok))
(question rec is "Use recovery consle.Does it work?")
(rule (if recok is nok and
boot is yes)
(then type.p is "Your boot.ini is broken."))
(rule (if recok is nok and
boot is no)
(then bootok is nok))
(question boot is "Fix a corrupt Boot.ini.Does it work?")
(rule (if bootok is nok and
sec is yes)
(then type.p is "your sector is broken."))
(rule (if bootok is nok and
sec is no)
(then secok is nok))
(question sec is "Fix a corrupt parition boot sector.Does it work?")
(rule (if secok is nok and
mas is yes)
(then type.p is "the master boot record is broken."))
(rule (if secok is nok and
mas is no)
(then masok is nok))
(question mas is "Fix a corrupt master boot record.Does it work?")
(rule (if masok is nok and
restart is yes)
(then type.p is "your computer stuck in reboot cycle."))
(rule (if masok is nok and
restart is no)
(then restartok is ok))
(question restart is "Disable automatic restart.Does it work?")
(rule (if restartok is ok and
bac is yes)
(then type.p is "your system should be restore for it is destroyed."))
(rule (if restartok is ok and
bac is no)
(then bacok is nok))
(question bac is "Restore from a backup.Dose it work?")
(rule (if bacok is nok and
per is yes)
(then type.p is "you need to upgrade it."))
(rule (if bacok is nok and
per is no)
(then type.p is "in fact, I do not know what's wrong. You should informed the factory."))
(question per is "Perform an in-place upgrade.Does it work?")
(answer is "I think your problem is: " type.p))
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -