By: Dr. Christel Kemke Department of Computer Science University of Manitoba.

Slides:



Advertisements
Similar presentations
Introduction to Defining Classes. Objectives: Design and implement a simple class from user requirements. Organize a program in terms of a view class.
Advertisements

When is Orientated Programming NOT? Mike Fitzpatrick.
Chapter 7 User-Defined Methods. Chapter Objectives  Understand how methods are used in Java programming  Learn about standard (predefined) methods and.
The CLIPS Programming Tool History of CLIPS –Influenced by OPS5 and ART –Implemented in C for efficiency and portability –Developed by NASA, distributed.
Expert System Shells - Examples
© C. Kemke CLIPS 1 1 COMP 4200: Expert Systems Dr. Christel Kemke Department of Computer Science University of Manitoba.
Chapter 7: Introduction to CLIPS
Chapter 6 Introduction to Defining Classes
Solutions to Review Questions. 4.1 Define object, class and instance. The UML Glossary gives these definitions: Object: an instance of a class. Class:
Chapter 11: Classes, Instances, and Message- Handlers Expert Systems: Principles and Programming, Fourth Edition.
VBA Modules, Functions, Variables, and Constants
© 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.
Modelling classes Drawing a Class Diagram. Class diagram First pick the classes –Choose relevant nouns, which have attributes and operations. Find the.
C++ fundamentals.
Object Oriented Software Development
C++ Programming: Program Design Including Data Structures, Fourth Edition Chapter 13: Pointers, Classes, Virtual Functions, and Abstract Classes.
C++ Object Oriented 1. Class and Object The main purpose of C++ programming is to add object orientation to the C programming language and classes are.
Pointer Data Type and Pointer Variables
C++ Programming: From Problem Analysis to Program Design, Fourth Edition Chapter 14: Pointers, Classes, Virtual Functions, and Abstract Classes.
Chapter 9: Modular Design, Execution Control, and Rule Efficiency Expert Systems: Principles and Programming, Fourth Edition.
Chapter 11 Introduction to Classes Intro to Computer Science CS1510, Section 2 Dr. Sarah Diesburg.
Chapter 7: Introduction to CLIPS Expert Systems: Principles and Programming, Fourth Edition.
CMSC 202 Exceptions. Aug 7, Error Handling In the ideal world, all errors would occur when your code is compiled. That won’t happen. Errors which.
Lecture 7 Integrity & Veracity UFCE8K-15-M: Data Management.
Chapter 10: Procedural Programming Expert Systems: Principles and Programming, Fourth Edition.
11 Chapter 11 Object-Oriented Databases Database Systems: Design, Implementation, and Management 4th Edition Peter Rob & Carlos Coronel.
Using Client-Side Scripts to Enhance Web Applications 1.
CpSc 462/662: Database Management Systems (DBMS) (TEXNH Approach) Stored Procedure James Wang.
Data Structures Using C++ 2E1 Inheritance An “is-a” relationship –Example: “every employee is a person” Allows new class creation from existing classes.
JAVA: An Introduction to Problem Solving & Programming, 5 th Ed. By Walter Savitch and Frank Carrano. ISBN © 2008 Pearson Education, Inc., Upper.
Chapter 12 Support for Object oriented Programming.
CONTENTS Processing structures and commands Control structures – Sequence Sequence – Selection Selection – Iteration Iteration Naming conventions – File.
Chapter 10 Defining Classes. The Internal Structure of Classes and Objects Object – collection of data and operations, in which the data can be accessed.
Design Model Lecture p6 T120B pavasario sem.
Chapter 6 Introduction to Defining Classes. Objectives: Design and implement a simple class from user requirements. Organize a program in terms of a view.
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>
Copyright © 2006 Addison-Wesley. All rights reserved. Ambiguity in Grammars A grammar is ambiguous if and only if it generates a sentential form that has.
Artificial Intelligence Lecture No. 26 Dr. Asad Ali Safi ​ Assistant Professor, Department of Computer Science, COMSATS Institute of Information Technology.
Class Builder Tutorial Presented By- Amit Singh & Sylendra Prasad.
IT108 Objects and Classes Part I George Mason University Revised 4/3/2012.
2004 Hawaii Inter Conf Comp Sci1 Specifying and Proving Object- Oriented Programs Arthur C. Fleck Computer Science Department University of Iowa.
UMass Lowell Computer Science Java and Distributed Computing Prof. Karen Daniels Fall, 2000 Lecture 9 Java Fundamentals Objects/ClassesMethods Mon.
 In the java programming language, a keyword is one of 50 reserved words which have a predefined meaning in the language; because of this,
