Artificial Intelligence Lecture No. 24 Dr. Asad Ali Safi ​ Assistant Professor, Department of Computer Science, COMSATS Institute of Information Technology.

Slides:



Advertisements
Similar presentations
Artificial Intelligence Lecture No. 18 Dr. Asad Ali Safi ​ Assistant Professor, Department of Computer Science, COMSATS Institute of Information Technology.
Advertisements

Primitive Data Types There are a number of common objects we encounter and are treated specially by almost any programming language These are called basic.
Data Types in Java Data is the information that a program has to work with. Data is of different types. The type of a piece of data tells Java what can.
 2008 Pearson Education, Inc. All rights reserved JavaScript: Introduction to Scripting.
Chapter 8: Advanced Pattern Matching Expert Systems: Principles and Programming, Fourth Edition.
ECE122 L3: Expression Evaluation February 6, 2007 ECE 122 Engineering Problem Solving with Java Lecture 3 Expression Evaluation and Program Interaction.
JavaScript, Third Edition
 2008 Pearson Education, Inc. All rights reserved JavaScript: Control Statements II.
While Loops and Do Loops. Suppose you wanted to repeat the same code over and over again? System.out.println(“text”); System.out.println(“text”); System.out.println(“text”);
Chapter Seven Advanced Shell Programming. 2 Lesson A Developing a Fully Featured Program.
Computer Science 1000 Spreadsheets II Permission to redistribute these slides is strictly prohibited without permission.
Artificial Intelligence Lecture No. 15 Dr. Asad Ali Safi ​ Assistant Professor, Department of Computer Science, COMSATS Institute of Information Technology.
CSci 125 Lecture 10 Martin van Bommel. Simple Statements Expression followed by semicolon Assignments total = n1 + n2; Function calls printf(”Hello.\n”);
Java Primitives The Smallest Building Blocks of the Language (corresponds with Chapter 2)
Introduction to Python
Copyright © 2012 Pearson Education, Inc. Publishing as Pearson Addison-Wesley C H A P T E R 9 More About Strings.
CNG 140 C Programming (Lecture set 9) Spring Chapter 9 Character Strings.
Artificial Intelligence Lecture No. 17 Dr. Asad Ali Safi ​ Assistant Professor, Department of Computer Science, COMSATS Institute of Information Technology.
Haskell. 2 GHC and HUGS Haskell 98 is the current version of Haskell GHC (Glasgow Haskell Compiler, version 7.4.1) is the version of Haskell I am using.
Internet & World Wide Web How to Program, 5/e © by Pearson Education, Inc. All Rights Reserved.
Artificial Intelligence Lecture No. 29 Dr. Asad Ali Safi ​ Assistant Professor, Department of Computer Science, COMSATS Institute of Information Technology.
EXPRESSIONS AND ASSIGNMENT CITS1001. Scope of this lecture Assignment statements Expressions 2.
Introduction to Java Applications Part II. In this chapter you will learn:  Different data types( Primitive data types).  How to declare variables?
Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display. A Concise Introduction to MATLAB ® William J. Palm III.
Summary of what we learned yesterday Basics of C++ Format of a program Syntax of literals, keywords, symbols, variables Simple data types and arithmetic.
Integer numerical data types. The integer data types The integer data types use the binary number system as encoding method There are a number of different.
IMSS013 CLIPS. 2 Background CLIPS is an expert system tool developed by the Software Technology Branch (STB), NASA/Lyndon B. Johnson Space Center. First.
CPS120: Introduction to Computer Science Operations Lecture 9.
CMP 131 Introduction to Computer Programming Violetta Cavalli-Sforza Week 5, Lecture 1 (Monday)
Variables, Expressions and Statements
LISP Data Types Functional Programming Academic Year Alessandro Cimatti
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.
Control in LISP More on Predicates & Conditionals.
School of Computer Science & Information Technology G6DICP - Lecture 4 Variables, data types & decision making.
 2008 Pearson Education, Inc. All rights reserved JavaScript: Introduction to Scripting.
