Presentation is loading. Please wait.

Presentation is loading. Please wait.

Samad Paydar Ferdowsi University of Mashhad.  C Language Integrated Production System (CLIPS)  A tool for building expert systems  An expert system.

Similar presentations

Presentation on theme: "Samad Paydar Ferdowsi University of Mashhad.  C Language Integrated Production System (CLIPS)  A tool for building expert systems  An expert system."— Presentation transcript:

1 Samad Paydar Ferdowsi University of Mashhad

2  C Language Integrated Production System (CLIPS)  A tool for building expert systems  An expert system is a program which is specifically intended to model human expertise or knowledge  Created in 1985 at NASA’s Johnson Space Center 2

3  Written in C for portability and speed  Has been installed on many different operating systems  Widely used in industry, academia and government 3

4  Can be integrated with languages such as C, Java, Visual Basic  Different extensions are available:  FuzzyCLIPS: an extension of CLIPS incorporating fuzzy logic  PHLIPS is a PHP extension that provides a basic interface to the CLIPS environment  CLIPSNet, a.Net wrapper for CLIPS 4

5  Three ways to represent knowledge in CLIPS  Rules ▪ For heuristic knowledge base on experience  Deffunctions and generic functions ▪ For procedural knowledge  Object Oriented Programming ▪ For better (i.e. Modular) representation 5

6  CLIPS supports developing expert systems by providing some facilities  An integrated editor  Debugging tool  Shell ▪ Portion of CLIPS which performs inferences or reasoning 6

7  The CLIPS shell provides the basic elements of an expert system:  Fact-list, and instance-list: Global memory for data  Knowledge-base: Contains all the rules, the rule- base  Inference engine: Controls overall execution of rules 7

8  CLIPS has a LISP-like syntax  Extensive use of parentheses ▪ E.g. as delimiters  It is case-sensitive 8

9  assert command for adding facts to the fact- list  (assert (argument) )  Some example ▪ (assert(is-a-country “Iran” )) ▪ (assert (is-a-city “Tehran”)) ▪ (assert (has-population “Tehran” 14000000)) 9

10  facts command for listing current facts  (facts)  Each fact has an identifier of the form ▪ f-{fact-index}  Duplicate facts are not allowed by default ▪ set-fact-duplication allows duplicate fact entry. 10

