The CLIPS environment. The CLIPS programming language. CLIPS production rules language - facts. Notes



Similar documents
Reference Manual Volume I Basic Programming Guide

CLIPS-OWL: A Framework for Providing Object-Oriented Extensional Ontology Queries in A Production Rule Engine

Artificial Intelligence

Java (12 Weeks) Introduction to Java Programming Language

Glossary of Object Oriented Terms

JessTab: Using Jess together with Protégé. Henrik Eriksson

Artificial Intelligence

CS 111 Classes I 1. Software Organization View to this point:

KITES TECHNOLOGY COURSE MODULE (C, C++, DS)

Concepts and terminology in the Simula Programming Language

PL/SQL Overview. Basic Structure and Syntax of PL/SQL

Chapter 15 Functional Programming Languages

Delphi Developer Certification Exam Study Guide

Automated transformations from ECA rules to Jess

Facebook Twitter YouTube Google Plus Website

5. Advanced Object-Oriented Programming Language-Oriented Programming

PART-A Questions. 2. How does an enumerated statement differ from a typedef statement?

Java Interview Questions and Answers

Exercise 4 Learning Python language fundamentals

CLIPS User s Guide. by Joseph C. Giarratano, Ph.D. Version 6.30

: provid.ir

Visual Basic Programming. An Introduction

BUSINESS RULES CONCEPTS... 2 BUSINESS RULE ENGINE ARCHITECTURE By using the RETE Algorithm Benefits of RETE Algorithm...

Curriculum Map. Discipline: Computer Science Course: C++

Open-Source, Cross-Platform Java Tools Working Together on a Dialogue System

Formal Engineering for Industrial Software Development

Expert Systems : AI Course Lecture 35 36, notes, slides RC Chakraborty, rcchak@gmail.

History OOP languages Year Language 1967 Simula Smalltalk

Software Engineering

CS506 Web Design and Development Solved Online Quiz No. 01

Sources: On the Web: Slides will be available on:

The C Programming Language course syllabus associate level

The Relational Model. Ramakrishnan&Gehrke, Chapter 3 CS4320 1

FUNDAMENTALS OF ARTIFICIAL INTELLIGENCE KNOWLEDGE REPRESENTATION AND NETWORKED SCHEMES

IAI : Knowledge Representation

Schema Classes. Polyhedra Ltd

Many applications consist of one or more classes, each containing one or more methods. If you become part of a development team in industry, you may

A Proposed Decision Support System/Expert System for Guiding. Fresh Students in Selecting a Faculty in Gomal University, Pakistan

Java Application Developer Certificate Program Competencies

Part 1 Foundations of object orientation

Reference Manual Volume III Interfaces Guide

Functional Programming. Functional Programming Languages. Chapter 14. Introduction

Duration Vendor Audience 5 Days Oracle End Users, Developers, Technical Consultants and Support Staff

Fundamentals of Java Programming

Moving from CS 61A Scheme to CS 61B Java

Objective-C and Cocoa User Guide and Reference Manual. Version 5.0

ORACLE 9I / 10G / 11G / PL/SQL COURSE CONTENT

CHAPTER-2 CLIPS PROGRAMMING

Cohort: BCA/07B/PT - BCA/06/PT - BCNS/06/FT - BCNS/05/FT - BIS/06/FT - BIS/05/FT - BSE/05/FT - BSE/04/PT-BSE/06/FT

The Relational Model. Why Study the Relational Model? Relational Database: Definitions. Chapter 3

core. Volume I - Fundamentals Seventh Edition Sun Microsystems Press A Prentice Hall Title ULB Darmstadt

Data Modeling. Database Systems: The Complete Book Ch ,

Multichoice Quetions 1. Atributes a. are listed in the second part of the class box b. its time is preceded by a colon. c. its default value is

Schema Evolution in SQL-99 and Commercial (Object-)Relational DBMS

Python for Rookies. Example Examination Paper

Predicate Logic. For example, consider the following argument:

Compiling Object Oriented Languages. What is an Object-Oriented Programming Language? Implementation: Dynamic Binding

