1 / 49

A Brief Introduction to CLIPS C Language Integrated Production System

Samad Paydar Ferdowsi University of Mashhad. A Brief Introduction to CLIPS C Language Integrated Production System. Inroduction. C Language Integrated Production System (CLIPS) A tool for building expert systems

rosariov
Download Presentation

A Brief Introduction to CLIPS C Language Integrated Production System

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. SamadPaydar Ferdowsi University of Mashhad A Brief Introduction to CLIPSC Language Integrated Production System

  2. Inroduction • 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

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

  4. Inroduction • 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

  5. Knowledge Representation • 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

  6. Facilities • CLIPS supports developing expert systems by providing some facilities • An integrated editor • Debugging tool • Shell • Portion of CLIPS which performs inferences or reasoning

  7. Main Elements • 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

  8. Basic Points • CLIPS has a LISP-like syntax • Extensive use of parentheses • E.g. as delimiters • It is case-sensitive

  9. Facts • 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))

  10. Facts • 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.

  11. Facts • 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)

  12. Facts • Example • (retract 2) • It is possible to retract multiple facts simultaneously • (retract 3 4 5 6) • It is possible to retract all the facts • (retract *)

  13. Facts • Retract does not change indices of remaining facts

  14. Facts • 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

  15. Facts • clear command for removing all facts from memory • It actually does more than just removing facts • Also removes all the rules

  16. Facts • 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)

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

  18. Types • Different types of fields: • float • integer • symbol • string • …

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

  20. Comments • The semicolon acts as the start of a comment in CLIPS

  21. String • 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.

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

  23. Relations • 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)

  24. Debug • 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.

  25. Watch • 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

  26. unwatch • To turn off watching facts enter • (unwatch facts)

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

  28. Rules • 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

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

  30. Rules (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

  31. Variable • 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.

  32. Rules • 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.

  33. Rules • 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

  34. Rules • A program will cease execution when no activations are on the agenda

  35. Rules • 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

  36. Rules • 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.

  37. Rules • 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

  38. Agenda • You can check what's on the agenda with the agenda command

  39. Run • To make a program run, just enter the run command

  40. Creating output • 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

  41. Creating output • 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)) )

  42. Input • 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) )) )

  43. Conflict Resolution • 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.

  44. Conflict Resolution • 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."

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

  46. Templates • 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

  47. Templates • 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.

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

  49. Templates (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)) )

More Related