Documentos de Académico
Documentos de Profesional
Documentos de Cultura
Introduction
CLIPS is a tool for building expert systems
Originally developed by the Software Technology Branch (STB) at NASA Johnson Space Center First release in 1986
Web location
http://www.ghg.net/clips/CLIPS.html
November 2, 2004 AI: CLIPS Language Tutorial 2
Introduction
CLIPS was designed to facilitate the development of software to model human knowledge
Facts Rules Deffunctions and generic functions Object oriented programming
November 2, 2004
November 2, 2004
Facts
Fact Assertion
(assert (play Ivan tennis)) (assert (duck)) (assert (chair red))
As facts are entered into the KB, they are assigned a Fact Index
(retract 1)
Removes fact 1 from the KB
(clear)
Removes all facts from the fact base and KB
November 2, 2004 AI: CLIPS Language Tutorial 5
Facts
Fact Assertion
(facts)
Dump the fact base Fact identifier time tag
f-0 f-1
Special fact
(initial-fact) Is always F0 and is used to match the first/start rules
November 2, 2004 AI: CLIPS Language Tutorial 6
Facts
deffacts is a way of initializing the fact base (group of facts) Example:
(deffacts tennis-players people who play tennis (athelete Ivan very-good) (play Ivan tennis) (athelete Martina very-good) (play Martina tennis))
Will cause the fact base to be initialized with the facts + (initial-fact)
November 2, 2004 AI: CLIPS Language Tutorial 7
Facts
When (reset) is entered, the result is
f-0 f-1 f-2 f-3 f-4 (initial-fact) (athelete Ivan very-good) (play Ivan tennis) (athelete Martina very-good) (play Martina tennis)
November 2, 2004
Rules
Syntax
(defrule r-name
pattern-1 pattern-n => action-1 action-m)
November 2, 2004 AI: CLIPS Language Tutorial 9
comment
Rules
r-name is the rule name comment must be surrounded by quotes pattern-i is the antecedent pattern action-j is the consequent pattern
November 2, 2004
10
Rules
The agenda is the list of rules that have been matched and are waiting execution (agenda) will print out the rules The agenda is prioritized by salience value
Salience is specified by the programmer and is from 10000 to 10000 Default is 0 if (declare (salience 25)) is not in rule e.g. Rules are selected for firing by salience Two rules of same salience use LIFO to fire
AI: CLIPS Language Tutorial 11
November 2, 2004
Rules
(pprule r-name) will pretty print out the rule (excise r-name) will remove a rule from the system
November 2, 2004
12
Variables
Variables start with a ?
E.g. ?age Bindings are valid within a rule only
November 2, 2004
13
November 2, 2004
14
What facts are retracted? What facts are kept? What facts are generated? Changing harry to ?person and August-15 to ?date will generalize this rule
15
Firing Rules
November 2, 2004
16
Firing Rules
November 2, 2004
17
November 2, 2004
18
November 2, 2004
19
Wildcard Matching
?
matches one
$?
matches any number
$?name
match and bind
November 2, 2004 AI: CLIPS Language Tutorial 20
Examples
?x ?location ?sensor ?room ?color ?size
November 2, 2004
21
November 2, 2004
22
Wildcard Matching
Example (name ? ?Kennedy)
will match will match
(name John Fitzgerald Kennedy)
(name ? $? SMITH)
(name John SMITH) (name Suzie Jane SMITH) (name John James Jones SMITH) (name SMITH) (name John Jones SMITH Rogers)
$?name is the same as the previous but the matches are bound to $?name
November 2, 2004
23
Wildcard Matching
November 2, 2004
24
Field Constraints
Negation ~
(defrule apply-heat
(temperature water ~boil) => (adjust heat maximum); a function call (printout t Turn the heat to the maximum setting crlf))
November 2, 2004
25
Field Constraints
OR |
(temperature water cold|cool|warm) => (adjust heat maximum); a function call (printout t Turn the heat to a medium setting crlf))
(defrule apply-heat
November 2, 2004
26
Field Constraints
AND &
(temperature water ?temp&hot|boil)
November 2, 2004
27
Mathematical Operators
Uses prefix notation as in Lisp
(+ 3 4) (+ (* 3 4) (* 5 6))
put
(answer 12)
Systematic Manner
November 2, 2004
29
Templates
November 2, 2004
30