UNIVERSITY OF CALIFORNIA BERKELEY Engineering 7 Department of Civil and Environmental Engineering. Object Oriented Programming and Classes in MATLAB 1

Creating a Custom Class in Xcode

DATA STRUCTURES USING C

Flavors. A non-hierarchical approach to object-oriented programming. Howard I. Cannon

Lecture 6. SQL, Logical DB Design

Certified PHP Developer VS-1054

Polymorphism. Problems with switch statement. Solution - use virtual functions (polymorphism) Polymorphism

Aspect-Oriented Programming

A Comparison of Database Query Languages: SQL, SPARQL, CQL, DMX

Object Oriented Software Design

Appendix... B. The Object Constraint

The Import & Export of Data from a Database

Exercise 1: Python Language Basics

Ch 7-1. Object-Oriented Programming and Classes

2. Basic Relational Data Model

Checking Access to Protected Members in the Java Virtual Machine

COMP 356 Programming Language Structures Notes for Chapter 4 of Concepts of Programming Languages Scanning and Parsing

Programming Database lectures for mathema

Best Practices in Qt Quick/QML. Langston Ball Senior Qt Developer ICS, Inc.

ALLIED PAPER : DISCRETE MATHEMATICS (for B.Sc. Computer Technology & B.Sc. Multimedia and Web Technology)

Computing Concepts with Java Essentials

Flowcharting, pseudocoding, and process design

Artificial Intelligence 2014

Model Driven Security: Foundations, Tools, and Practice

Course Number: IAC-SOFT-WDAD Web Design and Application Development

How To Design Software

This module explains fundamental aspects of Microsoft Dynamics NAV Development Environment.

DIPLOMADO DE JAVA - OCA

SQL Server Database Coding Standards and Guidelines

Course Name: ADVANCE COURSE IN SOFTWARE DEVELOPMENT (Specialization:.Net Technologies)

Welcome to the topic on approval procedures in SAP Business One.

The Designer's Guide to VHDL

Database Query 1: SQL Basics

Anatomy of Programming Languages. William R. Cook

Integrating Formal Models into the Programming Languages Course

Outline. Data Modeling. Conceptual Design. ER Model Basics: Entities. ER Model Basics: Relationships. Ternary Relationships. Yanlei Diao UMass Amherst

Oracle Database: SQL and PL/SQL Fundamentals

Organization of Programming Languages CS320/520N. Lecture 05. Razvan C. Bunescu School of Electrical Engineering and Computer Science

7.1 Our Current Model

Functional Programming

MS Access: Advanced Tables and Queries. Lesson Notes Author: Pamela Schmidt

Transcription:

The CLIPS environment The CLIPS environment CLIPS is an environment to develop knowledge based systems It defines a programming language that allows to represent declarative and procedural knowledge This language has a syntax to define production rules and frames The execution environment is an inference engine that uses forward chaining This inference engine is implemented over an interpreter of the CLIPS language Javier Béjar (LSI - FIB - UPC) The CLIPS language AI - 2009/2010 Fall Term 1 / 29 The CLIPS environment The CLIPS programming language The CLIPS programming language derives its syntax from the LISP programming language It is a parenthesized language that uses prefix notation The predefined data types are: real, integer, string, symbol, pointer to fact, instance name and pointer to instance The usual data types have the usual operators CLIPS programming language joins three programming paradigms: rule programming, functional programming and object oriented programming Javier Béjar (LSI - FIB - UPC) The CLIPS language AI - 2009/2010 Fall Term 2 / 29 CLIPS production rules language - facts The two elements that allow to represent problems using production rules are facts and rules In CLIPS facts can be of two kinds: ordered facts and deftemplate facts Ordered Facts have a free syntax, therefore they have not a fixed structure, they follow the pattern: (relation p1 p2... pn) relation has to be a symbol, the rest of parameters can be of any kind, for examples (father john peter) (num-children john 2) Javier Béjar (LSI - FIB - UPC) The CLIPS language AI - 2009/2010 Fall Term 3 / 29

