The CLIPS Expert System Shell Dr Nicholas Gibbins

Slides:



Advertisements
Similar presentations
Expert systems CLIPS Seyed Hashem Davarpanah
Advertisements

CIS 240 Introduction to UNIX Instructor: Sue Sampson.
(FO) Inference Methods CPSC 386 Artificial Intelligence Ellen Walker Hiram College.
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.
Debugging What can debuggers do? Run programs Make the program stops on specified places or on specified conditions Give information about current variables’
Expert System Shells - Examples
Introduction to Unix – CS 21 Lecture 11. Lecture Overview Shell Programming Variable Discussion Command line parameters Arithmetic Discussion Control.
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.
Mary Lou Maher MIT Fall 2002 Jess: A Production System Language Agent-Based Virtual Worlds.
© 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.
Introduction to Jess.
Jess Presentation by Chun Ping Wang. What is Jess? Jess is an expert system shell made for java. Rete pattern algorithm. Purpose. –Jess is best use for.
CS 561, Session 25 1 Introduction to CLIPS Overview of CLIPS Facts Rules Rule firing Control techniques Example.
Testing a program Remove syntax and link errors: Look at compiler comments where errors occurred and check program around these lines Run time errors:
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.
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.
Writing C-shell scripts #!/bin/csh # Author: Ken Berman # Date: # Purpose: display command and parameters echo $0 echo $argv[*]
CS 403: Programming Languages Fall 2004 Department of Computer Science University of Alabama Joel Jones.
Java Expert System Shell JESS 報告者 : 江梓安. Why we need an expert systems? Conventional programming languages Conventional programming languages Complex.
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.
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>
Searching and Sorting. Why Use Data Files? There are many cases where the input to the program may come from a data file.Using data files in your programs.
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.
1 Knowledge Based Systems (CM0377) Lecture 10 (Last modified 19th March 2001)
1 Printing in Python Every program needs to do some output This is usually to the screen (shell window) Later we’ll see graphics windows and external files.
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.
Linux Administration Working with the BASH Shell.
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
For loops Taken from notes by Dr. Neil Moore
Computer Based Tutoring
Presentation transcript:

The CLIPS Expert System Shell Dr Nicholas Gibbins

The CLIPS Expert System Shell A framework for building expert systems –Don’t need to build basic infrastructure every time you build an expert system Commonly used and well-understood –First developed at NASA JSC in mid-1980s Provides the following facilities: –Representation of facts and rules –Search mechanism for identifying and firing matching rules

Facts in CLIPS Represented in CLIPS by s-expressions: –(likes fred sally) –likes, fred and sally are symbols Two types of CLIPS fact –Ordered (as above) –Unordered, specified using deftemplate (we’ll come to this later)

Starting and stopping CLIPS Run CLIPS from the UNIX command line: CLIPS> To quit CLIPS, type (exit)

Asserting facts Add a new fact to the knowledge base with assert : CLIPS> (assert (likes fred mary)) CLIPS> Check for asserted facts with facts : CLIPS> (facts) f-0 (likes fred mary) For a total of 1 fact. CLIPS> The 0 in f-0 and Fact-0 is the fact-index of the new fact

Retracting facts Remove a fact from the knowledge base with retract: CLIPS> (assert (likes fred mary)) CLIPS> (facts) f-0 (likes fred mary) For a total of 1 fact. CLIPS> (retract 0) CLIPS> (facts) CLIPS> Note that you need to know the fact-index to retract a fact Remove all facts from the knowledge base using (clear)

Watching the knowledge base Observe the activity in the knowledge base using watch : CLIPS> (watch facts) CLIPS> (assert (likes fred mary)) ==> f-0 (likes fred mary) CLIPS> (retract 0) ==> indicates that a fact is being added <== indicates that a fact is being removed Turn off watch using (unwatch facts)

Creating rules A simple rule: (defrule mary-loved (likes fred mary) => (assert (loved mary))) The name of the rule The rule condition The rule action

Rules in general (defrule “optional comment”...) Everything before => is known as the left-hand side (LHS), everything after the right-hand side (RHS) The rule is fired if all of the conditions in the LHS match When the rule fires, all of the actions are carried out

The Agenda The list of rules which are waiting to be fired (the conflict set) is known as the agenda This can be examined using (agenda) : CLIPS> (agenda) 0 mary-loved: f-0 For a total of 1 activation. CLIPS>

Running your rules Start executing your rules with run: CLIPS> (run) ==> f-1 (loved mary) CLIPS> Execution continues until there are no rules left to be fired (the agenda is empty) Can control number of rule firings with (run )

