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>

Slides:



Advertisements
Similar presentations
Expert systems CLIPS Seyed Hashem Davarpanah
Advertisements

Chapter 3: Editing and Debugging SAS Programs. Some useful tips of using Program Editor Add line number: In the Command Box, type num, enter. Save SAS.
Introduction to CLIPS COMP 474/674 FALL 2003 Michelle Khalifé.
The CLIPS Programming Tool History of CLIPS –Influenced by OPS5 and ART –Implemented in C for efficiency and portability –Developed by NASA, distributed.
CLIPS 1 Expert Systems Dr. Samy Abu Nasser. CLIPS 2 Course Overview u Introduction u CLIPS Overview u Concepts, Notation, Usage u Knowledge Representation.
November 2, 2004AI: CLIPS Language Tutorial1 CLIPS Michael Scherger Department of Computer Science Kent State University.
Expert System Shells - Examples
Samad Paydar Ferdowsi University of Mashhad.  C Language Integrated Production System (CLIPS)  A tool for building expert systems  An expert system.
1 01/12/2011Knowledge-Based Systems, Paula Matuszek Intro to CLIPS Paula Matuszek CSC 9010, Spring, 2011.
November 2, 2004AI: CLIPS Language Tutorial1 Artificial Intelligence CLIPS Language Tutorial Michael Scherger Department of Computer Science Kent State.
Chapter 8 Pattern Matching
© C. Kemke CLIPS 1 1 COMP 4200: Expert Systems Dr. Christel Kemke Department of Computer Science University of Manitoba.
Simple Rule Based Systems Directly implementing rule based systems in Java Need vocabulary Simplicity sometimes works.
Introduction to CLIPS (Lecture Note #17)
Chapter 7: Introduction to CLIPS
CLIPS C Language Integrated Production System Note: Some slides and/or pictures are adapted from Lecture slides / Books of Dr Zafar Alvi.
Artificial Intelligence Lecture No. 18 Dr. Asad Ali Safi ​ Assistant Professor, Department of Computer Science, COMSATS Institute of Information Technology.
Chapter 12: Expert Systems Design Examples
Introduction to CLIPS (Chapter 7) Fact List (contains data) Knowledge Base (contains rules) Inference Engine (controls execution)
© Franz J. Kurfess CLIPS 1 CPE/CSC 481: Knowledge-Based Systems Dr. Franz J. Kurfess Computer Science Department Cal Poly.
© C. Kemke CLIPS 1 1 COMP 4200: Expert Systems Dr. Christel Kemke Department of Computer Science University of Manitoba.
© C. Kemke Control 1 COMP 4200: Expert Systems Dr. Christel Kemke Department of Computer Science University of Manitoba.
Chapter 8: Advanced Pattern Matching Expert Systems: Principles and Programming, Fourth Edition.
Chapter 9: Modular Design, Execution Control, and Rule Efficiency Expert Systems: Principles and Programming, Fourth Edition.
A Guide to Oracle9i1 Advanced SQL And PL/SQL Topics Chapter 9.
Chapter 6 C Arrays Acknowledgment The notes are adapted from those provided by Deitel & Associates, Inc. and Pearson Education Inc. Arrays are data structures.
Introduction to Jess.
Guide To UNIX Using Linux Third Edition
CS 561, Session 25 1 Introduction to CLIPS Overview of CLIPS Facts Rules Rule firing Control techniques Example.
Chapter Seven Advanced Shell Programming. 2 Lesson A Developing a Fully Featured Program.
CHAPTER 4: INTRODUCTION TO COMPUTER ORGANIZATION AND PROGRAMMING DESIGN Lec. Ghader Kurdi.
1 01/12/2011Knowledge-Based Systems, Paula Matuszek More Intro to CLIPS Paula Matuszek CSC 9010, Spring, 2011.
Chapter 9: Modular Design, Execution Control, and Rule Efficiency Expert Systems: Principles and Programming, Fourth Edition.
Review Topics Test 1. Background Topics Definitions of Artificial Intelligence & Turing Test Physical symbol system hypothesis vs connectionist approaches.
Expert System Topic 2.
© Copyright 1992–2005 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. Tutorial 2 - Welcome Application: Introduction to C++
1 Programming a Knowledge Based Application. 2 Overview.
Chapter 7: Introduction to CLIPS Expert Systems: Principles and Programming, Fourth Edition.
Artificial Intelligence Lecture No. 17 Dr. Asad Ali Safi ​ Assistant Professor, Department of Computer Science, COMSATS Institute of Information Technology.
Chapter 10: Procedural Programming Expert Systems: Principles and Programming, Fourth Edition.
Chapter One An Introduction to Visual Basic 2010 Programming with Microsoft Visual Basic th Edition.
Expert Systems An Introduction to Expert Systems and CLIPS by Charles Weddle.
Linux+ Guide to Linux Certification Chapter Eight Working with the BASH Shell.
Jess: A Rule-Based Programming Environment Reporter: Yu Lun Kuo Date: April 10, 2006 Expert System.
Access Project 3 Notes. Introduction Maintaining the Database  Modifying the data to keep it up-to-date Restructure the Database  To change the database.
Chapter 7: Introduction to CLIPS Presented By: Farnaz Ronaghi.
IMSS013 CLIPS. 2 Background CLIPS is an expert system tool developed by the Software Technology Branch (STB), NASA/Lyndon B. Johnson Space Center. First.
Microsoft Access 2010 Chapter 10 Administering a Database System.
Advanced Pattern Matching. Field constraints Used to restrict the values of a field on LHS of a rule Used to restrict the values of a field on LHS of.
Artificial Intelligence Lecture No. 26 Dr. Asad Ali Safi ​ Assistant Professor, Department of Computer Science, COMSATS Institute of Information Technology.
Artificial Intelligence Lecture No. 24 Dr. Asad Ali Safi ​ Assistant Professor, Department of Computer Science, COMSATS Institute of Information Technology.
Introduction to CLIPS. Expert Systems: Principles and Programming, Fourth Edition2 What is CLIPS? CLIPS is a multiparadigm programming language that provides.
JessTab Tutorial Henrik Eriksson. 2 JessTab Tutorial Outline 1.Introduction 2.Background 3.Installation 4.Interaction with JessTab 5.Introduction.
Artificial Intelligence Lecture No. 19 Dr. Asad Ali Safi ​ Assistant Professor, Department of Computer Science, COMSATS Institute of Information Technology.
Artificial Intelligence Lecture No. 23 Dr. Asad Ali Safi ​ Assistant Professor, Department of Computer Science, COMSATS Institute of Information Technology.
Mostly adopted from Jason Morris notes (Morris Technical Solutions)
Artificial Intelligence Lecture No. 22 Dr. Asad Ali Safi ​ Assistant Professor, Department of Computer Science, COMSATS Institute of Information Technology.
The CLIPS Expert System Shell Dr Nicholas Gibbins
FILES AND EXCEPTIONS Topics Introduction to File Input and Output Using Loops to Process Files Processing Records Exceptions.
Summary for final exam Agent System..
Introduction to CLIPS 2 Session 13 Course: T0273 – EXPERT SYSTEMS Year: 2014.
Jörg Kewisch, June 10, 2013, LILUG Meeting CLIPS C Language Integrated Production System Developed at the Software Development Branch, NASA Lyndon B. Johnson.
Intelligent Systems JESS constructs.
Chapter 7: Introduction to CLIPS
Chapter 8: Advanced Pattern Matching
بسم الله الرحمن الرحیم آموزش نرم افزار CLIPS
Chapter 11: Classes, Instances, and Message-Handlers
JESS (Java Expert System Shall)
CPE/CSC 481: Knowledge-Based Systems
Computer Based Tutoring
Presentation transcript:

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> (exit) A> 7.5

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. 7.6

Deftemplate Construct Defining the list of valid slots for a given relation name. Analogous to a record structure in Pascal. Format: (deftemplate [ ] *) : (slot | ( multislot )

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

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.

Defining “ person ” fact with 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

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).

Example: (number-list ) is equivalent to defining (deftemplate number-list (multislot values)) and then defining the fact as (number-list (values ))

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)

