Professional Documents
Culture Documents
2 Clips
2 Clips
CLIPS 1
Course Overview
Introduction CLIPS
Pattern
Matching
Knowledge
Expert
Expert
System Design
ES Life Cycle
Reasoning
System Implementation
Salience, Rete Algorithm
Reasoning
with Uncertainty
Expert
CLIPS 2
Overview CLIPS
Motivation Objectives CLIPS
Variables
and Pattern
Matching
Background
Execution
of Programs
Facts
and Rules
Important
Concepts and
CLIPS 3
Logistics
http://www.csc.calpoly.edu/~fkurfess
CLIPS 4
Bridge-In
CLIPS 5
Pre-Test
CLIPS 6
Motivation
CLIPS
rule-based,
it
illustrates many of the concepts and methods used in other ES shells it allows the representation of knowledge, and its use for solving suitable problems
CLIPS 7
Objectives
be
familiar with the important concepts and methods used in rule-based ES shells
facts, rules, pattern matching, agenda, working memory, forward chaining
understand
apply
rule-based techniques to simple examples evaluate the suitability of rule-based systems for specific tasks dealing with knowledge
CLIPS 8
Introduction
CLIPS
stands for
forward-chaining
starting
pattern-matching
Rete
knowledge-based
empty
system shell
multi-paradigm
rule-based,
programming language
CLIPS 10
of CLIPS
influenced
by OPS5 and ART implemented in C for efficiency and portability developed by NASA, distributed & supported by COSMIC runs on PC, Mac, UNIX, VAX VMS
CLIPS
a
top-level interpreter production rule interpreter object oriented programming language LISP-like procedural language
2002 Franz J. Kurfess [Jackson 1999] CLIPS 11
Components of CLIPS
rule-based
can
language
create a fact list can create a rule set an inference engine matches facts against rules
object-oriented
can
language (COOL)
define classes can create different sets of instances special forms allow you to interface rules and objects
[Jackson 1999]
CLIPS 12
Notation
entered exactly as shown: (example) contents are optional: (example [test]) replace contents by an instance of that type (example <char>) replace with zero or more instances of the type <char>* replace with one or more instances of the type <char>+ (is equivalent to <char> <char>* ) choice among a set of items: true | false
CLIPS 13
pointed brackets (less than / greater than signs) < ... >
star *
plus +
vertical bar |
fields
particularly
float, integer, symbol, string, external address, instance name, instance address
CLIPS 14
string:
e.g. "This is a string" address of external data structure returned by user-defined functions
external address
CLIPS
double-click on icon, or type program name (CLIPS) system prompt appears: CLIPS>
exiting
CLIPS
enclosing parentheses are important; they indicate a command to be executed, not just a symbol
CLIPS 16
Facts
elementary
symbolic field used to access the information often serves as identifier for the fact
slots
symbolic fields with associated values used to define the structure of a fact
deftemplate
deffacts
CLIPS 17
Examples of Facts
ordered
fact
fact
person "deftemplate example name) age) eye-color) hair-color))
CLIPS 18
Defining Facts
Facts
can be asserted
can be listed
can be retracted
Instances
CLIPS 20
Initial Facts
(deffacts kurfesses "some members of the Kurfess family" (person (name "Franz J. Kurfess") (age 46) (eye-color brown) (hair-color brown)) (person (name "Hubert Kurfess") (age 44) (eye-color blue) (hair-color blond)) (person (name "Bernhard Kurfess") (age 41) (eye-color blue) (hair-color blond)) (person (name "Heinrich Kurfess") (age 38) (eye-color brown) (hair-color blond)) (person (name "Irmgard Kurfess") (age 37) (eye-color green) (hair-color blond)) )
2002 Franz J. Kurfess CLIPS 21
Usage of Facts
adding facts
(assert <fact>+)
deleting facts
(retract
<fact-index>+)
modifying facts
(modify <fact-index> (<slot-name> <slot-value>)+ ) retracts the original fact and asserts a new, modified fact (duplicate <fact-index> (<slot-name> <slot-value>)+ ) adds a new, possibly modified fact (facts) prints the list of facts (watch facts) automatically displays changes to the fact list
duplicating facts
inspection of facts
CLIPS 22
Rules
general
format
(defrule <rule name> ["comment"] <patterns>* ; left-hand side (LHS) ; or antecedent of the rule => <actions>*) ; right-hand side (RHS) ; or consequent of the rule
CLIPS 23
Rule Components
rule
header
keyword, name of the rule, optional comment string to be matched against facts
defrule
rule
rule rule
antecedent (LHS)
arrow
antecedent and consequent
patterns
separates
consequent (RHS)
to be performed when the rule fires
actions
CLIPS 24
Examples of Rules
simple
rule
(defrule birthday-FJK (person (name "Franz J. Kurfess") (age 46) (eye-color brown) (hair-color brown)) (date-today April-13-02) => (printout t "Happy birthday, Franz!") (modify 1 (age 47)) )
CLIPS 25
limited:
LHS
must match facts exactly facts must be accessed through their index number changes must be stated explicitly
can
CLIPS 26
variable
bindings
variables in a rule pattern (LHS) are bound to the corresponding values in the fact, and then can be used on the RHS all occurrences of a variable in a rule have the same value the left-most occurrence in the LHS determines the value bindings are valid only within one rule
access
to facts
variables can be used to make access to facts more convenient: ?age <- (age harry 17)
CLIPS 27
Wildcards
question
mark ?
any single field within a fact
matches
multi-field
matches
wildcard $?
zero or more fields in a fact
CLIPS 28
Field Constraints
not constraint ~
the
field can take any value except the one specified alternative values, one of which must match
or constraint |
specifies
value of the field must match all specified values mostly used to place constraints on the binding of a variable
CLIPS 29
Mathematical Operators
operators (+,-,*,/) and many functions (trigonometric, logarithmic, exponential) are supported prefix notation no built-in precedence, only left-to-right and parentheses test feature
basic
pattern
connectives
multiple patterns in the LHS are implicitly AND-connected patterns can also be explicitly connected via AND, OR, NOT
user-defined
functions
external functions written in C or other languages can be integrated Jess is tightly integrated with Java
CLIPS 30
Examples of Rules
more
complex rule (defrule find-blue-eyes (person (name ?name) (eye-color blue)) => (printout t ?name " has blue eyes." crlf))
CLIPS 31
Using Templates
(deftemplate student a student record (slot name (type STRING)) (slot age (type NUMBER) (default 18))) CLIPS> (assert (student (name fred))) (defrule print-a-student (student (name ?name) (age ?age)) => (printout t name? is ?age) )
[Jackson 1999]
CLIPS 33
[Jackson 1999]
CLIPS 34
a special fact
[Jackson 1999]
CLIPS 35
(defrule pick-a-chore (today is ?day) (chore is ?job) => (assert (do ?job on ?day)) )
if
[Jackson 1999]
CLIPS 36
[Jackson 1999]
CLIPS 37
matching
of wild cards
? ? monday) ? on ?) ? ? ?day) $?) $? monday) ?chore $?when)
[Jackson 1999] CLIPS 38
(deffunction function-name (arg ... arg) action ... action) (deffunction hypotenuse (?a ?b) (sqrt (+ (* ?a ?a) (* ?b ?b)))) (deffunction initialize () (clear) (assert (today is sunday)))
[Jackson 1999]
CLIPS 39
an instance of CAR
[Jackson 1999]
CLIPS 40
Person
Man
Woman
Jack
2002 Franz J. Kurfess [Jackson 1999]
Jill
CLIPS 41
Managing Instances
Commands
to display instances
CLIPS> (instances) [corvette] of car CLIPS> (send [corvette] print) [corvette] of car (made-by chevrolet)
Command
an instance
all instances
CLIPS> (unmake-instance *)
resetting
Manipulation of Constructs
show
list of constructs
prints a list of the respective constructs
text of constructs
displays the text of the construct (``pretty print'')
deleting
constructs
clearing
(clear)
removes all constructs and adds the initial facts to the CLIPS environment
CLIPS 44
Input / Output
print information (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")
2002 Franz J. Kurfess CLIPS 45
Program Execution
agenda
if
all patterns of a rule match with facts, it is put on the agenda (agenda) displays all activated rules
salience
indicates
priority of rules
refraction
rules
(refresh
Execution of a Program
(reset)
all
previous facts are deleted initial facts are asserted rules matching these facts are put on the agenda
(run
breakpoints
(set-break
stops the execution before the rule fires, continue with (run)
(remove-break (show-breaks)
2002 Franz J. Kurfess
[<rule-name>])
CLIPS 47
Watching
watching
(watch
the execution
(unwatch
<watch-item>)
CLIPS 48
of
facts
for each rule that is fired
rules
message
activations
activated
CLIPS 49
about the program execution (number of rules fired, run time, ... )
compilation
shows
(default)
Defining deftemplate: ... Defining defrule: ... +j=j +j, =j indicates the internal structure of the compiled rules
+j =j
focus
used
User Interface
menu-based
most
version
command-line
all
interface
CLIPS 51
Limitations of CLIPS
single
in
LOOPS, you could arrange rule sets in a hierarchy, embedding one rule set inside another, etc
loose
rules
can communicate with objects via message passing rules cannot easily be embedded in objects, as in Centaur
CLIPS
the
basic control flow is forward chaining to implement other kinds of reasoning you have to manipulate tokens in working memory
[Jackson 1999]
CLIPS 52
Alternatives to CLIPS
JESS
see below has same syntax as CLIPS (both are based on ART) supports goal-driven (i.e., backwards) reasoning has a truth maintenance facility for checking consistency can be integrated with C++ and dBase new extension RETE++ can generate C++ header files
Eclipse
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
[Jackson 1999]
CLIPS 53
JESS
JESS
stands for Java Expert System Shell it uses the same syntax and a large majority of the features of CLIPS tight integration with Java
can
be invoked easily from Java programs can utilize object-oriented aspects of Java
some
COOL
CLIPS 54
Post-Test
CLIPS 55
CLIPS Summary
notation
similar to Lisp, regular expressions (deftemplate), (deffacts), assert / retract (defrule ...), agenda
facts
rules
input/output
program execution
user interface
CLIPS 57
agenda antecedent assert backward chaining consequent CLIPS expert system shell fact field forward chaining function inference inference mechanism instance If-Then rules JESS
knowledge base knowledge representation pattern matching refraction retract rule rule header salience template variable wild card
CLIPS 58
Summary CLIPS
CLIPS 59
CLIPS 60