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.

Slides:



Advertisements
Similar presentations
Semantics Static semantics Dynamic semantics attribute grammars
Advertisements

ICE1341 Programming Languages Spring 2005 Lecture #6 Lecture #6 In-Young Ko iko.AT. icu.ac.kr iko.AT. icu.ac.kr Information and Communications University.
Stacks & Their Applications COP Stacks  A stack is a data structure that stores information arranged like a stack.  We have seen stacks before.
Overloading Operators Object-Oriented Programming Using C++ Second Edition 8.
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.
Introduction to CLIPS (Lecture Note #17)
Chapter 7: Introduction to CLIPS
Artificial Intelligence Lecture No. 18 Dr. Asad Ali Safi ​ Assistant Professor, Department of Computer Science, COMSATS Institute of Information Technology.
Copyright © 2006 Addison-Wesley. All rights reserved.1-1 ICS 410: Programming Languages Chapter 3 : Describing Syntax and Semantics Axiomatic Semantics.
Copyright © 2006 Addison-Wesley. All rights reserved. 3.5 Dynamic Semantics Meanings of expressions, statements, and program units Static semantics – type.
For Friday Read “lectures” 1-5 of Learn Prolog Now: prolog-now/
CSE 115 Week 11 March , Announcements March 26 – Exam 7 March 26 – Exam 7 March 28 – Resign Deadline March 28 – Resign Deadline Lab 7 turned.
Chapter 4B: More Advanced PL/SQL Programming
Introduction to CLIPS (Chapter 7) Fact List (contains data) Knowledge Base (contains rules) Inference Engine (controls execution)
Week 10 Recap CSE 115 Spring For-each loop When we have a collection and want to do something to all elements of that collection we use the for-each.
© C. Kemke Control 1 COMP 4200: Expert Systems Dr. Christel Kemke Department of Computer Science University of Manitoba.
Environments and Evaluation
Chapter 8: Advanced Pattern Matching Expert Systems: Principles and Programming, Fourth Edition.
Dr. Muhammed Al-Mulhem 1ICS ICS 535 Design and Implementation of Programming Languages Part 1 Fundamentals (Chapter 4) Axiomatic Semantics ICS 535.
Introduction to Jess.
CS 561, Session 25 1 Introduction to CLIPS Overview of CLIPS Facts Rules Rule firing Control techniques Example.
Basic Elements of C++ Chapter 2.
Bash Shell Scripting 10 Second Guide Common environment variables PATH - Sets the search path for any executable command. Similar to the PATH variable.
Objectives You should be able to describe: Data Types
1 01/12/2011Knowledge-Based Systems, Paula Matuszek More Intro to CLIPS Paula Matuszek CSC 9010, Spring, 2011.
Review Topics Test 1. Background Topics Definitions of Artificial Intelligence & Turing Test Physical symbol system hypothesis vs connectionist approaches.
1 Overloading Operators Object-Oriented Programming Using C++ Second Edition 8.
Ryan Chu. Arithmetic Expressions Arithmetic expressions consist of operators, operands, parentheses, and function calls. The purpose is to specify an.
Chapter 61 More about Loop Do ….. Loop Write Down “Do” and “Loop”
Chapter 7: Introduction to CLIPS Expert Systems: Principles and Programming, Fourth Edition.
Flow of Control. 2 Control Structures Control structure: An instruction that determines the order in which other instructions in a program are executed.
Basic Lisp CIS 479/579 Bruce R. Maxim UM-Dearborn.
Chapter 3: Data Types and Operators JavaScript - Introductory.
Chapter 10: Procedural Programming Expert Systems: Principles and Programming, Fourth Edition.
EXPRESSIONS AND ASSIGNMENT CITS1001. Scope of this lecture Assignment statements Expressions 2.
Interpretation Environments and Evaluation. CS 354 Spring Translation Stages Lexical analysis (scanning) Parsing –Recognizing –Building parse tree.
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.
CompSci 100E 2.1 Java Basics - Expressions  Literals  A literal is a constant value also called a self-defining term  Possibilities: o Object: null,
Operators Precedence - Operators with the highest precedence will be executed first. Page 54 of the book and Appendix B list C's operator precedence. Parenthesis.
MT311 Java Application Development and Programming Languages Li Tak Sing( 李德成 )
Figure 2.1a Evaluating Expressions To evaluate an algebraic expression, we may substitute the value(s) in place of the variable(s) and evaluate the numeric.
Chapter 3 Part II Describing Syntax and Semantics.
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.
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.
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.
Control statements Mostafa Abdallah
1 Assertions. 2 A boolean expression or predicate that evaluates to true or false in every state In a program they express constraints on the state that.
Mostly adopted from Jason Morris notes (Morris Technical Solutions)
Chapter 4: Variables, Constants, and Arithmetic Operators Introduction to Programming with C++ Fourth Edition.
Expressions Version Topics Arithmetic expressions Conversions Operator precedence String class 2.
An Introduction to Programming with C++ Sixth Edition Chapter 5 The Selection Structure.
The CLIPS Expert System Shell Dr Nicholas Gibbins
Introduction to CLIPS 2 Session 13 Course: T0273 – EXPERT SYSTEMS Year: 2014.
Chapter Topics The Basics of a C++ Program Data Types
Intelligent Systems JESS constructs.
Basic Elements of C++.
The Selection Structure
Chapter 7: Introduction to CLIPS
Basic Elements of C++ Chapter 2.
Chapter 8: Advanced Pattern Matching
بسم الله الرحمن الرحیم آموزش نرم افزار CLIPS
Expressions.
Computer Based Tutoring
Presentation transcript:

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 a rule (defrule person-without-brown-hair (person (name ?name) (hair ~brown)) => (printout t ?name “ does not have brown hair”)) Not field constraint

Other field contraints And field constraint  & And field constraint  & Or field constraint  | Or field constraint  | (defrule black-or-brown-hair (person (name ?name) (hair ?color&~brown&~black)) => (printout t ?name “ has ” ?color “ hair ” crlf))

Functions & Expressions Numeric Expression Numeric Expression –Prefix notation –Basic operations : +,-,*,/ (y2-y1) / (x2-x1) >0\ Will be : (> (/ (- y2 y1) (- x2 x1)) 0)

Functions & Expressions Clips supports variable numbers of arguments Clips supports variable numbers of arguments There is no built-in precedence of arithmetic operations There is no built-in precedence of arithmetic operations Everything is simply evaluated from left to right, parentheses determining precedence Everything is simply evaluated from left to right, parentheses determining precedence

Functions & Expressions Be careful! Be careful! (assert (answer (+ 2 2))) (assert (expression 2+3*4)) (answer 4) (expression 2+3*4) Facts inserted by clips

Summing values using rules This will loop endlessly This will loop endlessly –Retracting the sum rule and reasserting it will produce a loop with a single rule –Use a temporary fact!! (defrule sum-rectangles (rectangle (height ?height)(width ?width)) ?sum<- (sum ?total) => (retract ?sum) (assert (sum(+ ?total (* ?height ?width)))))

Summing values using rules (defrule sum-rectangles (rectangle (height ?height) (width ?width)) => (assert (add-to-sum (* ?height ?width)))) (defrule sum-areas ?sum <- (sum ?total) ?new-area <- (add-to-sum ?area) => (retract ?sum ?new-area) (assert (sum (+ ?total ?area))))

Variable Binding Used to store a value in a variable to prevent recalculation Used to store a value in a variable to prevent recalculation –Syntax: (bind ) –(bind ?new-total (+ ?total ?area))

How to read input? (defrule get-first-name => (printout t “what’s your name?”) (bind ?response (read) (assert (user-name ?response) ))) Sina jafarpour “sina jafarpour”

Predicate Functions Any function that return the symbol TRUE or FALSE Any function that return the symbol TRUE or FALSE Any value other than FALSE is treated as TRUE Any value other than FALSE is treated as TRUE Check appendix E in Book! Check appendix E in Book! –(and (> 4 3) (> 4 5)) –(integerp 3.5)

The Test conditional element A way to evaluate expressions on the LHS of a rule A way to evaluate expressions on the LHS of a rule Instead of pattern matching, test will evaluate an expression Instead of pattern matching, test will evaluate an expression –(test (> ?size 1))

Conditional Elements Thus far all rules had an implicit and conditional elements between patterns Thus far all rules had an implicit and conditional elements between patterns (defrule shutt-off-electricity-1 (emergency (type flood)) => (printout t “shut off electricity” clrf)) (defrule shutt-off-electricity-2 (emergency (type water-sprinkler)) => (printout t “shut off electricity” clrf)) (defrule shut-off-electricity (electrical-power (status on)) (Or (emergency (type flood)) (extinguisher-system (type water-sprinkler) (status on))) => (printout t “shut off electricity”))

Exists and forall conditional Elements (defrule all-fires-being-handled (forall (emergency (type fire) (location ?where)) (fire-squad (location ?where)) (evacuated (building ?where)))) => (printout t “all buildings that are on fire” clrf “have been evacuated and ” clrf “have firefighters on location” clrf)

Logical conditional element Allows you to specify that the existence of a fact depends on the existence of another fact or group of facts Allows you to specify that the existence of a fact depends on the existence of another fact or group of facts (defrule noxious-fumes-present (emergency (type fire)) (noxious-fumes-present) => (assert (use-oxygen-masks)))

Logical conditional element After deleting the two preconditions, use-oxygen-masks will remain a fact After deleting the two preconditions, use-oxygen-masks will remain a fact (defrule noxious-fumes-present (logical (noxious-fumes-present)) (emergency (type fire)) => (assert (use-oxygen-masks))) When the noxious-fumes-present rule is executed A link is created between the facts matching the pattern Contained within the logical CE in the LHS of a rule And the facts asserted in the RHS of the rule. So, if either the emergency fact or the noxious-fumes fact Is retracted,then use-oxygen-masks fact will be also retracted