CONSTRUCT DEFTEMPLATE IMPLIED DEFTEMPLATE EXPLICIT DEFTEMPLATE FACT ORDERED FACT DEFTEMPLATE FACT (number-list ) (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 Creates Is-a Creates Is-a

CONSTRUCT DEFTEMPLATE IMPLIED DEFTEMPLATE EXPLICIT DEFTEMPLATE FACT ORDERED FACT DEFTEMPLATE FACT (number-list ) (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 Creates Is-a Creates Is-a Relation Name

CONSTRUCT DEFTEMPLATE IMPLIED DEFTEMPLATE EXPLICIT DEFTEMPLATE FACT ORDERED FACT DEFTEMPLATE FACT (number-list ) (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 Creates Is-a Creates Is-a Fields

CONSTRUCT DEFTEMPLATE IMPLIED DEFTEMPLATE EXPLICIT DEFTEMPLATE FACT ORDERED FACT DEFTEMPLATE FACT (number-list ) (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 Creates Is-a Creates Is-a Slots Slot Name Slot Value (a field)

CONSTRUCT DEFTEMPLATE IMPLIED DEFTEMPLATE EXPLICIT DEFTEMPLATE FACT ORDERED FACT DEFTEMPLATE FACT (number-list ) (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 Creates Is-a Creates Is-a Multifield Slot Single-field Slot

Adding Facts Syntax: (assert +) 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)))  CLIPS> 7.7

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

Asserting multiple facts with single 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)))