Introduction to Python Dr. José M. Reyes Álamo. 2 Three Rules of Programming Rule 1: Think before you program Rule 2: A program is a human-readable set.
Artificial Intelligence Lecture No. 19 Dr. Asad Ali Safi ​ Assistant Professor, Department of Computer Science, COMSATS Institute of Information Technology.
Copyright © 2008 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Fluency with Information Technology Third Edition by Lawrence Snyder Chapter.
Artificial Intelligence Lecture No. 23 Dr. Asad Ali Safi ​ Assistant Professor, Department of Computer Science, COMSATS Institute of Information Technology.
CSM-Java Programming-I Spring,2005 Fundamental Data Types Lesson - 2.
Introduction to Java Applications Part II. In this chapter you will learn:  Different data types( Primitive data types).  How to declare variables?
1 CSC 221: Computer Programming I Fall 2005 simple conditionals and expressions  if statements, if-else  increment/decrement, arithmetic assignments.
Artificial Intelligence Lecture No. 22 Dr. Asad Ali Safi ​ Assistant Professor, Department of Computer Science, COMSATS Institute of Information Technology.
Python Basics  Values, Types, Variables, Expressions  Assignments  I/O  Control Structures.
Chapter 4: Variables, Constants, and Arithmetic Operators Introduction to Programming with C++ Fourth Edition.
Chapter 2: Data and Expressions. Variable Declaration In Java when you declare a variable, you must also declare the type of information it will hold.
An Introduction to Programming with C++ Sixth Edition Chapter 5 The Selection Structure.
The CLIPS Expert System Shell Dr Nicholas Gibbins
Internet & World Wide Web How to Program, 5/e © by Pearson Education, Inc. All Rights Reserved.
Random Functions Selection Structure Comparison Operators Logical Operator
Fundamentals of Programming I Overview of Programming
Chapter 4 C Program Control Part I
Multiple variables can be created in one declaration
The Selection Structure
Haskell.
JavaScript: Control Statements.
Operators and Expressions
Conditions and Ifs BIS1523 – Lecture 8.
Chapter 8: Advanced Pattern Matching
Chapter 8 JavaScript: Control Statements, Part 2
بسم الله الرحمن الرحیم آموزش نرم افزار CLIPS
Web DB Programming: PHP
Microsoft Visual Basic 2005: Reloaded Second Edition
Algorithms computer as the tool process – algorithm
Chapter 3: Selection Structures: Making Decisions
Summary of what we learned yesterday
Chapter 3: Selection Structures: Making Decisions
ENERGY 211 / CME 211 Lecture 5 October 1, 2008.
PROGRAMMING IN HASKELL
Presentation transcript:

Artificial Intelligence Lecture No. 24 Dr. Asad Ali Safi ​ Assistant Professor, Department of Computer Science, COMSATS Institute of Information Technology (CIIT) Islamabad, Pakistan.

Summary of Previous Lecture Functional ~ | & Basic arithmetic Read

Today’s Lecture readline function (assert-string) Functions

(read) function The (read) function is not a general-purpose function that will read anything you type on the keyboard. One limitation is that (read) will read only one field. So if you try to read – primary color is red only the first field, "primary", will be read. To (read) all the input, you must enclose the input within double quotes. Of course, once the input is within double quotes, it is a single literal field. You can then access the substrings "primary", "color", "is", and "red“ with the str-explode or sub-string functions.

(read) function The second limitation of (read) is that you can't input parentheses unless they are within double quotes. Just as you can't assert a fact containing parentheses, you can't (read) parentheses directly except as literals.

readline function The readline function is used to read multiple values until terminated by a carriage return. This function reads in data as a string. In order to assert the (readline) data, an (assert-string) function is used to assert the nonstring fact, just as input by (readline).

CLIPS> (clear) CLIPS> (assert-string "(primary color is red)") Notice that the argument of (assert-string) must be a string The following shows how to assert a fact of multiple fields from (readline).

CLIPS> (clear) CLIPS> (defrule test-readline => (printout t "Enter input" crlf) (bind ?string (readline)) (assert-string (str-cat "(" ?string ")"))) CLIPS> (reset) CLIPS> (run)

(assert-string) Since (assert-string) requires parentheses around the string to be asserted, the (str-cat) function is used to put them around ?string. Both (read) and (readline) also can be used to read information from a file by specifying the logical name of the file as the argument. For more information, see the CLIPS Reference Manual.

