Professional Documents
Culture Documents
Introduction To CLIPS
Introduction To CLIPS
CLIPS
Objectives
2
Objectives
3
Objectives
4
What is CLIPS?
5
Other CLIPS Characteristics
6
CLIPS Characteristics
7
CLIPS Notation
8
CLIPS Notation
9
Fields
10
Numeric Fields
11
Symbol Fields
12
String Fields
13
Address Fields
14
Entering / Exiting CLIPS
15
Facts and CLIPS
16
Example Fact in CLIPS
17
Deftemplate
18
Deftemplate General Format
19
Deftemplate vs. Ordered Facts
20
Adding Facts
• CLIPS store all facts known to it in a fact list.
• To add a fact to the list, we use the assert command.
21
Displaying Facts
• CLIPS> (facts)
22
Removing Facts
23
Modifying Facts
• Slot values of deftemplate facts can be modified using
the modify command:
24
Results of Modification
25
Watch Command
26
Deffacts Construct
27
The Components of a Rule
28
Rule Components
29
Rule Components
30
Analysis of the Rule
31
Analysis of Rule
32
The Agenda and Execution
33
Execution
34
What is on the Agenda?
36
Commands
37
Commands
• (printout <logical-name> <print-
items>*)
<logical-name> indicates the output destination
of the command (for example, printer, screen,
etc)
Ex: (printout t "his name is ahmad" crlf)
t: is defined to be the screen and could be
defined to be another output device.
38
Other Commands
39
•Example (saving facts):
CLIPS> (facts)
f-0 (initial-fact)
f-1 (fire second)
f-2 (fire third)
For a total of 3 facts.
CLIPS> (save-facts “C:/myfacts.dat”)
TRUE
CLIPS>
(initial-fact)
(fire second)
(fire third)
40
•Example (loading facts):
CLIPS> (facts)
CLIPS> (load-facts “C:/myfacts.dat”)
TRUE
CLIPS>
f-0 (initial-fact)
f-1 (fire second)
f-2 (fire third)
For a total of 3 facts.
CLIPS>
41
Other Commands
• (set-break <rule-name>)
this command will put a break point at <rule-
name>.
• (show-breaks): list all break points.
• (remove-break [<rule-name>])
If <rule-name> is provided then it will removes the
break point in it, otherwise it will removes all
break points.
42
Example 1:
CLIPS> (defrule first => (assert (fire second)))
CLIPS> (rules)
first
For a total of 1 defrule.
CLIPS> (defrule second (fire second) => (assert (fire third)))
CLIPS> (defrule third (fire third) =>)
CLIPS> (agenda)
0 first: f-0
For a total of 1 activation.
CLIPS> (watch rules)
CLIPS> (reset)
CLIPS> (facts)
f-0 (initial-fact)
For a total of 1 fact.
CLIPS> (run)
FIRE 1 first: f-0
FIRE 2 second: f-1
FIRE 3 third: f-2
43
Example 2 (set break points):
CLIPS> (defrule first => (assert (fire second)))
CLIPS> (defrule second (fire second) => (assert (fire
third)))
CLIPS> (defrule third (fire third) =>)
CLIPS> (rules)
first
second
third
For a total of 3 defrules.
CLIPS> (agenda)
0 first: f-0
For a total of 1 activation.
CLIPS> (set-break second)
CLIPS> (set-break third)
CLIPS> (show-breaks)
second
third
44
CLIPS> (watch rules)
CLIPS> (reset)
CLIPS> (show-breaks)
second
third
CLIPS> (facts)
f-0 (initial-fact)
For a total of 1 fact.
CLIPS> (run)
FIRE 1 first: f-0
Breaking on rule second.
CLIPS> (run)
FIRE 1 second: f-1
Breaking on rule third.
CLIPS> (run)
FIRE 1 third: f-2
CLIPS>
45
Commenting and Variables
46
CLIPS> (deftemplate person (slot name )(slot eyes))
CLIPS> (defrule find-blue-eyes (person (name ?name)(eyes blue))
=> (printout t ?name " has blue eyes" crlf))
CLIPS> (rules)
find-blue-eyes
For a total of 1 defrule.
CLIPS> (assert (person (name jane)(eyes green))
(person (name jack)(eyes blue)))
<Fact-1>
CLIPS> (facts)
f-0 (person (name jane) (eyes green))
f-1 (person (name jack) (eyes blue))
For a total of 2 facts.
CLIPS> (agenda)
0 find-blue-eyes: f-4
For a total of 1 activation.
CLIPS> (run)
jack has blue eyes
CLIPS>
47
Fact Addresses, Single-Field
Wildcards, and Multifield Variables
• A variable can be bound to a fact address of a
fact matching a particular pattern on the LHS of a
rule by using the pattern binding operator “<-”.
• Single-field wildcards can be used in place of
variables when the field to be matched against
can be anything and its value is not needed later
in the LHS or RHS of the rule.
• Multifield variables and wildcards allow
matching against more than one field in a pattern.
48
Example (fact address):
49
Summary
50
Summary
51
Summary
• Refraction prevents old facts from activating
rules.
• Variables are used to receive information from
facts and constrain slot values when pattern
matching on the LHS of a rule.
• Variables can store fact addresses of patterns on
the LHS of a rule so that the fact bound to the
pattern can be retracted on the RHS of the rule.
• We also looked at single-field wildcards and
multifield variables.
52