Chapter 7: Introduction to CLIPS Presented By: Farnaz Ronaghi.

Slides:



Advertisements
Similar presentations
The CLIPS Programming Tool History of CLIPS –Influenced by OPS5 and ART –Implemented in C for efficiency and portability –Developed by NASA, distributed.
Advertisements

CLIPS 1 Expert Systems Dr. Samy Abu Nasser. CLIPS 2 Course Overview u Introduction u CLIPS Overview u Concepts, Notation, Usage u Knowledge Representation.
The Web Warrior Guide to Web Design Technologies
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.
Chapter 8 Pattern Matching
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.
Lecture 2 Introduction to C Programming
Introduction to C Programming
 2005 Pearson Education, Inc. All rights reserved Introduction.
1 Chapter 2 Introduction to Java Applications Introduction Java application programming Display ____________________ Obtain information from the.
2440: 211 Interactive Web Programming JavaScript Fundamentals.
VBA Modules, Functions, Variables, and Constants
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.
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.
Introduction to Jess.
About the Presentations The presentations cover the objectives found in the opening of each chapter. All chapter objectives are listed in the beginning.
Guide To UNIX Using Linux Third Edition
JavaScript, Third Edition
Guide To UNIX Using Linux Third Edition
Introduction to C Programming
CS 561, Session 25 1 Introduction to CLIPS Overview of CLIPS Facts Rules Rule firing Control techniques Example.
Introduction to Array The fundamental unit of data in any MATLAB program is the array. 1. An array is a collection of data values organized into rows and.
Chapter 3: Introduction to C Programming Language C development environment A simple program example Characters and tokens Structure of a C program –comment.
Chapter Seven Advanced Shell Programming. 2 Lesson A Developing a Fully Featured Program.
XP New Perspectives on XML Tutorial 3 1 DTD Tutorial – Carey ISBN
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.
Expert System Topic 2.
Chapter 7: Introduction to CLIPS Expert Systems: Principles and Programming, Fourth Edition.
Copyright © 2012 Pearson Education, Inc. Publishing as Pearson Addison-Wesley C H A P T E R 2 Input, Processing, and Output.
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.
1 Tutorial 13 Validating Documents with DTDs Working with Document Type Definitions.
Input, Output, and Processing
© Copyright 1992–2004 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. Chapter 2 Chapter 2 - Introduction to C Programming.
Week 1 Algorithmization and Programming Languages.
Copyright © 2010 Certification Partners, LLC -- All Rights Reserved Perl Specialist.
 Pearson Education, Inc. All rights reserved Introduction to Java Applications.
IMSS013 CLIPS. 2 Background CLIPS is an expert system tool developed by the Software Technology Branch (STB), NASA/Lyndon B. Johnson Space Center. First.
Copyright © 2012 Pearson Education, Inc. Publishing as Pearson Addison-Wesley C H A P T E R 2 Input, Processing, and Output.
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>
Artificial Intelligence Lecture No. 26 Dr. Asad Ali Safi ​ Assistant Professor, Department of Computer Science, COMSATS Institute of Information Technology.
Copyright © 2003 ProsoftTraining. All rights reserved. Perl Fundamentals.
Introduction to CLIPS. Expert Systems: Principles and Programming, Fourth Edition2 What is CLIPS? CLIPS is a multiparadigm programming language that provides.
CSC 1010 Programming for All Lecture 3 Useful Python Elements for Designing Programs Some material based on material from Marty Stepp, Instructor, University.
Artificial Intelligence Lecture No. 19 Dr. Asad Ali Safi ​ Assistant Professor, Department of Computer Science, COMSATS Institute of Information Technology.
© Copyright 1992–2004 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. 1 Chapter 2 - Introduction to C Programming Outline.
Artificial Intelligence Lecture No. 22 Dr. Asad Ali Safi ​ Assistant Professor, Department of Computer Science, COMSATS Institute of Information Technology.
Chapter 4: Variables, Constants, and Arithmetic Operators Introduction to Programming with C++ Fourth Edition.
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.
Intelligent Systems JESS constructs.
Chapter 7: Introduction to CLIPS
Topics Introduction to File Input and Output
Chapter 8: Advanced Pattern Matching
بسم الله الرحمن الرحیم آموزش نرم افزار CLIPS
Chapter 11: Classes, Instances, and Message-Handlers
New Perspectives on XML
CPE/CSC 481: Knowledge-Based Systems
Topics Introduction to File Input and Output
Presentation transcript:

