Академический Документы
Профессиональный Документы
Культура Документы
COMP 4200:
Expressions, Constraints
Concepts, Notation, Usage
3. Knowledge Representation 7. Expert System Design
Expert Systems Semantic Nets, Frames,
Logic
XPS Life Cycle
8. Expert System
4. Reasoning and Inference Implementation
Dr. Christel Kemke Predicate Logic, Inference Salience, Rete Algorithm
Methods, Resolution 9. Expert System Examples
Department of Computer Science 5. Reasoning with 10. Conclusions and Outlook
University of Manitoba Uncertainty
Probability, Bayesian
Decision Making
1
Objectives Introduction
be familiar with the important concepts and methods used in CLIPS stands for
rule-based XPS shells C Language Implementation Production System
facts, rules, pattern matching, agenda, working memory, forward
chaining forward-chaining
understand the fundamental workings of an XPS shell starting from the facts, a solution is developed
knowledge representation pattern-matching
reasoning
Rete matching algorithm: find ``fitting'' rules and facts
apply rule-based techniques to simple examples
evaluate the suitability of rule-based systems for specific
knowledge-based system shell
tasks dealing with knowledge empty tool, to be filled with knowledge
multi-paradigm programming language
rule-based, object-oriented (Cool) and procedural
2
Notation Tokens and Fields
symbols, characters, keywords
entered exactly as shown: tokens
(example)
square brackets [...] groups of characters with special meaning for CLIPS,
contents are optional: e.g. ( ) \ separated by delimiters
(example [test])
pointed brackets (less than / greater than signs) < ... > (space, tab, Carriage Return, ...)
replace contents by an instance of that type
(example <char>)
fields
star * particularly important group of tokens
replace with zero or more instances of the type
<char>* CLIPS primitive data types
plus + float, integer, symbol, string,
replace with one or more instances of the type external address, instance name, instance address
<char>+ (is equivalent to <char> <char>* )
vertical bar |
choice among a set of items:
true | false
© C. Kemke CLIPS 9 © C. Kemke CLIPS 10
3
Facts Examples of Facts
elementary information items (“chunks”) ordered fact
relation name (person-name Franz J. Kurfess)
symbolic field used to access the information
deftemplate fact
often serves as identifier for the fact
(deftemplate person "deftemplate example”
slots (zero or more)
symbolic fields with associated values (slot name)
deftemplate construct (slot age)
used to define the structure of a fact (slot eye-color)
names and number of slots (slot hair-color))
deffacts
used to define initial groups of facts
4
Initial Facts Usage of Facts
(deffacts kurfesses "some members of the
adding facts
Kurfess family" (assert <fact>+)
(person (name "Franz J. Kurfess") (age 46) deleting facts
(eye-color brown) (hair-color brown)) (retract <fact-index>+)
modifying facts
(person (name "Hubert Kurfess") (age 44) (modify <fact-index> (<slot-name> <slot-value>)+ )
(eye-color blue) (hair-color blond)) retracts the original fact and asserts a new, modified fact
)
© C. Kemke CLIPS 17 © C. Kemke CLIPS 18
5
Examples of Rules Properties of Simple Rules
simple rule very limited:
(defrule birthday-FJK LHS must match facts exactly
(person (name "Franz J. Kurfess") facts must be accessed through their index number
(age 46)
changes must be stated explicitly
(eye-color brown)
(hair-color brown)) can be enhanced through the use of variables
(date-today April-13-02)
=>
(printout t "Happy birthday, Franz!")
(modify 1 (age 47))
)
6
Field Constraints Mathematical Operators
basic operators (+,-,*,/) and many functions
not constraint ~ (trigonometric, logarithmic, exponential) are supported
the field can take any value except the one specified prefix notation
or constraint | no built-in precedence, only left-to-right and parentheses
specifies alternative values, one of which must match test feature
evaluates an expression in the LHS instead of matching a pattern
and constraint & against a fact
the value of the field must match all specified values pattern connectives
multiple patterns in the LHS are implicitly AND-connected
mostly used to place constraints on the binding of a
patterns can also be explicitly connected via AND, OR, NOT
variable
user-defined functions
external functions written in C or other languages can be integrated
Jess is tightly integrated with Java
7
Using Templates An Example CLIPS Rule
(deftemplate student “a student record” (defrule sunday “Things to do on Sunday”
(slot name (type STRING)) (salience 0) ; salience in the interval [-10000, 10000]
(slot age (type NUMBER) (default 18))) (today is Sunday)
(weather is sunny)
CLIPS> (assert (student (name fred)))
=>
(assert (chore wash car))
(defrule print-a-student
(assert (chore chop wood))
(student (name ?name) (age ?age))
=> )
(printout t ?name “ is “ ?age)
)
8
Retracting Facts from a Rule Pattern Matching Details
(defrule do-a-chore one-to-one matching
(today is ?day) ; ?day must have a (do ?job on ?day)
consistent binding (do washing on monday)
?chore <- (do ?job on ?day)
=>
(printout t ?job “ done”) use of wild cards
(retract ?chore) (do ? ? monday)
) (do ? on ?)
(do ? ? ?day)
(do $?)
a variable must be assigned to the item for retraction (do $? monday)
(do ?chore $?when)
9
Concrete & Abstract Classes Managing Instances
some classes only exist for inheritance purposes Commands to display instances
CLIPS> (instances)
[corvette] of car
Person CLIPS> (send [corvette] print)
[corvette] of car
(made-by chevrolet)
Man Woman
Command to group instances (in a file)
(definstances
(corvette of car (made-by chevrolet))
Jack Jill (thunderbird of car (made-by ford)))
10
Input / Output Program Execution
print information agenda
(printout <logical-device> <print-items>*) if all patterns of a rule match with facts, it is put on the
logical device frequently is the standard output device t (terminal) agenda
terminal input (agenda) displays all activated rules
(read [<logical-device>]), (readline [<logical-device>])
read an atom or string from a logical device salience
the logical device can be a file which must be open
indicates priority of rules
open / close file
(open <file-name> <file-ID> [<mode>]), (close [<file-ID>]) refraction
open /close file with <file-id> as internal name rules fire only once for a specific set of facts
load / save constructs from / to file prevents infinite loops
(load <file-name>), (save <file-name>)
backslash \ is a special character and must be ``quoted'' (preceded by a
(refresh <rule-name>)
backslash \) reactivates rules
☯ e.g. (load "B:\\clips\\example.clp")
© C. Kemke CLIPS 41 © C. Kemke CLIPS 42
11
Watching Facts, Rules and Activations More Watching ...
statistics
facts information about the program execution
assertions (add) and retractions (delete) (number of rules fired, run time, ... )
of facts compilation (default)
shows information for constructs loaded by (load)
rules Defining deftemplate: ...
message for each rule that is fired Defining defrule: ... +j=j
☯ +j, =j indicates the internal structure of the compiled rules
activations » +j join added
activated rules: matching antecedents » =j join shared
these rules are on the agenda ☯ important for the efficiency of the Rete pattern matching network
focus
used with modules
indicates which module is currently active
© C. Kemke CLIPS 45 © C. Kemke CLIPS 46
12
Alternatives to CLIPS JESS
JESS
see below
JESS stands for Java Expert System Shell
Eclipse
enhanced, commercial variant of CLIPS it uses the same syntax and a large majority of the
has same syntax as CLIPS (both are based on ART) features of CLIPS
supports goal-driven (i.e., backwards) reasoning
has a truth maintenance facility for checking consistency tight integration with Java
can be integrated with C++ and dBase can be invoked easily from Java programs
new extension RETE++ can generate C++ header files
can utilize object-oriented aspects of Java
not related to the (newer) IBM Eclipse environment
NEXPERT OBJECT some incompatibilities with CLIPS
another rule- and object-based system COOL replaced by Java classes
has facilities for designing graphical interfaces a few missing constructs
has a ‘script language’ for designing user front-end
more and more added as new versions of JESS are released
written in C, runs on many platforms, highly portable
© C. Kemke [Jackson 1999] CLIPS 49 © C. Kemke CLIPS 50
13