Introduction to Object-Oriented Programming Lesson 2.
Principles of programming languages 10: Object oriented languages Isao Sasano Department of Information Science and Engineering.
Artificial Intelligence Lecture No. 23 Dr. Asad Ali Safi ​ Assistant Professor, Department of Computer Science, COMSATS Institute of Information Technology.
Object-Oriented Design Concepts University of Sunderland.
Mostly adopted from Jason Morris notes (Morris Technical Solutions)
FIT Objectives By the end of this lecture, students should: understand the role of constructors understand how non-default constructors are.
Artificial Intelligence Lecture No. 22 Dr. Asad Ali Safi ​ Assistant Professor, Department of Computer Science, COMSATS Institute of Information Technology.
Object-Oriented Programming: Inheritance and Polymorphism.
Fusion Design Overview Object Interaction Graph Visibility Graph Class Descriptions Inheritance Graphs Fusion: Design The overall goal of Design is to.
POLYMORPHISM Chapter 6. Chapter Polymorphism  Polymorphism concept  Abstract classes and methods  Method overriding  Concrete sub classes and.
Object-Oriented Programming: Classes and Objects Chapter 1 1.
CPSC 252 ADTs and C++ Classes Page 1 Abstract data types (ADTs) An abstract data type is a user-defined data type that has: private data hidden inside.
UMass Lowell Computer Science Java and Distributed Computing Prof. Karen Daniels Fall, 2000 Lecture 10 Java Fundamentals Objects/ClassesMethods.
In this session, you will learn to: Create and manage views Implement a full-text search Implement batches Objectives.
Geoff Holmes and Bernhard Pfahringer COMP206-08S General Programming 2.
Introduction to CLIPS 2 Session 13 Course: T0273 – EXPERT SYSTEMS Year: 2014.
Intelligent Systems JESS constructs.
Chapter 7: Introduction to CLIPS
Java Programming Language
بسم الله الرحمن الرحیم آموزش نرم افزار CLIPS
Chapter 11: Classes, Instances, and Message-Handlers
Object-Oriented Programming: Inheritance and Polymorphism
CMSC 202 Exceptions.
Computer Based Tutoring
Presentation transcript:

By: Dr. Christel Kemke Department of Computer Science University of Manitoba

CLIPS – Classes (COOL) Intro to CLIPS – Classes (COOL) class definition class specification slot specification, facets instance creation message-handlers Classes and rules

CLIPS – Example Classes (defclass person (is-a USER) ;provides reference to system-defined ;super-class USER ( role concrete) ;this class can have instances (slot gender (type STRING)) ;just slots with type (slot age (type NUMBER))) ;constraints (defclass man (is-a person) (slot gender (type STRING)(default “male”))) Try: In the Browse-Menu, for the Defclass-Manager and check the messagehandlers of these classes.

CLIPS – Defining Classes (defclass person (is-a USER) ; provides reference to system-defined ;super-class USER (role concrete) ; this class can have instances (pattern-match reactive)* ; instances of this class can be ;used for pattern-matching in rules (slot ; slot-specification (create-accessor read-write) * ; read /write accessor ;created for this slot (default ); default-value for slot... *...)) * Class and Slot descriptions often have defaults, e.g. pattern-match reactive, or create-accessor read-write. Refer to the CLIPS bpg.

CLIPS – Defining Instances (definstances people people is a list of instances (mike of personof class person; instance (gender “male”)mike is created. (age 24)) ) (definstances men men is a list of instances of (mark of manclass man; here only one (age 24)) )instance named mark. Try: (send [mark] get-gender) and (send [mike] get-gender) Try: (send [mark] put-age 25) Note: instance-names in messages have to be put in [... ]