CLIPS production rules language - deftemplates The structure of deftemplate facts has to be declared, they could be assimilated to a frame-like representation The definition of this facts is done using (slots) that define their characteristics. Each slot can have constraints such as data type, cardinality or a default value that can be a constant o a function that can compute it (deftemplate template-name "comment" (slot slot-name) (multislot slot-name)) For example: (deftemplate person (slot name (type STRING)) (slot age (type INTEGER) (default 0))) Javier Béjar (LSI - FIB - UPC) The CLIPS language AI - 2009/2010 Fall Term 4 / 29 CLIPS production rules language - creating facts The creation of new facts is performed by using the construction assert (just one) or deffacts (a set), for example: (assert (father joseph john)) (assert (person (name "peter") (age 25))) (deffacts my-facts (house red) (ball green) (person (name "louis") (age 33))) Javier Béjar (LSI - FIB - UPC) The CLIPS language AI - 2009/2010 Fall Term 5 / 29 CLIPS production rules language - facts CLIPS has other constructors that allow to manipulate and query the fact base (facts) allows to know what facts has been created (clear) deletes all existing facts (retract <fact-index>) deletes the fact identified by the given index (get-deftemplate-list) returns the list of defined deftemplates Javier Béjar (LSI - FIB - UPC) The CLIPS language AI - 2009/2010 Fall Term 6 / 29

CLIPS production rules language - rules CLIPS rules are defined by: A left hand side (LHS) that defines the conditions to hold A right hand side (RHS) that defines the actions to execute Syntax: (defrule rule-name "comment" (condition-1) (condition-2)... => (action-1) (action-2)...) Javier Béjar (LSI - FIB - UPC) The CLIPS language AI - 2009/2010 Fall Term 7 / 29 CLIPS production rules language - variables To build patterns in the conditions of the rules we need variables In CLIPS variables are denoted by a question mark before their name (?variable) if the variable is for just one value, or by a dollar sign and a question mark if the variable is for a list of values $?variable There are anonymous variables or wild-cards (their value is immaterial) for just one value? of for a list of values?$ In execution time the inference engine instantiates adequately the variables so the conditions of the rules hold Rule variables are local to the rule, global variables can be defined using constructor defglobal (global variables are denoted as?*variable*) Javier Béjar (LSI - FIB - UPC) The CLIPS language AI - 2009/2010 Fall Term 8 / 29 CLIPS production rules language - LHS In the left hand side of a rule can appear different kinds of conditions Constants, Patterns with variables or wild-cards: they can be instantiated with facts from the knowledge base Expressions using logic connectives as not, and, or, exist and forall with patterns Test for expressions using the variables instantiated by the patterns (test) Patterns can also constraint what facts can instantiate the rules by using conditions over the variables or using constant values Simple constraints can be stated by using logic connectives ~ (not), & (and) and (or) More complex constraints can be also defined by using the operator : Javier Béjar (LSI - FIB - UPC) The CLIPS language AI - 2009/2010 Fall Term 9 / 29

CLIPS production rules language - examples Person over 18: (person (age?x&:(>?x 18))) Person named john or peter: (person (name john peter)) Two persons with different name: (person (name?x)) (person (name?y&~?x)) Nobody has the name peter: (not (person (name peter))) Everybody is over 18: (forall (person (name?n) (age?x)) (test (>?x 18))) Javier Béjar (LSI - FIB - UPC) The CLIPS language AI - 2009/2010 Fall Term 10 / 29 CLIPS production rules language The address of a fact that matches a pattern can be obtained using the operator <-, for example: (defrule my-rulea?x <- (person (name john)) => (retract?x) ) In the right hand side of a rule we can use any valid CLIPS construction Javier Béjar (LSI - FIB - UPC) The CLIPS language AI - 2009/2010 Fall Term 11 / 29 CLIPS production rules language - modules CLIPS rules can be organized in modules The main advantage is to be able to structure the knowledge and to focus the rules execution depending on their goal The definition of a module uses the constructor: (defmodule <name> "comment" <export-import>) Constructors defined in a module have to be exported to be visible Constructions from other module only can be used if they are imported There is a default module named MAIN that has all that is not defined in other module Javier Béjar (LSI - FIB - UPC) The CLIPS language AI - 2009/2010 Fall Term 12 / 29

