Expert Systems Chapter 7 Introduction to CLIPS Entering and Exiting CLIPS A> CLIPS CLIPS (V6.5...

50
Expert Systems Chapter 7 Introduction to CLIPS

Transcript of Expert Systems Chapter 7 Introduction to CLIPS Entering and Exiting CLIPS A> CLIPS CLIPS (V6.5...

Page 1: Expert Systems Chapter 7 Introduction to CLIPS Entering and Exiting CLIPS A> CLIPS  CLIPS (V6.5 09/01/97) CLIPS> exit exit CLIPS> (+ 3 4)  7 CLIPS>

Expert Systems

Chapter 7

Introduction to CLIPS

Page 2: Expert Systems Chapter 7 Introduction to CLIPS Entering and Exiting CLIPS A> CLIPS  CLIPS (V6.5 09/01/97) CLIPS> exit exit CLIPS> (+ 3 4)  7 CLIPS>

Entering and Exiting CLIPS

A> CLIPS CLIPS (V6.5 09/01/97)

CLIPS> exitexitCLIPS> (+ 3 4) 7CLIPS> (exit)A>

7.5

Page 3: Expert Systems Chapter 7 Introduction to CLIPS Entering and Exiting CLIPS A> CLIPS  CLIPS (V6.5 09/01/97) CLIPS> exit exit CLIPS> (+ 3 4)  7 CLIPS>

Facts

A “chunk” of information in CLIPS is called a fact.

Facts consists of a relation name followed by zero or more slots and their associated values.

(person (name “John Q. Public”) (age 23) (eye-color blue) (hair-color black))

The order in which slots are

specified is irrelevant.

The order in which slots are

specified is irrelevant.

7.6

Page 4: Expert Systems Chapter 7 Introduction to CLIPS Entering and Exiting CLIPS A> CLIPS  CLIPS (V6.5 09/01/97) CLIPS> exit exit CLIPS> (+ 3 4)  7 CLIPS>

Deftemplate Construct

Defining the list of valid slots for a given relation name.

Analogous to a record structure in Pascal.

Format:

(deftemplate <relation-name> [<optional-comment>] <slot-definition>*)

<slot-definition> : (slot <slot-name> | ( multislot <slot-name>)

Page 5: Expert Systems Chapter 7 Introduction to CLIPS Entering and Exiting CLIPS A> CLIPS  CLIPS (V6.5 09/01/97) CLIPS> exit exit CLIPS> (+ 3 4)  7 CLIPS>

Defining “person” fact

(deftemplate person “An example deftemplate”(slot name)(slot age)(slot eye-color)(slot hair-color))

(person (name “John Q. Public”) (age 23) (eye-color blue) (hair-color black))

The “person” template

The fact following the format of

“person” template

Page 6: Expert Systems Chapter 7 Introduction to CLIPS Entering and Exiting CLIPS A> CLIPS  CLIPS (V6.5 09/01/97) CLIPS> exit exit CLIPS> (+ 3 4)  7 CLIPS>

Multifield Slots

Slots of a fact that have been specified with the slot keyword in their deftemplates are allowed to contain only one value.

Which specified with multislot keyword are allowed to contain zero or more values.

Page 7: Expert Systems Chapter 7 Introduction to CLIPS Entering and Exiting CLIPS A> CLIPS  CLIPS (V6.5 09/01/97) CLIPS> exit exit CLIPS> (+ 3 4)  7 CLIPS>

Defining “person” factwith multislot

(deftemplate person “An example deftemplate”(multislot name)(slot age)(slot eye-color)(slot hair-color))

(person (name John Q. Public) (age 23) (eye-color blue) (hair-color brown))

Multislot

Specifying multislot

Page 8: Expert Systems Chapter 7 Introduction to CLIPS Entering and Exiting CLIPS A> CLIPS  CLIPS (V6.5 09/01/97) CLIPS> exit exit CLIPS> (+ 3 4)  7 CLIPS>

Ordered Facts

Facts with a relation name that has a corresponding deftemplate are called deftemplate facts.Facts with a relation name that does not have a corresponding deftemplate are called ordered facts.Whenever CLIPS encounters an ordered fact it automatically creates an implied deftemplate for that fact (as opposed to an explicit deftemplate, created using the deftemplate construct).

Page 9: Expert Systems Chapter 7 Introduction to CLIPS Entering and Exiting CLIPS A> CLIPS  CLIPS (V6.5 09/01/97) CLIPS> exit exit CLIPS> (+ 3 4)  7 CLIPS>

Example: (number-list 7 9 3 4 20)

is equivalent to defining (deftemplate number-list (multislot values))

and then defining the fact as (number-list (values 7 9 3 4 20))

Page 10: Expert Systems Chapter 7 Introduction to CLIPS Entering and Exiting CLIPS A> CLIPS  CLIPS (V6.5 09/01/97) CLIPS> exit exit CLIPS> (+ 3 4)  7 CLIPS>

Cases where Ordered Facts are useful

Case 1: Facts consisting of just a relation name are useful as flags and look identical regardless of whether a deftemplate has been defined.

(all-orders-processed)

Case 2: For facts containing a single slot, the slot name is usually synonymous with the relation name.

(time (value 8:45))

can be changed to(time 8:45)

Page 11: Expert Systems Chapter 7 Introduction to CLIPS Entering and Exiting CLIPS A> CLIPS  CLIPS (V6.5 09/01/97) CLIPS> exit exit CLIPS> (+ 3 4)  7 CLIPS>

CONSTRUCT

DEFTEMPLATE

IMPLIEDDEFTEMPLATE

EXPLICITDEFTEMPLATEFACT

ORDEREDFACT

DEFTEMPLATEFACT

(number-list 7 9 3 4 20)

(person (name John Q. Public) (age 23) (eye-color blue) (hair-color brown))

(deftemplate person (multislot name) (slot age) (slot eye-color) (slot hair-color))

Is-a

Is-a IS-A

Creates

Is-aIs-a Creates

Is-a

Is-aIs-a

Page 12: Expert Systems Chapter 7 Introduction to CLIPS Entering and Exiting CLIPS A> CLIPS  CLIPS (V6.5 09/01/97) CLIPS> exit exit CLIPS> (+ 3 4)  7 CLIPS>

CONSTRUCT

DEFTEMPLATE

IMPLIEDDEFTEMPLATE

EXPLICITDEFTEMPLATEFACT

ORDEREDFACT

DEFTEMPLATEFACT

(number-list 7 9 3 4 20)

(person (name John Q. Public) (age 23) (eye-color blue) (hair-color brown))

(deftemplate person (multislot name) (slot age) (slot eye-color) (slot hair-color))

Is-a

Is-a IS-A

Creates

Is-aIs-a Creates

Is-a

Is-aIs-a

Relation Name

Page 13: Expert Systems Chapter 7 Introduction to CLIPS Entering and Exiting CLIPS A> CLIPS  CLIPS (V6.5 09/01/97) CLIPS> exit exit CLIPS> (+ 3 4)  7 CLIPS>

CONSTRUCT

DEFTEMPLATE

IMPLIEDDEFTEMPLATE

EXPLICITDEFTEMPLATEFACT

ORDEREDFACT

DEFTEMPLATEFACT

(number-list 7 9 3 4 20)

(person (name John Q. Public) (age 23) (eye-color blue) (hair-color brown))

(deftemplate person (multislot name) (slot age) (slot eye-color) (slot hair-color))

Is-a

Is-a IS-A

Creates

Is-aIs-a Creates

Is-a

Is-aIs-a

Fields

Page 14: Expert Systems Chapter 7 Introduction to CLIPS Entering and Exiting CLIPS A> CLIPS  CLIPS (V6.5 09/01/97) CLIPS> exit exit CLIPS> (+ 3 4)  7 CLIPS>

CONSTRUCT

DEFTEMPLATE

IMPLIEDDEFTEMPLATE

EXPLICITDEFTEMPLATEFACT

ORDEREDFACT

DEFTEMPLATEFACT

(number-list 7 9 3 4 20)

(person (name John Q. Public) (age 23) (eye-color blue) (hair-color brown))

(deftemplate person (multislot name) (slot age) (slot eye-color) (slot hair-color))

Is-a

Is-a IS-A

Creates

Is-aIs-a Creates

Is-a

Is-aIs-a

Slots

SlotName

Slot Value(a field)

Page 15: Expert Systems Chapter 7 Introduction to CLIPS Entering and Exiting CLIPS A> CLIPS  CLIPS (V6.5 09/01/97) CLIPS> exit exit CLIPS> (+ 3 4)  7 CLIPS>

CONSTRUCT

DEFTEMPLATE

IMPLIEDDEFTEMPLATE

EXPLICITDEFTEMPLATEFACT

ORDEREDFACT

DEFTEMPLATEFACT

(number-list 7 9 3 4 20)

(person (name John Q. Public) (age 23) (eye-color blue) (hair-color brown))

(deftemplate person (multislot name) (slot age) (slot eye-color) (slot hair-color))

Is-a

Is-a IS-A

Creates

Is-aIs-a Creates

Is-a

Is-aIs-a

Multifield SlotSingle-field Slot

Page 16: Expert Systems Chapter 7 Introduction to CLIPS Entering and Exiting CLIPS A> CLIPS  CLIPS (V6.5 09/01/97) CLIPS> exit exit CLIPS> (+ 3 4)  7 CLIPS>

Adding FactsSyntax: (assert <facts>+)

Example: CLIPS>

(deftemplate person (slot name) (slot age) (slot eye-color) (slot hair-color)) CLIPS>(assert (person (name “John Q. Public”) (age 23) (eye-color blue) (hair-color black))) <Fact-0>CLIPS>

7.7

Page 17: Expert Systems Chapter 7 Introduction to CLIPS Entering and Exiting CLIPS A> CLIPS  CLIPS (V6.5 09/01/97) CLIPS> exit exit CLIPS> (+ 3 4)  7 CLIPS>

Display the facts

Syntax: (facts)

Example:CLIPS> (facts) f-0 (person (name “John Q. Public”) (age 23) (eye-color blue) (hair-color black))For a total of 1 fact.CLIPS>

Fact identifier,0: fact index

Page 18: Expert Systems Chapter 7 Introduction to CLIPS Entering and Exiting CLIPS A> CLIPS  CLIPS (V6.5 09/01/97) CLIPS> exit exit CLIPS> (+ 3 4)  7 CLIPS>

Asserting multiple facts withsingle assert

(assert (person (name “John Q. Public”) (age 23) (eye-color blue) (hair-color black)) (person (name “Jane Q. Public”) (age 26) (eye-color green) (hair-color red)))

Page 19: Expert Systems Chapter 7 Introduction to CLIPS Entering and Exiting CLIPS A> CLIPS  CLIPS (V6.5 09/01/97) CLIPS> exit exit CLIPS> (+ 3 4)  7 CLIPS>

Removing Facts

Syntax: (retract <fact-index>+)

Example: John Q. Public can be removed from the fact list with the command (retract 0)

and Jane can be removed by (retract 1)

Attempting to retract a nonexistent fact will produce an error.

Page 20: Expert Systems Chapter 7 Introduction to CLIPS Entering and Exiting CLIPS A> CLIPS  CLIPS (V6.5 09/01/97) CLIPS> exit exit CLIPS> (+ 3 4)  7 CLIPS>

Modifying Facts

Syntax: (modify <fact-index> <slot-modifier>+)

Example:CLIPS> (modify 0 (age 24))<Fact-2>CLIPS> (facts) f-2 (person (name “John Q. Public”) (age 24) (eye-color blue) (hair-color black))For a total of 1 fact.CLIPS>

A new fact index is generated for a modified fact.

7.8

Page 21: Expert Systems Chapter 7 Introduction to CLIPS Entering and Exiting CLIPS A> CLIPS  CLIPS (V6.5 09/01/97) CLIPS> exit exit CLIPS> (+ 3 4)  7 CLIPS>

Duplicating Facts

Works the same with modify but not retracting the original fact.

Syntax: (duplicate <fact-index> <slot-modifier>+)

Page 22: Expert Systems Chapter 7 Introduction to CLIPS Entering and Exiting CLIPS A> CLIPS  CLIPS (V6.5 09/01/97) CLIPS> exit exit CLIPS> (+ 3 4)  7 CLIPS>

Example:CLIPS> (duplicate 2 (name “Jack S. Public”))<Fact-3>CLIPS> (facts) f-2 (person (name “John Q. Public”) (age 24) (eye-color blue) (hair-color black))f-3 (person (name “Jack S. Public”) (age 24) (eye-color blue) (hair-color black))For a total of 2 facts.CLIPS>

Page 23: Expert Systems Chapter 7 Introduction to CLIPS Entering and Exiting CLIPS A> CLIPS  CLIPS (V6.5 09/01/97) CLIPS> exit exit CLIPS> (+ 3 4)  7 CLIPS>

Debugging

Syntax: (watch <watch-item>)

The <watch-item> is one of the symbols facts, rules, activations, statistics, compilations, focus, or all.

By default, when CLIPS is first started, compilations are watched and the remaining watch items are not watched.

7.9

Page 24: Expert Systems Chapter 7 Introduction to CLIPS Entering and Exiting CLIPS A> CLIPS  CLIPS (V6.5 09/01/97) CLIPS> exit exit CLIPS> (+ 3 4)  7 CLIPS>

Example:CLIPS> (facts 3 3) f-3 (person (name “Jack S. Public”) (age 24) (eye-color blue) (hair-color black))For a total of 1 fact.CLIPS> (watch facts) CLIPS> (modify 3 (age 25)) <== f-3 (person (name “Jack S. Public”) (age 24) (eye-color blue) (hair-color black)) ==> f-4 (person (name “Jack S. Public”) (age 25) (eye-color blue) (hair-color black))<Fact-4>CLIPS>

Indicating that the fact is being retracted.

Indicating that the fact is being asserted.

Page 25: Expert Systems Chapter 7 Introduction to CLIPS Entering and Exiting CLIPS A> CLIPS  CLIPS (V6.5 09/01/97) CLIPS> exit exit CLIPS> (+ 3 4)  7 CLIPS>

Defining Initial Knowledge

It is convenient to be able to automatically assert a set of facts instead of typing in the same assertions from the top level.Initial knowledge: facts that are known to be true before running a program.Groups of facts that represent initial knowledge can be defined using the deffacts construct.

7.10

Page 26: Expert Systems Chapter 7 Introduction to CLIPS Entering and Exiting CLIPS A> CLIPS  CLIPS (V6.5 09/01/97) CLIPS> exit exit CLIPS> (+ 3 4)  7 CLIPS>

Deffacts ConstructSyntax: (deffacts <deffacts name> [<optional comment>]

<facts>*)

Example:(deffacts people “Some people we know” (person (name “John Q. Public”) (age 24) (eye-color blue) (hair-color black)) (person (name “Jack S. Public”) (age 24) (eye-color blue) (hair-color black)) (person (name “Jane Q. Public) (age 36) (eye-color green) (hair-color red)))

Page 27: Expert Systems Chapter 7 Introduction to CLIPS Entering and Exiting CLIPS A> CLIPS  CLIPS (V6.5 09/01/97) CLIPS> exit exit CLIPS> (+ 3 4)  7 CLIPS>

ResetThe reset command removes all facts from the fact list and then asserts the facts from existing deffacts statement.

CLIPS> (unwatch facts)CLIPS> (reset) CLIPS> (facts) f-0 (initial-fact)f-1 (person (name “John Q. Public”) (age 24) (eye-color blue) (hair-color black))f-2 (person (name “Jack S. Public”) (age 24) (eye-color blue) (hair-color black))f-3 (person (name “Jane Q. Public) (age 36) (eye-color green) (hair-color red))For a total of 4 facts.CLIPS>

Page 28: Expert Systems Chapter 7 Introduction to CLIPS Entering and Exiting CLIPS A> CLIPS  CLIPS (V6.5 09/01/97) CLIPS> exit exit CLIPS> (+ 3 4)  7 CLIPS>

Initial Fact

A new fact generated by the reset command called initial-fact.Upon startup, CLIPS automatically defines the following two constructs:

(deftemplate initial-fact)(deffacts initial-fact

(initial-fact))

Even if no any deffacts statements defined, a reset will assert the fact (initial-fact).

Page 29: Expert Systems Chapter 7 Introduction to CLIPS Entering and Exiting CLIPS A> CLIPS  CLIPS (V6.5 09/01/97) CLIPS> exit exit CLIPS> (+ 3 4)  7 CLIPS>

RulesRules can be typed directly into CLIPS or loaded in from a file of rules created by an editor.

Example: pseudocode of plant monitoringIF the emergency is a fireTHEN the response is

to activate the sprinkler system

Representing emergency:(deftemplate emergency (slot type))

Representing response:(deftemplate response (slot action))

7.11

Page 30: Expert Systems Chapter 7 Introduction to CLIPS Entering and Exiting CLIPS A> CLIPS  CLIPS (V6.5 09/01/97) CLIPS> exit exit CLIPS> (+ 3 4)  7 CLIPS>

Rule RepresentationGeneral format of a rule:(defrule <rule name> [<comment>]

<patterns>* ;Left-hand side (LHS) =>

<actions>*) ;Right-hand side (RHS)

Representing the rule:(defrule fire-emergency “An example rule”

(emergency (type fire))=> (assert (response

(action activate-sprinkler-system))))

Page 31: Expert Systems Chapter 7 Introduction to CLIPS Entering and Exiting CLIPS A> CLIPS  CLIPS (V6.5 09/01/97) CLIPS> exit exit CLIPS> (+ 3 4)  7 CLIPS>

Conditional Elements

After the rule header are zero or more conditional elements (CEs).

The simplest type of CE is a pattern CE or simply pattern.

Each pattern consists of one or more constraints intended to match the fields of a deftemplate fact.

Page 32: Expert Systems Chapter 7 Introduction to CLIPS Entering and Exiting CLIPS A> CLIPS  CLIPS (V6.5 09/01/97) CLIPS> exit exit CLIPS> (+ 3 4)  7 CLIPS>

Example

(defrule fire-emergency “An example rule”(emergency (type fire))

(emergency (type flood))=> (assert (response

(action activate-sprinkler-system))))

pattern

patternConditionalElements

Page 33: Expert Systems Chapter 7 Introduction to CLIPS Entering and Exiting CLIPS A> CLIPS  CLIPS (V6.5 09/01/97) CLIPS> exit exit CLIPS> (+ 3 4)  7 CLIPS>

Rule without PatternIf a rule has no patterns, the special pattern (initial-fact) will be added as a pattern for the rule. Since the initial-fact deffacts is automatically defined, any rules with no patterns on their LHSs will be activated when a reset command is performed since the (initial-fact) fact will automatically be asserted.Thus any rule without LHS patterns will be placed on the agenda when a reset is performed

Page 34: Expert Systems Chapter 7 Introduction to CLIPS Entering and Exiting CLIPS A> CLIPS  CLIPS (V6.5 09/01/97) CLIPS> exit exit CLIPS> (+ 3 4)  7 CLIPS>

Program Execution

Syntax: (run [<limit>])limit: maximum number of rules to be fired

The facts asserted by a reset satisfy the patterns of one or more rules and place activations of these rules on the agenda.

Issuing the run command then begins execution of the program.

7.12

Page 35: Expert Systems Chapter 7 Introduction to CLIPS Entering and Exiting CLIPS A> CLIPS  CLIPS (V6.5 09/01/97) CLIPS> exit exit CLIPS> (+ 3 4)  7 CLIPS>

Displaying the Agenda

Syntax: (agenda)

Example:CLIPS> (reset)CLIPS> (assert (emergency (type fire)))<Fact-1>

CLIPS> (agenda)0 fire-emergency: f-1For a total of 1 activation.CLIPS>

Page 36: Expert Systems Chapter 7 Introduction to CLIPS Entering and Exiting CLIPS A> CLIPS  CLIPS (V6.5 09/01/97) CLIPS> exit exit CLIPS> (+ 3 4)  7 CLIPS>

Run

(Example continue)CLIPS> (run)CLIPS> (facts)f-0 (initial-fact)f-1 (emergency (type fire))f-2 (response action activate-sprinkler-system))For a total of 3 facts.CLIPS>

Page 37: Expert Systems Chapter 7 Introduction to CLIPS Entering and Exiting CLIPS A> CLIPS  CLIPS (V6.5 09/01/97) CLIPS> exit exit CLIPS> (+ 3 4)  7 CLIPS>

Refraction

Refraction: Rules in CLIPS won’t fire more than once for a specific set of facts.

Without refraction, expert systems would always be caught in trivial loops.

If necessary, the rule can be made to fire again by retracting the fact (emergency (type fire)) and asserting it again.

Page 38: Expert Systems Chapter 7 Introduction to CLIPS Entering and Exiting CLIPS A> CLIPS  CLIPS (V6.5 09/01/97) CLIPS> exit exit CLIPS> (+ 3 4)  7 CLIPS>

Refresh Command

Used to make the rule fire again.

Syntax: (refresh <rule-name>)

Example:CLIPS> (agenda)CLIPS> (refresh fire-emergency) CLIPS> (agenda) 0 fire-emergency: f-1For a total of 1 activation.CLIPS>

Page 39: Expert Systems Chapter 7 Introduction to CLIPS Entering and Exiting CLIPS A> CLIPS  CLIPS (V6.5 09/01/97) CLIPS> exit exit CLIPS> (+ 3 4)  7 CLIPS>

Watching ActivationsExample:CLIPS> (reset) CLIPS> (watch activations) CLIPS> (assert (emergency (type fire))) ==> Activation 0 fire-emergency: f-1<Fact-1>CLIPS> (agenda) 0 fire-emergency: f-1For a total of 1 activation.CLIPS> (retract 1) <== Activation 0 fire-emergency: f-1CLIPS> (agenda) CLIPS>

Page 40: Expert Systems Chapter 7 Introduction to CLIPS Entering and Exiting CLIPS A> CLIPS  CLIPS (V6.5 09/01/97) CLIPS> exit exit CLIPS> (+ 3 4)  7 CLIPS>

Watching Rules

CLIPS will print a message whenever a rule is fired.Example:CLIPS> (reset) CLIPS> (watch rules) CLIPS> (assert (emergency (type fire))) ==> Activation 0 fire-emergency: f-1<Fact-1>CLIPS> (run) FIRE 1 fire-emergency: f-1CLIPS> (agenda) CLIPS>

Page 41: Expert Systems Chapter 7 Introduction to CLIPS Entering and Exiting CLIPS A> CLIPS  CLIPS (V6.5 09/01/97) CLIPS> exit exit CLIPS> (+ 3 4)  7 CLIPS>

Displaying Construct ListExample:CLIPS> (list-defrules) fire-emergencyFor a total of 1 rule.CLIPS> (list-deftemplates) initial-factemergencyresponseFor a total of 3 deftemplates.CLIPS> (list-deffacts) initial-factFor a total of 1 deffacts.CLIPS>

Page 42: Expert Systems Chapter 7 Introduction to CLIPS Entering and Exiting CLIPS A> CLIPS  CLIPS (V6.5 09/01/97) CLIPS> exit exit CLIPS> (+ 3 4)  7 CLIPS>

Pretty PrintExample:CLIPS> (ppdefrule fire-emergency) (defrule MAIN::fire-emergency “An example rule”

(emergency (type fire))=> (assert (response

(action activate-sprinkler-system))))CLIPS> (ppdeftemplate response) (deftemplate MAIN::response

(slot action))CLIPS> (ppdeffacts initial-fact) CLIPS> (deffacts start-fact (start-fact)) CLIPS> (ppdeffacts start-fact) (deffacts MAIN::start-fact

(start-fact))CLIPS>

Page 43: Expert Systems Chapter 7 Introduction to CLIPS Entering and Exiting CLIPS A> CLIPS  CLIPS (V6.5 09/01/97) CLIPS> exit exit CLIPS> (+ 3 4)  7 CLIPS>

Deleting Constructs

Example:CLIPS> (undeffacts start-fact) CLIPS> (list-deffacts) initial-factFor a total of 1 deffacts.CLIPS> (undefrule fire-emergency) CLIPS> (list-defrules) CLIPS>

Page 44: Expert Systems Chapter 7 Introduction to CLIPS Entering and Exiting CLIPS A> CLIPS  CLIPS (V6.5 09/01/97) CLIPS> exit exit CLIPS> (+ 3 4)  7 CLIPS>

Clearing all ConstructsSyntax: (clear)

Example:CLIPS> (list-deffacts) CLIPS> (list-deftemplates) emergencyresponsestart-factFor a total of 3 deftemplates.CLIPS> (clear) CLIPS> (list-deffacts) initial-factFor a total of 1 deffacts.CLIPS> (list-deftemplates) initial-factFor a total of 1 deftemplate.CLIPS>

After clearing, it adds the initial-facts

deffacts to the environment.

Page 45: Expert Systems Chapter 7 Introduction to CLIPS Entering and Exiting CLIPS A> CLIPS  CLIPS (V6.5 09/01/97) CLIPS> exit exit CLIPS> (+ 3 4)  7 CLIPS>

Printout

Syntax: (printout <logical-name> <print-items> *)

Example:(defrule fire-emergency

(emergency (type fire))=>(printout t “Activate the sprinkler system”

crlf))

Output:“Activate the sprinkler system”

Stands for the standard output device of terminal.

Carriage return/Line feed

Page 46: Expert Systems Chapter 7 Introduction to CLIPS Entering and Exiting CLIPS A> CLIPS  CLIPS (V6.5 09/01/97) CLIPS> exit exit CLIPS> (+ 3 4)  7 CLIPS>

Multiple Rules

(defrule fire-emergency(emergency (type fire))=> (printout t “Activate the sprinkler system”

crlf))(defrule flood-emergency

(emergency (type flood))=> (printout t “Shut down electrical equipment”

crlf))

7.15

Page 47: Expert Systems Chapter 7 Introduction to CLIPS Entering and Exiting CLIPS A> CLIPS  CLIPS (V6.5 09/01/97) CLIPS> exit exit CLIPS> (+ 3 4)  7 CLIPS>

Rules with Multiple Patterns(deftemplate extinguisher-system

(slot type) (slot status))(defrule class-A-fire-emergency

(emergency (type class-A-fire))(extinguisher-system (type water-sprinkler)

(status off))=>(printout t “Activate water sprinkler” crlf))

(defrule class-B-fire-emergency(emergency (type class-B-fire))(extinguisher-system (type carbon-dioxide)

(status off))=>(printout t “Use carbon dioxide extinguisher” crlf))

Page 48: Expert Systems Chapter 7 Introduction to CLIPS Entering and Exiting CLIPS A> CLIPS  CLIPS (V6.5 09/01/97) CLIPS> exit exit CLIPS> (+ 3 4)  7 CLIPS>

Loading ConstructsSyntax: (load <file-name>)

Example:CLIPS> (load “fire.clp”) Defining deftemplate: emergencyDefining deftemplate: responseDefining defrule: fire-emergency +jTRUECLIPS>

If compilations are not being watched, then the character *, %, and $ will be used for defrules, deftemplates, and deffacts.

7.17

Page 49: Expert Systems Chapter 7 Introduction to CLIPS Entering and Exiting CLIPS A> CLIPS  CLIPS (V6.5 09/01/97) CLIPS> exit exit CLIPS> (+ 3 4)  7 CLIPS>

Saving Constructs

Syntax: (save <file-name>)

Example:(save “B:fire.clp”)

Page 50: Expert Systems Chapter 7 Introduction to CLIPS Entering and Exiting CLIPS A> CLIPS  CLIPS (V6.5 09/01/97) CLIPS> exit exit CLIPS> (+ 3 4)  7 CLIPS>

Comments;* Programmer: G. D. Riley; Deftemplates here(deftemplate emergency (slot type));;The purpose of this rule is to activate; the sprinkler system if there is a fire (defrule fire-emergency

; There is a fire emergency(emergency (type fire))=> ; Activate the sprinkler system(printout t “Activate the sprinkler system”

crlf))