Presentation is loading. Please wait.

Presentation is loading. Please wait.

Introduction to CLIPS 2 Session 13 Course: T0273 – EXPERT SYSTEMS Year: 2014.

Similar presentations


Presentation on theme: "Introduction to CLIPS 2 Session 13 Course: T0273 – EXPERT SYSTEMS Year: 2014."— Presentation transcript:

1

2 Introduction to CLIPS 2 Session 13 Course: T0273 – EXPERT SYSTEMS Year: 2014

3 Learning Outcomes LO 4 : Demonstrate the algorithm using Expert Systems tools After taking this course, students should be expected to use CLIPS as a tool to build an expert system. 3T0273 - Expert Systems

4 Lecture Outline Commands for Manipulating Constructs The Printout Command Using Multiple Rules The Set-Break Command Loading and Saving Constructs Commenting Constructs Variables Multiple Use of Variables Fact Addresses Single-Field Wildcards Blocks World Multifield Wildcards and Variables Summary Exercise 4T0273 - Expert Systems

5 Commands for Manipulating Constructs The list-defrules command is used to display the current list of rules maintained by CLIPS. Similarly, the list- deftemplates and list-deffacts commands, respectively can be used to display the current list of deftemplates or the current list of deffacts. (list-defrules) (list-deftemplates) (list-deffacts) The ppdefrule, ppdeftemplate, ppdeffacts commands are used to display the text representations of a defrule, a deftemplate, and a deffacts respectively. (ppdefrule ) (ppdeftemplate ) (ppdeffacts ) 5T0273 - Expert Systems

6 Commands for Manipulating Constructs The undefrule, undeftemplate, and undeffacts commands are used to delete a defrule, a deftemplate, and a deffacts, respectively. (undefrule ) (undeftemplate ) (undeffacts ) The clear command can be used to remove all information contained in the CLIPS environment. (clear) 6T0273 - Expert Systems

7 The Printout Command Beside asserting facts in the RHS of rules, the RHS can also be used to print out information using the printout command. (printout *) The following rule demonstrates the use of the printout command: (defrule fire-emergency (emergency (type fire)) => (printout t “Activate the sprinkler system” crlf)) 7T0273 - Expert Systems

8 Using Multiple Rules Practical expert systems may consist of hundreds or thousands of 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)) 8T0273 - Expert Systems

9 The Set-Break Command CLIPS has a debugging command called set-break that allows execution to be halted before any rule from a specified group of rules is fired. A rule that halts execution before being fired is called a breakpoint. (set-break ) The show-breaks command can be used to list all breakpoints. (show-breaks) The remove-break command can be used to remove breakpoints. (remove-break [ ]) 9T0273 - Expert Systems

10 Loading and Saving Constructs A file of constructs made with a text editor can be loaded into CLIPS using the load command. (load ) (load “N:fire.clp”) CLIPS also provides the opposite of the load command. The save command allows the set of constructs stored in CLIPS to be saved to a disk file. (save ) (save “B:fire.clp”) 10T0273 - Expert Systems

11 Commenting Constructs Comments are used for good documentation of programs and will be helpful in lengthy programs. A comment in CLIPS is any text that begins with a semicolon and ends with a carriage return. ; Deftemplates (deftemplate emergency “template #1” (slot type)); What type of emergency (deftemplate response “template #2” (slot type)); How to respond ; The purpose of this rule is to activate ; the sprinkler system if there is a fire 11T0273 - Expert Systems

12 Variables Just as with other programming languages, CLIPS has variables available to store values. Variables are always written in the syntax of a question mark followed by a symbolic field name. Variable names follow the syntax of a symbol, with the exception that they must begin with a character. ?speed ?sensor ?value ?noun ?color 12T0273 - Expert Systems

13 Multiple Use of Variables Instead of writing a single rule that looks only for people with blue eyes, a fact can be asserted that indicates the specific color of eyes to look for. CLIPS> (undefrule *) ↵ CLIPS> (deftemplate find (slot eyes)) ↵ CLIPS> (defrule find-eyes (find (eyes ?eyes)) (person (name ?name) (eyes ?eyes)) => (printout t ?name “ has “ ?eyes “ eyes.” crlf)) ↵ CLIPS> 13T0273 - Expert Systems

14 Fact Addresses Before a fact can be manipulated from the RHS of a rule, however, there must be some way to specify the fact that matched a particular pattern. To accomplish this, a variable can be bound to the fact address of the fact matching a pattern on the LHS of a rule by using the pattern binding operator, “<-”. CLIPS> (defrule process-moved-information ?f1 <- (moved (name ?name) (address ?address)) ?f2 <- (person(name ?name)) => (retract ?f1) (modify ?f2 (address ?address))) ↵ 14T0273 - Expert Systems

15 Single-Field Wildcards Instead of using a variable, a single-field wildcard can be used when a field is required, but the value is not important. A single-field wildcard is represented by a question mark. (defrule print-social-security-numbers (print-ss-numbers-for ?last-name) (person (name ? ? ?last-name) (social-security-number ?ss-number)) => (printout t ?ss-number crlf)) 15T0273 - Expert Systems

16 Blocks World To demonstrate variable bindings, we will build a program to move blocks in a simple blocks world. The only things of interest in a blocks world are blocks. The goal of a complex blocks world program is to rearrange the stacks of blocks into a goal configuration with the minimum number of moves. To begin to solve this problem, it will be useful to set up a configuration of blocks that can be used for testing the program. See the example in your textbook page 424-429 16T0273 - Expert Systems

17 Multifield Wildcards and Variables Multifield wildcards and variables can be used to match against zero or more fields of a pattern. The multifield wildcard is indicated by a dollar sign followed by a question mark, “$?”, and represents zero or more occurrences of a field. (defrule print-social-security-numbers (print-ss-numbers-for ?last-name) (person (name $? ?last-name) (social-security-number ?ss-number)) => (printout t ?ss-number crlf)) 17T0273 - Expert Systems

18 Multifield Wildcards and Variables Just as single-field variables are preceded by a “?”, multifield variables are preceded by a “S?”. (defrule print-children (print-children $?name) (person (name $?name) (children $?children)) => (printout t ?name “ has children “ ?children crlf)) 18T0273 - Expert Systems

19 Summary Practical expert systems may consist of hundreds or thousands of rules. Comments are used for good documentation of programs and will be helpful in lengthy programs. Just as with other programming languages, CLIPS has variables available to store values. The goal of a complex blocks world program is to rearrange the stacks of blocks into a goal configuration with the minimum number of moves. 19T0273 - Expert Systems

20 Exercise You have to create an Expert system for New Toyota Yaris for detecting troubles and give solution. –Please explain stages in development of an Expert Systems –Explain variables and components in the development phase –Create the main construction of the program using CLIPS 20T0273 - Expert Systems

21 Joseph Giarratano, Gary Riley. 2005. Expert Systems: Principles and Programming Chapter 7. Thomson Course Technology. Australia. ISBN:0-534-38447-1. Peter Jackson. 1998. Introduction to Expert Systems. Addison-Wesley. Harlow, England. ISBN:0201876868 References T0273 - Expert Systems21


Download ppt "Introduction to CLIPS 2 Session 13 Course: T0273 – EXPERT SYSTEMS Year: 2014."

Similar presentations


Ads by Google