Test conditional element The test conditional element provides a very powerful way by which to compare numbers, variables, and strings on the LHS. The (test) is used as a pattern on the LHS. A rule will only be triggered if the (test) is satisfied together with other patterns. Many predefined functions are provided by CLIPS as shown in the following table.

All the comparison functions except "eq" and "neq" will give an error message if they are used to compare a number and non-number. If the type is not known in advance, the "eq" and "neq" functions should be used. The eq function checks for the same magnitude and type of its arguments while the "=" function only checks the magnitude of its (numeric) arguments and doesn't care if they're integer or floating-point.

logical values The logical functions of CLIPS are and, or, and not. They can be used in expressions as Boolean functions. In CLIPS, true and false are represented by the symbols TRUE and FALSE. Note that upper-case must be used for logical values in CLIPS.

Functions The eq function returns the symbol TRUE if its first argument is equal in value to all its subsequent arguments, otherwise it returns the symbol FALSE. Note that eq compares types as well as values. Thus, (eq 3 3.0) is FALSE since 3 is an integer and 3.0 is a float. The neq function returns the symbol TRUE if its first argument is not equal in value to all its subsequent arguments, otherwise it returns the symbol FALSE. Note that neq compares types as well as values. Thus, (neq 3 3.0) is TRUE since 3 is an integer and 3.0 is a float.

Functions.. The = function returns the symbol TRUE if its first argument is equal in value to all its subsequent arguments, otherwise it returns the symbol FALSE. Note that = compares only numeric values and will convert integers to floats when necessary for comparison. The <> function returns the symbol TRUE if its first argument is not equal in value to all its subsequent arguments, otherwise it returns the symbol FALSE. Note that <> compares only numeric values and will convert integers to floats when necessary for comparison.

Functions …. The >= function returns the symbol TRUE if for all its arguments, argument n ‑ 1 is greater than or equal to argument n, otherwise it returns the symbol FALSE. Note that >= compares only numeric values and will convert integers to floats when necessary for comparison. The < function returns the symbol TRUE if for all its arguments, argument n ‑ 1 is less than argument n, otherwise it returns the symbol FALSE. Note that < compares only numeric values and will convert integers to floats when necessary for comparison. The <= function returns the symbol TRUE if for all its arguments, argument n ‑ 1 is less than or equal to argument n, otherwise it returns the symbol FALSE. Note that <= compares only numeric values and will convert integers to floats when necessary for comparison.

Functions The numberp function returns the symbol TRUE if its argument is a float or integer, otherwise it returns the symbol FALSE. The floatp function returns the symbol TRUE if its argument is a float, otherwise it returns the symbol FALSE. The integerp function returns the symbol TRUE if its argument is an integer, otherwise it returns the symbol FALSE. The stringp function returns the symbol TRUE if its argument is a string, otherwise it returns the symbol FALSE.

Functions.. The evenp function returns the symbol TRUE if its argument is an even number, otherwise it returns the symbol FALSE. The oddp function returns the symbol TRUE if its argument is an odd number, otherwise it returns the symbol FALSE.

Functions…… The and function returns the symbol TRUE if each of its arguments evaluates to TRUE, otherwise it returns the symbol FALSE. Each argument of the function is evaluated from left to right. If any argument evaluates to FALSE, then the symbol FALSE is immediately returned by the function. he or function returns the symbol TRUE if any of its arguments evaluates to TRUE, otherwise it returns the symbol FALSE. Each argument of the function is evaluated from left to right. If any argument evaluates to TRUE, then the symbol TRUE is immediately returned by the function. The not function returns the symbol TRUE if its argument evaluates to FALSE, otherwise it returns the symbol FALSE.

CLIPS> (= 3 3.0) TRUE CLIPS> (= 4 4.1) FALSE CLIPS> CLIPS> (neq foo bar yak bar) TRUE CLIPS> (neq foo foo yak bar) FALSE CLIPS> (neq 3 a) TRUE CLIPS> CLIPS> (eq foo bar mumble foo) FALSE CLIPS> (eq foo foo foo foo) TRUE CLIPS> (eq 3 4) FALSE CLIPS>

Summery of Today’s Lecture readline function (assert-string) Functions