Chapter 7: Introduction to CLIPS Presented By: Farnaz Ronaghi

2 Objectives  Learn what type of language CLIPS is  Study the notation (syntax) used by CLIPS  Learn the meaning of a field and what types exit  Learn how to launch and exit from CLIPS  Learn how to represent, add, remove, modified, and duplicated in CLIPS

3 Objectives  Learn how to debug programs using the watch command  Learn how to use the deffacts construct to define a group of facts  Learn how to use the agenda command and execute CLIPS programs  Learn about commands that can manipulate constructs

4 Objectives  Learn how to use the printout command  Learn how to use multiple rules  Learn how to use the set-break command  Learn how to use the load and save constructs  Learn how to use variables, single and multifield wildcards, and comment constructs

5 What is CLIPS?  CLIPS is a multiparadigm programming language that provides support for: Rule-based Object-oriented Procedural programming  Syntactically, CLIPS resembles: Eclipse CLIPS/R2 JESS

6 Other CLIPS Characteristics  CLIPS supports only forward-chaining rules.  The OOP capabilities of CLIPS are referred to as CLIPS Object-Oriented Language (COOL).  The procedural language capabilities of CLIPS are similar to languages such as: C Ada Pascal Lisp

7 CLIPS Characteristics  CLIPS is an acronym for C Language Integrated Production System.  CLIPS was designed using the C language at the NASA/Johnson Space Center.  CLIPS is portable – PC  CRAY.

8 CLIPS Notation  Symbols other than those delimited by, [ ], or { } should be typed exactly as shown. (exit)  [ ] mean the contents are optional and mean that a replacement is to be made.  * following a description means that the description can be replaced by zero or more occurrences of the specified value.

9 CLIPS Notation  Descriptions followed by + mean that one or more values specified by description should be used in place of the syntax description.  A vertical bar | indicates a choice among one or more of the items separated by the bars. ::= [ + | - ] +

10 Fields  To build a knowledge base, CLIPS must read input from keyboard / files to execute commands and load programs.  During the execution process, CLIPS groups symbols together into tokens – groups of characters that have the same meaning.  A field is a special type of token of which there are 8 types.

11 Numeric Fields  The floats and integers make up the numeric fields – simply numbers.  Integers have only a sign and digits  Floats have a decimal and possibly “e” for scientific notation. 237e e-7

12 Symbol Fields  Symbols begin with printable ASCII characters followed by zero or more characters, followed by a delimiter.  CLIPS is case sensitive.  Can not begin with ? Or $? Which are reserved for variables foo

13 Symbol Fields  Delimiters include: Non-printable ASCI characters Double quote Opening and closing parenthesis Ampersand Vertical bar Less than symbol Tilde Semicolon (used for comments)  Delimiters may not be included in a symbol except for < that may be the first character in a symbol

14 String Fields  Strings must begin and end with double quotation marks  The actual delimiter symbols can be included in a string by preceding the character with a backslash. “foo” “a and b” “a\”quote” “1 number”

15 Address Fields  External addresses represent the address of an external data structure returned by a user-defined function (written in a language like C or Ada integrated with CLIPS).  This can only be created by calling a function  The printed representation is where xxxxxx is an external adress  Refer to the advanced programming guide in CD

16 Address Fields  A fact is a list of atomic values that are either referenced appositionally or by name.  Facts are referred by index or Address.  The printed representation of a fact-adress is: where xxx is the fact index.

17 Entering / Exiting CLIPS  The CLIPS prompt is: CLIPS>  This is the type-level mode where commands can be entered.  To exit CLIPS, one types: CLIPS> (exit)   CLIPS will accept input from the user / evaluate it / return an appropriate response: CLIPS> ( )   value 12 would be returned.

18 Facts and CLIPS  To solve a problem, CLIPS must have data or information with which to reason.  Fundamental units of data used by rules, they are placed in the current list of facts called the fact-list.  Each chunk of information is called a fact.  Facts consist of: Relation name (symbolic field) Zero or more slots with associated values

19 Example Fact in CLIPS  Person( (name “John Public”) (age 23) (eye-color blue) (hair-color black) ) Relation name Slot name Slot value