Removing Facts Syntax: (retract +) 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.

Modifying Facts Syntax: (modify +) Example: CLIPS> (modify 0 (age 24))  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

Duplicating Facts Works the same with modify but not retracting the original fact. Syntax: (duplicate +)

Example: CLIPS> (duplicate 2 (name “Jack S. Public”))  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>

Debugging Syntax: (watch ) The 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

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-4 (person (name “Jack S. Public”) (age 25) (eye-color blue) (hair-color black)) CLIPS> Indicating that the fact is being retracted. Indicating that the fact is being asserted.

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

Deffacts Construct Syntax: (deffacts [ ] *) 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)))

Reset The 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>

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).

Rules Rules can be typed directly into CLIPS or loaded in from a file of rules created by an editor. Example: pseudocode of plant monitoring IF the emergency is a fire THEN the response is to activate the sprinkler system Representing emergency: (deftemplate emergency (slot type)) Representing response: (deftemplate response (slot action)) 7.11

Rule Representation General format of a rule: (defrule [ ] * ;Left-hand side (LHS) => *) ;Right-hand side (RHS) Representing the rule: (defrule fire-emergency “An example rule” (emergency (type fire)) => (assert (response (action activate-sprinkler-system))))

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.

Example (defrule fire-emergency “An example rule” (emergency (type fire)) (emergency (type flood)) => (assert (response (action activate-sprinkler-system)))) pattern Conditional Elements

Rule without Pattern If 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

Program Execution Syntax: (run [ ]) 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

Displaying the Agenda Syntax: (agenda) Example: CLIPS> (reset)  CLIPS> (assert (emergency (type fire)))  CLIPS> (agenda)  0fire-emergency: f-1 For a total of 1 activation. 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>

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.

Refresh Command Used to make the rule fire again. Syntax: (refresh ) Example: CLIPS> (agenda)  CLIPS> (refresh fire-emergency)  CLIPS> (agenda)  0fire-emergency: f-1 For a total of 1 activation. CLIPS>

Watching Activations Example: CLIPS> (reset)  CLIPS> (watch activations)  CLIPS> (assert (emergency (type fire)))  ==> Activation 0fire-emergency: f-1 CLIPS> (agenda)  0fire-emergency: f-1 For a total of 1 activation. CLIPS> (retract 1)  (agenda)  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 0fire-emergency: f-1 CLIPS> (run)  FIRE1 fire-emergency: f-1 CLIPS> (agenda)  CLIPS>

Displaying Construct List Example: CLIPS> (list-defrules)  fire-emergency For a total of 1 rule. CLIPS> (list-deftemplates)  initial-fact emergency response For a total of 3 deftemplates. CLIPS> (list-deffacts)  initial-fact For a total of 1 deffacts. CLIPS>

Pretty Print Example: 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>

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

Clearing all Constructs Syntax: (clear) Example: CLIPS> (list-deffacts)  CLIPS> (list-deftemplates)  emergency response start-fact For a total of 3 deftemplates. CLIPS> (clear)  CLIPS> (list-deffacts)  initial-fact For a total of 1 deffacts. CLIPS> (list-deftemplates)  initial-fact For a total of 1 deftemplate. CLIPS> After clearing, it adds the initial-facts deffacts to the environment.

Printout Syntax: (printout *) 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

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

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))

Loading Constructs Syntax: (load ) Example: CLIPS> (load “fire.clp”)  Defining deftemplate: emergency Defining deftemplate: response Defining defrule: fire-emergency +j TRUE CLIPS> If compilations are not being watched, then the character *, %, and $ will be used for defrules, deftemplates, and deffacts. 7.17

Saving Constructs Syntax: (save ) Example: (save “B:fire.clp”)

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))