Message-Handlers (defmessage-handler ( *) ) Some message-handlers like get- or put- are system pre-defined message-handlers.

System-defined Message-Handlers retrieving and storing slot-values retrieve (send [instance] get-slot) e.g. (send [Titanic] get-speed) store (send [instance] put-slot value) e.g. (send [Titanic] put-speed 20)

Message-Handler - Example (defmessage-handler person birthday () (send ?self put-age (+ (send ?self get-age) 1)) ) Message-Handler 'birthday' associated with class person (no parameter) sends a message to ?self to put-age to the current age + 1. It also works to use 'dynamic-put' which sends a put- message for the age to the current instance to which the birthday-message has been sent. Try: (send [mark] birthday) Try: substitute (send ?self...) with dynamic-put or dynamic-get

Parameters in Message-Handlers (defmessage-handler ship set-speed (?x) (dynamic-put speed ?x)) ) Message-Handler set-speed associated with class ship sets the speed of the current instance to the value of ?x. e.g. (send [Titanic] set-speed 20) sends a message to the instance [Titanic] of ship which evaluates to (dynamic-put speed 20); or (send ?self put-speed 20)

if-then-else in Message-Handlers Control Structures used in Message-Handlers. instead of send to self: (dynamic-put speed 20)) instead of ?self:speed (dynamic-get speed)) Message-Handler 'slow-down' associated with class ship tests whether speed of addressed instance is > 30 and then sends a message to ?self to put-speed 20. It also works to use 'dynamic-put speed 20' which sends a put-message for speed to the current instance. (defmessage-handler ship slow-down () (if (> ?self:speed 30) then (send ?self put-speed 20)) )

Classes and Meta-Classes in CLIPS OBJECT USER Liner Ship Titanic domain instances user defined classes system defined classes INSTANCES CLASSES

Objects and Rules How to connect objects (instances) with rules? 1. read slot-values - use object (instance and slot- values) in condition part of rule 2. write slot-values - include put-messages in action-part of rule

Objects in Condition Part of Rule Solution 1: (object (name [ ]) ( )* ) Example 1: Comment: In the 'object'-pattern the name of the addressed instance is identified as [titanic] and the value for the slot speed (defined in the class ship) is determined as 20. This information is used for pattern matching. (defrule if-titanic-goes-20-mph (object (name [titanic]) (speed 20)) =>... )

Objects in Condition Part of Rule Use variables instead of slot-values (corresponding to facts used in rules, based on templates) Example 2: Comment: In the 'object'-pattern the speed of the referenced object (instance [titanic]) is bound to variable ?speed which can be used later in the printout-function. (defrule titanic-goes-at-what-speed (object (name [titanic]) (speed ?speed)) => (printout "Titanic goes at " ?speed " mph." crlf ) )

Objects in Condition Part of Rule Use variables instead of instance-names Example 3: Comment: In the 'object'-pattern the variable ?name is bound to the referenced object (e.g. the instance [titanic]) and thus can be used later in the action-part. (defrule any-ship-which-goes-20mph (object (name ?name) (speed 20mph)) => (printout ?name " goes at 20 mph." crlf ) )

Objects in Action Part of Rule In the action-part of a rule, a message to an instance can be send, corresponding to messages used in message-handlers. (send [ ] ) Example 4: (defrule titanic-has-to-slow-down (object (name [titanic]) (speed ?speed)) (test (> ?speed 30)) => (send [titanic] put-speed 20))

Objects in Action Part of Rule Use variables instead of instance-names Example 5: Comment: the variable ?name can be bound during pattern matching to an instance, e.g. [titanic], and a message (to put the value 20 into the speed-slot) is sent in the action-part to this instance. (defrule ships-over-30mph-have-to-slow-down (object (name ?name) (speed ?speed)) (test (> ?speed 30)) => (send ?name put-speed 20))

Objects in Action Part of Rule Task: Define a rule which contains instead of a test-condition a field-constraint with predicate expression to constrain the matching instances to those whose speed is over 30. (defrule slow-down-ships-which-go-over-30mph (object (name ?name) (speed ?speed)) (test (> ?speed 30)) => (send ?name put-speed 20))

