Week9 ExpertSystems Programming Part2
Week9 ExpertSystems Programming Part2
Lectures of Week 9:
Expert Systems Programming and Shells – Part 2
Mathematical Operators in CLIPS
• question mark ?
– matches any single field within a fact
• multi-field wildcard $?
– matches zero or more fields in a fact
Example of Rule with Variable &
Pattern Matching
(defrule find-brown-eyes
(person (name ?name)
(eye-color brown))
=>
(printout t ?name " has brown
eyes." crlf))
Variables & Pattern Matching
(defrule pick-a-chore
(today is ?day)
(chore is ?job)
=>
(assert (do ?job on ?day))
)
(defrule print-a-student
(student (name ?name) (age ?age))
=>
(printout t ?name " is " ?age crlf ))
Retracting Facts from a Rule
(defrule do-a-chore
(today is ?day)
?chore <- (do ?job on ?day)
=>
(printout t ?job " done " crlf)
(retract ?chore) )
(deffunction initialize ()
(clear)
(assert (today is sunday)))
• print information Input / Output
(printout <logical-device> <print-items>*)
» logical device frequently is the standard output device t
(terminal)
• terminal input
(read [<logical-device>]), (readline [<logical-
device>])
» read an atom or string from a logical device
» the logical device can be a file which must be open
• open / close file
(open <file-name> <file-ID> [<mode>]), (close [<file-
ID>])
» open /close file with <file-id> as internal name
• load / save constructs from / to file
(load <file-name>), (save <file-name>)
» backslash \ is a special character and must be ``quoted''
(preceded by a backslash \)
• e.g. (load "B:\\clips\\example.clp")
Input / Output
• Use of read – Getting data from user
• Example 1: (Refer Tutorial 2)
(defrule what-is-child
(animal ?name)
(not (child-of ?name ?))
=>
(printout t "What do you call the child of a " ?name "?")
(assert (child-of ?name (read))))
Note: Please see the facts for this rule on next slide.
Input / Output
• Example of use of read – Getting data from user
Facts:
(deffacts startup
(animal dog) (animal duck) (animal turtle)
(warm-blooded dog) (warm-blooded cat)
(warm-blooded duck)
(lays-eggs duck) (lays-eggs turtle)
(child-of dog puppy) (child-of cat kitten)
(child-of turtle hatchling)
)
Input / Output
• Use of read – Getting data from user
• Example 2: (Refer Tutorial 2)
(defrule are-lights-working
(not (lights-working ?))
=>
(printout t "Are the car's lights working (yes or no)?")
(definstances Cars
(c1 of CAR (value 5000.0))
(c2 of LUXURY (color red) (value 15000.)))
[Jackson 1999]
Concrete & Abstract Classes
• some classes only exist for inheritance
purposes
Person
Man Woman
Jack Jill
[Jackson 1999]
Managing Instances
• (make-instance c3 of CAR (color blue))
[Jackson 1999]
Clearing & Resetting Instances
• deleting an instance
CLIPS> (send [c3] delete)
• menu-based version
– most relevant commands are available
through windows and menus
• command-line interface
– all commands must be entered at the
prompt
– (don’t forget enclosing parentheses)
Alternatives to CLIPS
• JESS
– see next
• Eclipse
– enhanced, commercial variant of CLIPS
– has same syntax as CLIPS (both are based on ART)
– supports goal-driven (i.e., backwards) reasoning, where as CLIPS
supports forward chaining
– can be integrated with C++ and dBase
• NEXPERT OBJECT
– another rule- and object-based system
– has facilities for designing graphical interfaces
– has a ‘script language’ for designing user front-end
– written in C, runs on many platforms, highly portable
JESS
• JESS stands for Java Expert System Shell