20 Deftemplate  Before facts can be constructed, CLIPS must be informed of the list of valid slots for a given relation name.  A deftemplate is used to describe groups of facts sharing the same relation name and contain common information.

21 Deftemplate General Format  (deftamplate [ ] * )  (deftemplate person “an example!” (slot name) (slot eye-color) (slot hair-color) (slot age) ) (slot ) | (multislot )

22 Deftemplate vs. Ordered Facts  Facts with a relation name defined using deftemplate are called deftemplate facts.  Facts with a relation name that does not have a corresponding deftemplate are called ordered facts – have a single implied multifield slot for storing all the values of the relation name. (father-of jack bill)  we may mean jack is bill’s father It will be considered as one fact

23 Adding Facts  CLIPS store all facts known to it in a fact list.  To add a fact to the list, we use the assert command. (deftemplate student (slot name) (slot age) (slot major)) (assert (student (name “farnaz”) (age 16) (major “computer”) ) )

24 Displaying Facts  CLIPS> (facts)  f-0 (student (name “farnaz”) (age 16) (major “comp’) ) For a total of 1 fact  (facts ) will display the fact with the specified identifier Fact identifier

25 Removing Facts  Just as facts can be added, they can also be removed.  Removing facts results in gaps in the fact identifier list.  To remove a fact: CLIPS> (retract 2)   Use (clear) or (retract*) to remove all facts

26 Modifying Facts  Slot values of deftemplate facts can be modified using the modify command (modify fact-index +) ( ) >(modify 0 (age 21)) f-1 (student (name “farnaz”) (age 21) (major “computer”)) for a total of 1 fact

27 Results of Modification  A new fact index is generated because when a fact is modified: The original fact is retracted The modified fact is asserted  The duplicate command is similar to the modify command, except it does not retract the original fact.

28 Watch Command  The watch command is useful for debugging purposes.  If facts are “watched”, CLIPS will automatically print a message indicating an update has been made to the fact list whenever either of the following has been made: Assertion Retraction  To cancel watching use unwatch command

29 Watching facts  CLIPS> (watch facts)  CLIPS> (assert (is-animal dog))  f-0 (is-animal dog)  CLIPS> (reset)  f-0 (is-animal dog)  f-0 (initial-fact) The default CLIPS fact

30 Deffacts Construct  The deffacts construct can be used to assert a group of facts.  Groups of facts representing knowledge can be defined as follows: (deffacts [ comment] * )  The reset command is used to assert the facts in a deffacts statement, used for initialization

31 The Components of a Rule  To accomplish work, an expert system must have rules as well as facts.  Rules can be typed into CLIPS (or loaded from a file).  Consider the pseudocode for a possible rule: IF the emergency is a fire THEN the response is to activate the sprinkler system

32 Rule Components  First, we need to create the deftemplate for the types of facts: -- type would be fire, flood, etc.  Similarly, we must create the deftemplate for the types of responses: -- action would be “activate the sprinkler” (deftemplate emergency (slot type)) (deftemplate response (slot action))

33 Rule Components  The rule would be shown as follows: (defrule fire-emergency “An example rule” (emergency )type fire)) => (assert (response (action activate-sprinkler-system))))

34 Analysis of the Rule  The header of the rule consists of three parts: 1. Keyword defrule 2. Name of the rule – fire-emergency 3. Optional comment string – “An example rule”  After the rule header are 1+ conditional elements, called patterns  If all the patterns of a rule match facts, the rule is activated and put on the agenda.

35 Analysis of Rule  The agenda is a collection of activated rules.  The arrow => represents the beginning of the THEN part of the IF-THEN rule.  The last part of the rule is the list of actions that will execute when the rule fires. fire: the rule has been selected by CLIPS to be executed

36 Activated rules  A rule is activated if its patterns are matched by a: A brand new entity that did not exist before A pattern entity that did exist before but retracted and reasserted, a clone of old pattern entity, and thus a new pattern entity.  The rule, and the indices of matching patterns, is the activation.  If either the rule or pattern entities change the activation is removed.  It may also be removed by action of a rule fired before that has removed necessary conditions for activation

37 The Agenda and Execution  To run the CLIPS program, use the run command : CLIPS> (run [ ])  -- the optional argument is the maximum number of rules to be fired – if omitted, rules will fire until the agenda is empty.

