; ====================================================== ; | Assignment #1 | ; | | ; | Part1: Programming in CLIPS | ; | | ; | by: Amin Allahyar 8923433030 | ; | | ; | | ; ====================================================== ;;;;;;;;;;;;;;;;;;;;;;;;;;;;; Questions ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; (deffacts question-1 (raw-question 1 can canary fly)) (deffacts question-2 (raw-question 2 color-of canary)) (deffacts question-3 (raw-question 3 can ostrich fly)) ;;;;;;;;;;;;;;;;;;;;;;;;;;;;; Initialization ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; (defglobal ?*q-number* = 0) ;;;;;;;;;;;;;;;;;;;;;;;;;;;;; Knowledge Base ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; (deffacts knowledge-base (have animal skin) (have fish gills) (have bird wings) (do fish lay-eggs) (do bird lay-eggs) (dont mammal lay-eggs) (dont shark lay-eggs) (is shark dangerous) (is salmon delicious) (is ostrich tall) (can bird fly) (can fish swim) (can ostrich walk) (cant ostrich fly) (is-kind-of fish animal) (is-kind-of bird animal) (is-kind-of mammal animal) (is-kind-of shark fish) (is-kind-of salmon fish) (is-kind-of canary bird) (is-kind-of ostrich bird) (color-is canary yellow) ) ;;;;;;;;;;;;;;;;;;;;;;;;;;;;; Inference Engine ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; (defrule question-feeder "" (not (question $?)) ?raw<-(raw-question ?*q-number* $?rest) ;?raw<-(raw-question ?y&:(> ?y ?*q-number*) $?rest) => (bind ?*q-number* (+ ?*q-number* 1)) (retract ?raw) (assert (question $?rest)) ) (defrule can-fly "" ?question <-(question can ?animal-name fly) (can ?animal-name fly) => (retract ?question) (printout t "Yes, '" ?animal-name "' can fly!" crlf) ) (defrule can-subtype-fly "" ?question <-(question can ?animal-name fly) (is-kind-of ?animal-name ?animal-type) (can ?animal-type fly) => (retract ?question) (printout t "Yes, '" ?animal-type "' can fly, and '" ?animal-name "' is a '" ?animal-type "'" crlf) ) (defrule can-subsubtype-fly "" ?question <-(question can ?animal-name fly) (is-kind-of ?animal-name ?animal-subtype) (is-kind-of ?animal-subtype ?animal-type) (can ?animal-type fly) => (retract ?question) (printout t "Yes, '" ?animal-type "' can fly, and '"?animal-subtype "' is a '" ?animal-type "', also '" ?animal-name "' is a '" ?animal-subtype "'" crlf) ) (defrule cant-fly "" (declare (salience -100)) ?question <-(question can ?animal-name fly) (cant ?animal-name fly) => (retract ?question) (printout t "'" ?animal-name "' cant fly." crlf) ) (defrule error-can-fly "" (declare (salience -100)) (question can ?animal-name fly) => (printout t "There is no information about flying '" ?animal-name "'" crlf) ) (defrule color-of "" ?question <-(question color-of ?animal-name) (color-is ?animal-name ?color) => (retract ?question) (printout t "The color of '" ?animal-name "' is '" ?color "'" crlf) ) (defrule error-color-of "" (declare (salience -100)) (question color-of ?animal-name) => (printout t "There is no information about color of '" ?animal-name "'" crlf) )