CLIPS - PowerPoint PPT Presentation

1 / 19
About This Presentation
Title:

CLIPS

Description:

1. CLIPS. CLIPS is a rule-based forward reasoning knowledge based ... CLIPS (assert (person (name 'John Durkin') (age 43) (eye-color blue) (hair-color brown) ... – PowerPoint PPT presentation

Number of Views:1126
Avg rating:3.0/5.0
Slides: 20
Provided by: hasa
Category:
Tags: clips | durkin

less

Transcript and Presenter's Notes

Title: CLIPS


1
CLIPS
  • CLIPS is a rule-based forward reasoning knowledge
    based systems shell based on Rete pattern
    matching algorithm used originally in OPS5.
  • CLIPS stands for
  • C Language Implementation Production System
  • Developed by
  • The AI section of the Johnson Space Center of
    NASA
  • CLIPS supports
  • Rule-based
  • Object oriented (COOL CLIPS Object Oriented
    Language)
  • Procedural programming paaradigms.

2
Attributes of CLIPS
High Portability Low Cost High Degree of
Integration with External Programs
To start working with CLIPS you issue the
corresponding command depending on the machine
used. CLIPS prompt will appear usually in a
window
CLIPSgt (assert (a) (b) (c)) ltFact-3gt CLIPSgt
(facts) f-0 (initial-fact) f-1 (a) f-2
(b) f-3 (c) For a total of 4 facts. CLIPSgt(exit)
ctrl Q
CLIPS CLIPSgt(reset) CLIPSgt(facts) f-0
(initial-fact) For a total of 1 fact. CLIPSgt
3
Facts A fact consistes of a relation name
followed by one or more slots.
Here is an example of a fact (plays john mary
netball) One way of entering facts into CLIPS
is (assert (play john mary netball)) (assert
(likes john mary))
CLIPSgt (reset) CLIPSgt (facts) f-0
(initial-fact) For a total of 1 fact. CLIPSgt
(assert (play john mary netball)) ltFact-1gt CLIPSgt
(assert (likes john mary)) ltFact-2gt CLIPSgt
Returned from CLIPS
4
CLIPSgt(facts) f-0 (initial-fact) f-1
(play john mary netball) f-2 (likes john
mary) For a total of 3 facts. CLIPSgt
To delete facts from CLIPS fact list
CLIPSgt (retract 1) CLIPSgt (facts) f-0
(initial-fact) f-2 (likes john mary) For a
total of 2 facts. CLIPSgt
5
To enter a fact with multiple slots you must
declare its template using the deftemplate
construct. We use this construct to decalre the
structure of a group of facts. The general form
of the deftemplate construct is
(deftemplate ltrelation-namegt ltoptional-commentgt
ltslot-definitionsgt)
Slots are defined as (slot ltslot-namegt)
(multislot ltslot-namegt)
CLIPSgt (deftemplate person "an example
deftemplate" (slot name)
(slot age) (slot
eye-color) (slot hair-color))
CLIPSgt (assert (person (name "John Durkin") (age
43) (eye-color blue) (hair-color
brown))) ltFact-3gt CLIPSgt
6
CLIPSgt (facts)
f-2 (likes john mary) f-3 (person (name
"John Durkin") (age 43) (eye-color
blue) (hair-color brown)) For a total of 2
facts. CLIPSgt
deftemplate can be implicit when we use ordered
facts (used earlier) (numbers 1 2 3) (likes
john mary)
7
Some CLIPS Commands
  • (exit) to exit from CLIPS
  • (clear) to clear the environment from active
    definitions
  • (reset) to set the fact base to its initial
    state clears all and sets (initial-fact). Use
    (reset) before run command
  • (load filename.clp) to load a program from the
    file named filename.clp into CLIPS.
  • (run) executes a program loaded into CLIPS
  • (facts) to display the fact list
  • (rules) to display the rules in the rule base.

8
An Example
Using an editor create a file containing the
following rule (defrule my-first (initial-fact)
gt (printout t "First CLIPS program
executed" crlf) )
CLIPS CLIPSgt (reset) CLIPSgt (facts) f-0
(initial-fact) For a total of 1 fact. CLIPSgt
(load "test.clp") Defining defrule my-first
j TRUE CLIPSgt (run) First CLIPS program
executed CLIPSgt
9
Rules
If the emergency is a fire Then the response is
to activate the sprinkler system
Lets define this rule. Before defining the rule
we use deftemplates to define emergencies and
responses (deftemplate emergency (slot
type)) (deftemplate response (slot action))
Rule header (defrule fire-emergency an example
rule pattern (emergency (type fire))
arrow gt action (assert (response (action
activate-sprinkler-system))))
10
General format of rules
(defrule ltrule-namegt ltcommentgt ltpatternsgt
LHS of the rule gt ltactionsgt ) RHS of
the rule
A rule may have no conditional element (in which
case initial fact is its conditional element) or
no action part. Or they may have multiple
patterns or actions
(defrule is-it-a-duck (animal-has webbed-feet)
(animal-has feathers) gt
(assert (animal-is duck)))
(defrule duck (animal-is duck)
gt (assert (sound-is quack))
(printout t "its a duck" crlf))
11
The run command is used to run a CLIPS program
(run ltlimitgt ) limit is the maximum
number of rules we want to fire Rules that match
facts are put on the agenda and fire according to
their priority. We may display the
agena (agenda)
CLIPSgt (reset) CLIPSgt (deftemplate emergency
(slot type)) CLIPSgt (deftemplate response (slot
action)) CLIPSgt (assert (emergency (type
fire))) ltFact-2gt CLIPSgt (defrule fire-emergency
"an example rule" pattern
(emergency (type fire)) gt arrow
(assert (response (action
activate-sprinkler-system)))) action CLIPSgt
(agenda) 0 fire-emergency f-2 For a total
of 1 activation. CLIPSgt agenda agenda CLIPSgt
12
CLIPSgt (run) CLIPSgt (facts) f-0
(initial-fact) f-1 (emergency (type
fire)) f-2 (response (action
activate-sprinkler-system)) For a total of 3
facts.
Rules have a property called refraction which
means that they will fire only once for the same
set of facts. If run is issued again the rule
wont fire again. We can however force this to
happen by retracting and asserting the fact again
or by using refresh to refresh the rule
(refresh fire-emergency)
13
Variables
?name ?color ?status ?value ?x A variable may be
bound to a value or even a fact address.
CLIPSgt (clear) CLIPSgt (deftemplate person
(slot name) (slot eyes)
(slot hair))
14
CLIPSgt (defrule find-blue-eyes
(person (name ?name) (eyes blue))
gt (printout t ?name " has blue
eyes." crlf)) CLIPSgt (deffacts people
(person (name Jane) (eyes blue)
(hair red)) (person (name Joe)
(eyes green) (hair brown)) (person
(name Jack) (eyes blue) (hair
black)) (person (name Jeff)
(eyes green) (hair brown)))
CLIPSgt (reset) CLIPSgt (run) Jack has blue
eyes. Jane has blue eyes. CLIPSgt
15
CLIPSgt (defrule list-animals (animal
?name) gt (printout t ?name " found"
crlf)) CLIPSgt(run) haddock found duck found dog
found CLIPSgt
16
CLIPSgt (defrule mammal (animal ?name)
(warm-blooded ?name) (not (lays-eggs
?name)) gt (assert (mammal ?name))
(printout t ?name " is a mammal" crlf))
CLIPSgt (deffacts startup (animal dog) (animal
duck) (animal haddock) (animal cat))
CLIPSgt (deffacts warm-blooded (warm-blooded
cat) (warm-blooded dog))
CLIPSgt (reset) CLIPSgt (run) cat is a mammal dog
is a mammal
17
Functions and expressions
CLIPSgt ( 2 3) 5 CLIPSgt ( 2 3.0 4) 9.0 CLIPSgt (/
6 2) 3.0 CLIPSgt (/ 6 2 3) 1.0
CLIPSgt (clear) CLIPSgt (assert (answer ( 2
2))) ltFact-0gt CLIPSgt (facts) f-0 (answer
4) For a total of 1 fact. CLIPSgt
(Y2 y1) / (x2 x1) gt 0 (gt (/ (- y2 y1) (- x2
x1)) 0)
18
I/O
CLIPSgt (defrule what-is-child (animal
?name) (not (child-of ?name ?)) gt
(printout t "What do you call the child of
a " ?name "?") (assert (child-of ?name
(read)))) CLIPSgt (run) What do you call the child
of a haddock?Hoddy What do you call the child of
a duck?haddock
In an Automobile Diagnosis Expert System
CLIPSgt (defrule are-lights-working (not
(lights-working ?)) gt (printout t
"Are the car's lights working (yes or no)?")
(assert (lights-working (read))))
19
Functions
(deffunction yes-or-no-p (?question) (bind
?response (ask-question ?question yes no y n))
(if (or (eq ?response yes) (eq ?response y))
then TRUE else FALSE))
Write a Comment
User Comments (0)
About PowerShow.com