38 Execution  When the program runs, the rule with the highest salience on the agenda is fired.  This sorting process according to salience is called conflict resolution because it eliminates the conflict of which rule should fire first.  After execution the activation is removed  A mechanism named refraction will avoid CLIPS from trivial traps. Refraction is the property that rules will not fire more than once for a specific set of facts.

39 The reset command  The reset command is the key method for starting or restarting.  Facts asserted by a reset satisfy the patterns of one or more rules and place activation of these rules on the agenda.

40 What is on the Agenda?  To display the rules on the agenda, use the agenda command: CLIPS> (agenda)   The refresh command can be used to make a rule fire again by placing all activations that have already fired for a rule back on the agenda.  You can also watch how activations change (watch activations)

41 Command for Manipulating Constructs  The list-defrules command is used to display the current list of rules maintained by CLIPS.  The list-deftemplates displays the current list of deftemplates.  The list-deffacts command displays the current list of deffacts.  The ppdefrule, ppdeftemplate and ppdeffacts commands display the text representations of a defrule, deftemplate, and a deffact, respectively.

42 Some other useful Commands  The undefrule, undeftemplate, and undeffacts commands are used to delete a defrule, a deftemplate, and a deffact, respectively.  The printout command can also be used to print information. CLIPS>(printout t “stop” crlf) t means that the string will be printed to standard output device

43 Other Commands  Set-break – allows execution to be halted before any rule from a specified group of rules is fired. Used for debugging, the rule will be used as breakpoint  Load – allows loading of rules from an external file.  Save – opposite of load, allows saving of constructs to disk (save “fire.clp”)  will save all the written codes in a file named “fire.clp” Save-fact will save all facts in the fact list in a file and load-fact will load it

44 Commenting and Variables  Comments – provide a good way to document programs to explain what constructs are doing.  Variables – store values, syntax requires preceding with a question mark (?)

45 Variables  Variable identifier is always written by a question mark followed by a symbol that is the name of the variable  Before a variable can be used, it should be assigned a value CLIPS> (defrule test (initial-fact) => (printout t ?x )) CLIPS will show you an error message

46 Variable’s usage (defrule make-quack (quack-sound ?sound) => (assert (sound-is ?sound))) (defrule make-quack (quack-sound ?sound) => (assert (sound-is ?sound)))

47 Variable’s usage (defrule find-eyes (find eyes ?eye) (person (eye-color ?eye) (name ?name)) => (printout t ?name “ has ” ?eye “ eyes”)) (defrule find-eyes (find eyes ?eye) (person (eye-color ?eye) (name ?name)) => (printout t ?name “ has ” ?eye “ eyes”))

48 Variable’s usage (defrule marriage ?duck (printout t “?name married”) (retract ?duck)) (defrule marriage ?duck (printout t “?name married”) (retract ?duck))

49 Wildcards (defrule dating-ducks (bachelor Depoy ?) => (printout t “meet depoy”)) (deffacts duck (bachelor depoy) (bachelor depoy mallard) (bachelor depoy dicky mallard) (bachelor dicky depoy)) (reset) (run) meet depoy

50 Wildcards (defrule dating-ducks (bachelor Depoy $?) => (printout t “meet depoy”)) (deffacts duck (bachelor depoy) (bachelor depoy mallard) (bachelor depoy dicky mallard) (bachelor dicky depoy)) (reset) (run) meet depoy

51 Summary  In this chapter, we looked at the fundamental components of CLIPS.  Facts make up the first component of CLIPS, made up of fields – symbol, string, integer, or float.  The deftemplate construct was used to assign slot names to specific fields of a fact.  The deffacts construct was used to specify facts as initial knowledge.

52 Summary  Rules make up the second component of a CLIPS system.  Rules are divided into LHS – IF portion and the RHS – THEN portion.  Rules can have multiple patterns and actions.  The third component is the inference engine – rules having their patterns satisfied by facts produce an activation that is placed on the agenda.

53 Summary  Refraction prevents old facts from activating rules.  Variables are used to receive information from facts and constrain slot values when pattern matching on the LHS of a rule.  Variables can store fact addresses of patterns on the LHS of a rule so that the fact bound to the pattern can be retracted on the RHS of the rule.  We also looked at single-field wildcards and multifield variables.