foo.clp
CLIPS Source File


;;;*************************** ;;;* 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 "%n%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-legalvalues "" (declare (salience 10)) ?f1 <- (goal is ?variable) ?f2 <- (question ?variable ? ?text ANSWERS $?answers LEGALS $?legals) => (retract ?f1) (format t "%n%s%n" ?text) (loop-for-count (?cnt 1 (length ?answers)) do (format t "%s%n" (nth$ ?cnt ?answers))) (format t "==> ") (bind ?reply (read)) (if (member ?reply ?legals) then (assert (variable ?variable ?reply)) (retract ?f2) else (assert (goal is ?variable)))) (deffacts knowledge-base (goal is type.computer) (rule (if console is yes and primary.app is 4) (then type.computer is "a game console")) (rule (if console is yes and primary.app is 5) (then type.computer is "WebTV")) (rule (if workstation is yes and expertise is 1) (then type.computer is "a Macintosh")) (rule (if workstation is yes and price is 4 and primary.app is 2) (then type.computer is "an SGI Workstation")) (rule (if workstation is yes and service is 1) (then type.computer is "an IBM PC")) (rule (if workstation is yes and service is 3 and expertise is 3) (then type.computer is "components to custom build a PC yourself")) (rule (if workstation is yes and price is 3 and service is 2) (then type.computer is "a Compaq or HP PC")) (rule (if workstation is yes and price is 3 and service is 3) (then type.computer is "a Compaq or HP PC")) (rule (if workstation is yes and price is 2 and service is 2) (then type.computer is "a DELL PC")) (rule (if workstation is yes and price is 2 and service is 3) (then type.computer is "a DELL PC")) (rule (if unix.server is yes and performance is 3) (then type.computer is "a DEC Alpha Server")) (rule (if unix.server is yes and service is 1) (then type.computer is "an IBM AIX Server")) (rule (if unix.server is yes and service is 2) (then type.computer is "an HP or Sun UNIX server")) (rule (if unix.server is yes and service is 3) (then type.computer is "an HP or Sun UNIX server")) (rule (if pc.server is yes and service is 1) (then type.computer is "an IBM PC Server")) (rule (if pc.server is yes and service is 3) (then type.computer is "components to custom build a PC server yourself")) (rule (if pc.server is yes and price is 2 and service is 2) (then type.computer is "a low end DELL PC Server")) (rule (if pc.server is yes and price is 3 and service is 2) (then type.computer is "a DELL, Compaq, or HP PC Server")) (rule (if pc.server is yes and price is 4 and service is 2) (then type.computer is "a DELL, Compaq, or HP PC Server")) (rule (if server is yes and price is 1) (then type.computer is "go buy a used computer off someone")) (rule (if console is yes and primary.app is 1) (then type.computer is "a used PC")) (rule (if console is yes and primary.app is 2) (then type.computer is "a used PC")) (rule (if console is yes and primary.app is 3) (then type.computer is "a used PC")) (rule (if primary.use is 1 and price is 4) (then workstation is yes)) (rule (if primary.use is 1 and price is 3) (then workstation is yes)) (rule (if primary.use is 1 and price is 2) (then workstation is yes)) (rule (if primary.use is 1 and price is 1) (then console is yes)) (rule (if primary.use is 2) (then server is yes)) (rule (if server is yes and expertise is 3 and price is 4) (then unix.server is yes)) (rule (if server is yes and expertise is 2) (then pcserver is yes)) (rule (if server is yes and expertise is 1) (then pcserver is yes)) (rule (if server is yes and price is 3) (then pc.server is yes)) (rule (if server is yes and price is 2) (then pc.server is yes)) (rule (if server is yes and price is 1) (then pc.server is yes)) (question primary.use is "What will the primary use be?" ANSWERS "1. Workstation" "2. Server" LEGALS 1 2) (question primary.app is "What will the main application be?" ANSWERS "1. development" "2. graphics" "3. office software" "4. games" "5. internet" LEGALS 1 2 3 4 5) (question price is "What price range a you looking for?" ANSWERS "1. < $1000" "2. < $2000" "3. < $5000" "4. not an issue" LEGALS 1 2 3 4) (question expertise is "What level of expertise are you?" ANSWERS "1. beginner" "2. power user" "3. God's gift to computers" LEGALS 1 2 3) (question service is "What type of service would you like?" ANSWERS "1. come fix this" "2. send it back to fix" "3. I'll fix it" LEGALS 1 2 3) (question performance is "What performance would you like?" ANSWERS "1. low end" "2. middle of the road" "3. blow me away!" LEGALS 1 2 3) (answer is "You should probably buy " type.computer))