CLIPS production rules language - modules We can assign a construction to a module by using as a prefix the name of the module followed by two colons ::, for example: (deftemplate A::cube (slot size)) Export of constructions from a module is done by including the sentence export in its definition. Anything that is defined can be exported, for example: (defmodule A (export deftemplate cube)) (defmodule A (export deftemplate?all)) Import of constructions from other modules is done by including the sentence import in its definition. Anything that is visible from other modules can be imported, for example: (defmodule B (import A deftemplate cube)) Javier Béjar (LSI - FIB - UPC) The CLIPS language AI - 2009/2010 Fall Term 13 / 29 CLIPS production rules language - focus We can restrict the modules that are used to execute rules using the sentence (focus <module>*) This sentence can be used in the right hand side of a rule to explicitly change the module It also is allows to focus on the module of the last executed rule declaring the rule property auto-focus, for example: (defrule JOHN::my-rule (declare (auto-focus TRUE)) (person (name john)) =>... Javier Béjar (LSI - FIB - UPC) The CLIPS language AI - 2009/2010 Fall Term 14 / 29 Conflict Resolution Strategies The inference engine has defined some conflict resolution strategies Depth-first, newest rules have priority Breadth-first, oldest rules have priority Simplicity, the less specific rule is preferred (specificity is measured respect the complexity of the conditions of the rules) Complexity, the more specific rules have priority Javier Béjar (LSI - FIB - UPC) The CLIPS language AI - 2009/2010 Fall Term 15 / 29

Conflict Resolution Strategies LEX strategy, priority to the rules instantiated with the newest facts, ordering the facts that instantiate the rule by recency and following a lexicographic order MEA strategy, rules are ordered by the recency of the fact that instantiates the first condition, ties are break using LEX strategy Random, rules are fired in random order Javier Béjar (LSI - FIB - UPC) The CLIPS language AI - 2009/2010 Fall Term 16 / 29 CLIPS programming language CLIPS includes a pseudo-functional programming language It can be used to define new functions or to implement the actions to be performed on the right hand side of the rules Each sentence or control structure is a function that receives parameters and returns a result (functional paradigm) Javier Béjar (LSI - FIB - UPC) The CLIPS language AI - 2009/2010 Fall Term 17 / 29 CLIPS programming language - syntax These are the more commonly used sentences and control structures: (bind <var> <value>): assigns a value to a variable, returns the value assigned (if <exp> then <action>* [else <action>*]): alternative control structure, returns the value of the last evaluated expression (while <exp> do <action>*): conditional iteration control structure, returns false, except if a return sentence breaks the iteration (loop-for-count (<var> <val-i> <val-f>) do <action>*): Iteration over a range of values, returns false, except is there is a return sentence Javier Béjar (LSI - FIB - UPC) The CLIPS language AI - 2009/2010 Fall Term 18 / 29

CLIPS programming language - syntax (progn <action>*): Executes a set of actions sequentially, returns the value of the last one (return <expr>): Breaks the execution of the current control block and returns the value of the expression (break): Breaks the execution of the current control block (switch <expr> (case (<comp>) then <action>*)* [(default <action>*)]): Case structure each case compares with the value of the expression. Returns the last evaluated expression or false if no case clause holds Javier Béjar (LSI - FIB - UPC) The CLIPS language AI - 2009/2010 Fall Term 19 / 29 CLIPS programming language - defining functions The constructor deffunction allows to define new functions (deffunction <name> "Comment" (<?parameter>* [<$?wilcard-parameter>]) <action>*) The list of parameters can be variable in size, the wild-card parameter puts in a list the remaining parameters The function returns the last evaluated expression Javier Béjar (LSI - FIB - UPC) The CLIPS language AI - 2009/2010 Fall Term 20 / 29 CLIPS Object Oriented language CLIPS defines also an object oriented language that complements its ability to represent knowledge It could be considered an extension of the constructor deftemplate that allows to use frames as a representation language As in Object Oriented languages/frame languages we can define slots and methods CLIPS defines an initial set of classes that organize the CLIPS predefined data types in a hierarchy Javier Béjar (LSI - FIB - UPC) The CLIPS language AI - 2009/2010 Fall Term 21 / 29

CLIPS Object Oriented language The constructor defclass allows to define a class In order to define a class has to be specified: 1 The name of the class 2 A lists of its superclasses (it will inherit their slots and methods) 3 If the class is abstract or not (if it is not abstract we can define instances of the class) 4 If it is allowed to use the instances of the class as patterns of the LHS of a rule 5 Definition of the slots of the class (slot, multi-slot) All classes must have at least a superclass Javier Béjar (LSI - FIB - UPC) The CLIPS language AI - 2009/2010 Fall Term 22 / 29 CLIPS Object Oriented language For example: (defclass living-being (is-a USER) (role abstract) (pattern-match non-reactive) (slot breathes (default si))) (defclass person (is-a living-being) (role concrete) (pattern-match reactive) (slot name)) Javier Béjar (LSI - FIB - UPC) The CLIPS language AI - 2009/2010 Fall Term 23 / 29 CLIPS Object Oriented language - slots The definition of a slot includes a set of properties, such as: (default?derive?none <exp>*) (default-dynamic <expr>*) (access read-write read-only initialize-only) (propagation inherit no-inherit) (visibility public private) (create-accessor?none read write read-write) We can also declare the data type, cardinality,... Javier Béjar (LSI - FIB - UPC) The CLIPS language AI - 2009/2010 Fall Term 24 / 29

CLIPS Object Oriented language - instances To create an instance of a class the constructor make-instance is used When we create an instance we must give the values of their slots, for example: (make-instance john of person (name "john")) We can create sets of instances with the constructor definstances, for examples: (definstances persons (john of person (name "john")) (mary of person (name "mary")) ) Javier Béjar (LSI - FIB - UPC) The CLIPS language AI - 2009/2010 Fall Term 25 / 29 CLIPS Object Oriented language - messages All the interaction with objects is perform using messages These messages has handlers that process the messages and perform the indicated task These handlers are defined using the constructor defmessage-handler, their syntax is identical to the syntax of the functions (defmessage-handler <class> name <hand-type> (<param>*) <expr>*) There are different kinds of handlers primary, before, after, around, we will only use primary handlers Javier Béjar (LSI - FIB - UPC) The CLIPS language AI - 2009/2010 Fall Term 26 / 29 CLIPS Object Oriented language- messages By default each class has defined a set of handlers, for example: init, delete, print Defining create-accessor in a slot we are creating two messages, get-name slot, put-name slot to access and modify the slot The access to a slot inside the code of a handler is done using the variable?self, and putting : before the name of the slot, for example: (defmessage-handler person print-name () (printout t "Name:"?self:name crlf)) Javier Béjar (LSI - FIB - UPC) The CLIPS language AI - 2009/2010 Fall Term 27 / 29

CLIPS Object Oriented language - messages To send a message to an instance is done using the sentence send, the name of the instance has to be between square brackets, for example: (send [john] print-name) (send [john] set-name "peter") Handlers can be defined in each class, hence each subclass can run the handlers of their superclasses. For the handlers of type primary it is used the handler of the most specific class, to execute the handlers of the superclasses the sentence call-next-handler as to be used It must be at least a primary handler for each message Javier Béjar (LSI - FIB - UPC) The CLIPS language AI - 2009/2010 Fall Term 28 / 29 CLIPS Object Oriented language - instances and rules In order to use instances on the LHS of a rule the sentence object has to be used, for example: (defrule rule-person (object (is-a person) (name =>... )?x)) The class must be declared as pattern-match reactive Modifying a slot allows an instance to be instantiated again by same rule if its conditions hold Javier Béjar (LSI - FIB - UPC) The CLIPS language AI - 2009/2010 Fall Term 29 / 29