11  Removing facts from the fact-list is called retraction and is done with the retract command.  To retract a fact, you must specify the fact index as the argument of retract  (retract (facts indices) 11

12  Example ▪ (retract 2)  It is possible to retract multiple facts simultaneously ▪ (retract3 4 5 6)  It is possible to retract all the facts ▪ (retract*) 12

13  Retract does not change indices of remaining facts 13

14  reset command to clear all the facts  It insert a fact (initial-fact) as f-0  This fact is often used for convenience to initially activate rules 14

15  clear command for removing all facts from memory  It actually does more than just removing facts  Also removes all the rules 15

16  A fact such as (Tuesday) or (“Bahman”) is said to consist of a single field.  A field is a placeholder (named or unnamed) that may have a value associated with it.  The (Tuesday) fact has a single, unnamed field  Multi-field fact ▪ (Country Iran)  The order of unnamed fields is significant. ▪ (Country Iran) vs. (Iran Country) 16

17  Symbol nil, which means "nothing" may be used for an empty field as a placeholder. ▪ (basket-content nil)  The basket yet contains nothing 17

18  Different types of fields:  float  integer  symbol  string  … 18

19  A symbol is one type of field that starts with a printable ASCII character and is followed optionally by zero or more printable characters. 19

20  The semicolon acts as the start of a comment in CLIPS 20

21  A string must begin and end with double quotes.  The double quotes are part of the field.  Zero or more characters of any kind can appear between the double quotes. 21

22  All numbers in CLIPS are treated as long integers or double-precision floats  (assert (x 1.5))  (assert (y -1)) 22

23  It is good rule-based programming style to use the first field of a fact to describe the  relationship of the following fields. When used this way, the first field is called a relation.  (basket-contents apple orange banana) 23

24  CLIPS provides several commands to help you debug programs  One command allows you to continuously watch facts being asserted and retracted  This is more convenient than having to type in a (facts) command over and over again and trying to figure out what's changed in the fact-list. 24

25  To start watching facts, enter the command (watch facts)  The right double arrow, ==>, means that a fact is entering memory  The left double arrow, <==, indicates a fact is leaving memory 25

26  To turn off watching facts enter  (unwatch facts) 26

27  A rule is similar to an IF THEN statement in traditional programming languages  Rules are defined by defrule construct 27

28  General syntax of a rule (defrulerule_name "optional_comment" (pattern_1) ;Left-Hand Side (LHS) (pattern_2) ;of the rule consisting of elements ;before the "=>" (pattern_N) => (action_1) ;Right-Hand Side (RHS) (action_2) ;of the rule consisting of elements ;after the "=>" (action_M)) ;the last ")" balances the opening ; "(" to the left of "defrule". Be ; sure all your parentheses balance ; or you will get error messages 28

29  An action is actually a function which performs some useful action  Typically has no return value  such as an (assert) or (retract) 29

30 (defrule capital-rule “simple rule about capitals" (is-a-country ?country) ;Pattern1 (has-capital ?country ?capital) ;Pattern2 => (assert (is-a-city ?capital)) ;Action1 (assert (has-city ?country ?capital)) ;Action2 ) ;end of defrule 30

31  The name of a variable, or variable identifier, is always written by a question mark followed by a symbol that is the name of the variable. 31

32  CLIPS attempts to match the patterns of rules against facts in the fact-list.  If all the patterns of a rule match facts, the rule is activated and put on the agenda.  The agenda is a collection of activations which are those rules which match pattern entities.  Zero or more activations may be on the agenda. 32

33  The last part of a rule is the list of zero or more actions that will be executed when the rule fires.  The term fires means that CLIPS has selected a certain rule for execution from the agenda 33

34  A program will cease execution when no activations are on the agenda 34

35  When multiple activations are on the agenda, CLIPS automatically determines which activation is appropriate to fire  CLIPS orders the activations on the agenda in terms of increasing priority or salience 35

36  CLIPS always executes the actions on the RHS of the highest priority rule on the agenda.  This rule is then removed from the agenda and the actions of the new highest salience rule is executed.  This process continues until there are no more activations or a command to stop is encountered. 36

37  To see a rule, use the ppdefrule command  pretty print rule  To see a rule, specify the rule name as an argument to ppdefrule  To list all the current rules, use the rules command 37

38  You can check what's on the agenda with the agenda command 38

39  To make a program run, just enter the run command 39

40  Use printout function to print something in the output  (printout t “Hello World!“ crlf))  letter "t” tells CLIPS to send the output to the standard output device of your computer, i.e. the terminal 40

41  Besides asserting facts in the RHS of rules, you also can print out information using the printout function (defrule good_rule (today “Friday”) => (printout t “No Study! No Work!“ crlf)) ) 41

42  CLIPS can read the information from the keyboard using the read function (defrule simple-rule (initial-fact) => (printout t “Enter your name:" crlf) (assert (Person (read) )) ) 42

43  The Inference Engine sorts the activations according to their salience.  This sorting process is called conflict resolution because it eliminates the conflict of deciding which rule should fired next. 43

44  CLIPS offers seven different modes of conflict resolution: depth, breadth, LEX, MEA, complexity, simplicity, and random.  It's difficult to say that one is clearly better than another without considering the specific application.  Even then, it may be difficult to judge which is "best." 44

45  The depth strategy is the standard default strategy of CLIPS.  In this strategy, is ordered from highest to lowest salience 45

46  Can help in writing rules whose patterns have a well-defined structure.  Templates are defined by the deftemplate construct  Analogous to a record structure in Pascal, or Class in C++  Defines a group of related fields in a pattern 46

47  A deftemplate is a list of named fields called slots  Allows access by name rather than by specifying the order of fields  Contributes to good style in expert systems programs and is a valuable tool  A slot is a named single-slot or multi-slot. 47

48 (deftemplate person (slot name) (slot age) (slot eye-color) (slot hair-color) ) 48

49 (deftemplate Person “This is a sample template for the concept of person" ;optional comment (slot name (type STRING) (default “”)) (slot gender (type SYMBOL) (default male)) ) 49

Download ppt "Samad Paydar Ferdowsi University of Mashhad.  C Language Integrated Production System (CLIPS)  A tool for building expert systems  An expert system."

Similar presentations

Ads by Google