A defclass is a construct for specifying the properties (slots) of a class of objects. A defclass consists of four elements: 1)a name, 2)a list of superclasses from which the new class inherits slots and message-handlers, 3)a specifier saying whether or not the creation of direct instances of the new class is allowed and 4)a list of slots specific to the new class. All user-defined classes must inherit from at least one class; COOL provides predefined system classes for use as a base in the derivation of new classes. Any slots explicitly given in the defclass override those gotten from inheritance. COOL applies rules to the list of superclasses to generate a class precedence list for the new class. Facets further describe slots. Some examples of facets include: default value, cardinality, and types of access allowed. DEFCLASS Description

(defclass [ ] (is-a +)superclass(es) [ ]can instances be created? [ ]can instances be used in pattern matching? *slots! *)methods associated with this class ::= (message-handler [ ]) ::= primary | around | before | after DEFCLASS - Syntax

::= (role concrete | abstract) ::= (pattern-match reactive | non-reactive) ::= (slot *) | (single-slot *) | (multislot *) ::= | | | | | | | |

::= (default ?DERIVE | ?NONE | ) ::= (pattern-match reactive | non- reactive) ::= (visibility private | public) ::= (create-accessor ?NONE | read | write | read-write) ::= (override-message ?DEFAULT | )

DEFINSTANCES Similar to deffacts, the definstances construct allows the specification of instances which will be created every time the reset command is executed. On every reset all current instances receive a delete message, and the equivalent of a make-instance function call is made for every instance specified in the definstances constructs.

DEFINSTANCES - Syntax (definstances [ ] ( )*) ::= of * ::= ( *)

DEFMESSAGE HANDLER Objects are manipulated by sending them messages via the function send. The result of a message is a useful return-value or side-effect. A defmessage-handler is a construct for specifying the behavior of a class of objects in response to a particular message. The implementation of a message is made up of pieces of procedural code called message-handlers (or handlers for short). Each class in the class precedence list of an object's class can have handlers for a message. In this way, the object's class and all its superclasses share the labor of handling the message. Each class's handlers handle the part of the message which is appropriate to that class.

DEFMESSAGE HANDLER A defmessage-handler is comprised of: a class name to which to attach the handler (the class must have been previously defined), a message name to which the handler will respond, an optional type (the default is primary), an optional comment, a list of parameters that will be passed to the handler during execution, an optional wildcard parameter, and a series of expressions which are executed in order when the handler is called. The return-value of a message-handler is the evaluation of the last expression in the body.

DEFMESSAGE HANDLER (defmessage-handler [ ] [ ] ( * [ ]) *) ::= around | before | primary | after ::=

DEFMESSAGE HANDLER Within a class, the handlers for a particular message can be further subdivided into four types or categories: 1.primary, 2.before, 3.after and 4.around.

(defclass pistol (is-a USER) (role concrete) (pattern-match reactive) (slot safety (type SYMBOL) (create-accessor read-write)) (slot slide (type SYMBOL) (create-accessor read-write)) (slot hammer (type SYMBOL) (create-accessor read-write)) (slot chamber (type INTEGER) (create-accessor read-write)) (slot magazine (type SYMBOL) (create-accessor read-write)) (slot rounds (type INTEGER) (create-accessor read-write)) ) CLIPS Example – Pistol Firing

;; We associate message-handlers with ‘safety’ and ‘drop.’ (defmessage-handler pistol safety (?on-off) (dynamic-put safety ?on-off) (if (eq ?on-off on) then (dynamic-put hammer down)) ) ;; The ‘drop’ message-handler drops the magazine from the mag. (defmessage-handler pistol drop () (dynamic-put magazine out) )

;; We associate message-handlers with ‘safety’ and ‘drop.’ (defmessage-handler pistol safety (?on-off) (dynamic-put safety ?on-off) (if (eq ?on-off on) then (dynamic-put hammer down)) ) ;; The ‘drop’ message-handler drops the magazine from the mag well. (defmessage-handler pistol drop () (dynamic-put magazine out) )