110 likes | 288 Views
Artificial Intelligence Lecture No. 20 . Dr. Asad Ali Safi Assistant Professor, Department of Computer Science, COMSATS Institute of Information Technology (CIIT) Islamabad, Pakistan. Summary of Previous Lecture. Reopen Rule Print out Variables . Today’s Lecture. Be Assertive
E N D
Artificial IntelligenceLecture No. 20 Dr. Asad Ali Safi Assistant Professor, Department of Computer Science, COMSATS Institute of Information Technology (CIIT) Islamabad, Pakistan.
Summary of Previous Lecture • Reopen • Rule • Print out • Variables
Today’s Lecture • Be Assertive • variable more than once • Retraction • single-field wildcard
Be Assertive • One common use of variables is to match a value on the LHS and then assert this bound variable on the RHS. For example, enter (defrule make-quack (duck-sound ?sound) => (assert (sound-is ?sound)))
variable more than once • Be sure to do a (reset) and assert (duck-sound quack) again. (defrule make-quack (duck-sound ?sound) => (assert (sound-is ?sound ?sound))) • When the rule fires, it will produce (sound-is quack quack) since the variable ?sound is used twice.
(duckshoot ?hunter ?who) CLIPS> (clear) CLIPS> (defrulewhohunt (duckshoot ?hunter ?who) => (printout t ?hunter " shot " ?who crlf)) (assert (duckshoot Brian duck))
Retraction • Retraction is very useful in expert systems and usually done on the RHS rather than at the top-level. Before a fact can be retracted, it must be specified to CLIPS. To retract a fact from a rule, the fact-address first must be bound to a variable on the LHS.
However, if you want to remove the fact whose contents are, you must first tell CLIPS the address of the fact to be retracted. • The fact-address is specified using the left arrow, "<-". To create this, just type a "<“ symbol followed by a "-"
(defrule get-married ?Ad <- (bachelor Ali) => (printout t “Ali is now happily married " ?Ad crlf) (retract ?Ad)) (assert (bachelor Ali)) (run)
(defrule marriage ?Ad<- (bachelor ?name) => (printout t ?name " is now happily married" crlf) (retract ?Ad) (deffacts good-prospects (bachelor Ali) (bachelor Aslam) (bachelor Abid)) (reset) (run)
Summery of Today’s Lecture • Be Assertive • variable more than once • Retraction • single-field wildcard