Download presentation
Presentation is loading. Please wait.
2
Introduction to CLIPS (Chapter 7) Fact List (contains data) Knowledge Base (contains rules) Inference Engine (controls execution)
3
Overview n CLIPS is a programming language that provides support for rule-based, object- oriented and procedural programming. n The search in the Inference Engine uses forward chaining and rule prioritization. n Looks like LISP (List Processing) with object features.
4
Object Features n CLIPS Object-Oriented Language (COOL) is a hybrid of features found in Common Lisp Object and SmallTalk. n Example: object template or frame for a bearing – (deftemplate bearing (slot type) (slot size) (slot load) (slot lubrication) (slot max_temperature)...)
5
Car Frame or Template Example SlotsFillers Namecar name Typesedan, sports, station_wagon.. ManufacturerGM, Ford, Chrysler, Toyota... OwnerName of owner Wheels4, 6 Transmissionmanual, automatic Enginegasoline, diesel, methanol Conditionlemon, OK, peach Under-warrantyno, yes
6
Car Instance Example SlotsFillers NameAlice’s car Typestation_wagon ManufacturerGM OwnerAlice M. Agogino Wheels4 Transmissionmanual Enginegasoline ConditionOK Under-warrantyyes
7
Notation n Everything in parentheses is to be entered exactly are shown within the parentheses. (exit) or (+ 6 3 2) n Square brackets indicate that the contents are optional. (example [1]) n Pointed brackets indicate that a replacement is to be made with a value of the type specified within the brackets. (example )
8
Elementary Math Operators n Arithmetic – Addition (+ 6 3 2) – Subtraction (- 6 3 2) – Multiplication (* 6 3 2) – Division (/ 6 3 2) n Logical Arithmetic – (> 6 3 2) – (< 6 3 2)
9
Notation wild cards n A * following a description indicates that the description can be replaced with zero or one or more occurrences of the value, separated by spaces. n A + following a description indicates that the description can be replaced with one or more occurrences of the value, separated by spaces. n + is equivalent to * n A vertical bar | indicates a choice among one or more of the items separated by the bars. n A | B | C means (A, B or C).
10
Fields n Tolkens represent groups of characters that have special meaning in CLIPS. n Fields or CLIPS primitive data types are groups of tokens. n Seven types of Fields – Float – Integer – Symbol – String – External address – Instance name – Instance address
11
Facts n A “chunk” of information in CLIPS is called a fact. n Facts consist of a relation name followed by zero or more slots and their associated values.
12
Deftemplate Construct n A template for a fact needs to be defined in order to determine the name and number and types of slots. n (deftemplate [ ] *] n (deftemplate apple “facts about the color of apples” (slot color))
13
Multifield Slots n Use multislot in cases where you want an undefined zero or more “arity” to the slot. n (deftemplate apple “facts about the color of apples” (multislot color)) n (assert (apple (color red))) n (assert (apple (color green))) n (assert (apple (color red green)))
14
Adding and Removing Facts n New facts are added with the assert command: (assert +) n Facts can be listed with: (facts) n Facts are numbered sequentially starting with 1. (fact 0 is baseline). n Remove facts with: (retract + ) n Facts can also be duplicated with slot modifications (duplicate 0 (color brown)).
15
Deffacts Construct n Useful for automatically asserting a set of facts. n Useful for defining initial knowledge. n Assumes template of first item and single slots by default. n (deffacts apple “apple color facts” (apple (color red)) (apple (color green)))
16
Watch Command n The watch command is for debugging programs. n (watch ) n ): – Facts or Rules – Activations – Statistics & Compilations – Focus or all
17
Rules n Rules are in the following form: (defrule [ ] * ; condition or left-hand side (LHS) => ; implies * ;action, consequence or right-hand side (RHS) n ( => *) or (IF * *)
18
Manipulating Constructs n Listing members of a construct: – (list-defrules) – (list-deftemplates) – (list-deffacts) n Display text of a construct with pp (pretty print command): – (ppdefrules ) – (ppdeftemplates ) – (ppdeffacts )
19
Deleting Constructs n Delete a member by undefining: – (undefrule ) – (undeftemplates ) – (undeffacts ) n Delete all with clear command: (clear)
20
Load, Save, Print, Break commands n Load and Save files: – (load ) – (save ) n printout command: – (printout *) – Default is usually the terminal. n The set-break command allows the execution to be halted before a rule is fired: (set-break )
21
Agenda and Execution n A CLIPS program can be made to run with the run command. – (run [ ]) – Where the optional is the maximum number of rules to be fired. n Rules which can be activated are put on the agenda list. n The rule with the highest salience or priority on the agenda is fired.
22
Pattern Matching: Rules and Facts Agenda FactsRules Inference Engine
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.