Variables We can have variables in the conditions of our rules: (defrule loved (likes ?sub ?obj) => (assert (loved ?obj)))

Variables CLIPS> (assert (likes fred mary)) ==> f-0 (likes fred mary) CLIPS> (assert (likes fred sue)) ==> f-1 (likes fred sue) CLIPS> (agenda) 0 loved: f-1 0 mary-loved: f-0 0 loved: f-0 For a total of 3 activations. CLIPS> (run) ==> f-2 (loved sue) ==> f-3 (loved mary) CLIPS>

Loading from files If your rules are defined in a file called myrules.clp At the shell command line: $ clips -f myrules.clp At the CLIPS command line: CLIPS> (load “myrules.clp”)

Retracting facts (defrule remove-liked ?fact (retract ?fact)) <- binds the address of a matching fact to a variable

Anonymous variables If we’re not interested in the value of a variable, we can match using a single-field wildcard variable: ? (defrule remove-liked ?fact (retract ?fact))

Multifield variables Consider a knowledge base with variable-length facts of the form (route town-1 town-2 town-3 … town-n) If we wish to match all routes that start at A and end at B, we can match all the intermediate towns using a multifield wildcard: $? Multifield variables match a list of objects (…) (defrule find-route (route town-a $?towns town-b) => (printout t “Route from A to B via “ ?towns crlf))

Multifield variables We have a fact: (route a b c d e f g h) In how many ways can this be matched by this pattern? (route $?start ?item $?end)

Multifield variables $?start = (), ?item = a, $?end = (b c d e f g h) $?start = (a), ?item = b, $?end = (c d e f g h) $?start = (a b), ?item = c, $?end = (d e f g h) $?start = (a b c), ?item = d, $?end = (e f g h) $?start = (a b c d), ?item = e, $?end = (f g h) $?start = (a b c d e), ?item = f, $?end = (g h) $?start = (a b c d e f), ?item = g, $?end = (h) $?start = (a b c d e f g), ?item = h, $?end = ()

Field Constraints We can further constraint the values taken by variables ~symbol matches anything but symbol symbol1|symbol2 matches either symbol1 or symbol2 symbol1&symbol2 matches both symbols ?var&constraint matches anything that satisfies the constraint, and assigns it to ?var

Test Conditions LHS of rule can contain other sorts of constraints on variable values (see BPG p. 47) For example: (defrule my-rule (age fred ?var1) (age sally ?var2) (test (> ?var1 ?var2)) => … )

Functions CLIPS has a number of built-in functions which can be invoked like their Scheme look-a-likes: (+ 1 2) Complete list of built-in functions starting at p.149 of the CLIPS reference manual (Basic Programming Guide)

Defining functions We can define a custom function using deffunction: (deffunction square (?x) (* ?x ?x))

Defining functions (deffunction function-name (?arg1 ?arg2... $?args) (action1 action2... actionn)) Value returned by function is that of last action Final argument may be a multifield variable

Binding variables We can bind the result of a function to a variable: (bind ?sum (+ ?x ?y))

Example: Route Finding E E C C B B D D A A

Represent routes as facts of the form: (route start … end distance) For example: (route town-a town-b town-d town-e 16) How can we generate all of the shortest routes from every town to every other town?

Writing output We can write to stdout using printout: (defrule print-likes (likes ?x ?y) => (printout t ?x “ likes “ ?y crlf)) prints: “john likes sally”

Reading input (defrule read-colour (initial-fact) => (printout t “Name a colour” crlf) (assert (colour (read)))) (read) reads a single symbol, integer or string (readline) reads until the next carriage return

Templated facts The ordered lists of terms we’ve seen so far are only one kind of fact We can also create facts containing unordered (but named) terms: (car (colour red) (doors 4) (maker vw)) is the same as: (car (doors 4) (maker vw) (colour red))

Templated facts We introduce a new type of templated fact as follows: (deftemplate car (slot registration (type SYMBOL)) (slot color (type SYMBOL) (allowed-symbols white red green blue)) (slot doors (type INTEGER) (default 4)) (slot maker (type SYMBOL)))

Templated facts Templated facts are asserted like any other fact: (assert (car (registration g885tnj) (doors 4) (maker vw) (colour green)))

Example: Classification We wish to build an expert system to classify the following farmyard animals: –Dog –Cows –Chickens –Ducks –Pigs

Example: Classification Possible means for classification: –Fur/feathers/skin –Number of legs –Swims/doesn’t swim –Eats meat/grass/grain

Example: Classification (deftemplate observation (slot name (type SYMBOL)) (slot value)) (deftemplate classification (slot name (type SYMBOL)))