1 / 15

CLIPS basics

CLIPS basics. CLIPS is an industrial strength expert system shell. That is, one can use CLIPS to generate powerful industrial-strength expert systems. an expert system contains a database which in turn contains a series of facts and rules (productions).

cybil
Download Presentation

CLIPS basics

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. CLIPS basics

  2. CLIPS is an industrial strength expert system shell. • That is, one can use CLIPS to generate powerful industrial-strength expert systems. • an expert system contains a database which in turn contains a series of facts and rules (productions). • Facts come in two varieties:  structured facts (templates) and ad-hoc facts.

  3. The templates for structured tasks are specified by the deftemplatecommand:     (deftemplateaTemplate "some documentation"         (slot slot1)         (slot slot2)             (etc.)     ) e.g (deftemplate student "A student template"         (slot sno)         (slot sname)         (slot major)         (slot advisor)     )

  4. Asserting facts • There are two ways of introducing facts into the CLIPS database.  One way is to include them in a set of initial facts. (deffacts initial-facts         (student (sno 123) (snamemaigret) (major pre-med)             (advisor simenon)) ... ) deffacts are asserted after the CLIPS file containing them has been loaded into CLIPSand then after the (reset) command.

  5. Another way to assert a fact is to assert it "on the fly", generally as an action in a rule:     (assert (student (sno 123) (snamemaigret)         (major pre-med) (advisor simenon))) Note:  While running clips, keep your eye on the facts window, and you will see the facts you have written being added to the database.

  6. Non-structured facts • It is sometimes convenient to have a series of ad-hoc facts in the database, as well as the structured ones.  These are simply lists of words between parenthesis, such as:     (alarm on)     (alarm off)     (temperature high)     (valve a3572 open)

  7. Rules The basis for a production system, of course, is the collection of condition-action rules.  The syntax for defining a rule is (defrule rule-name "some documentation"     (if-condition)     (if-condition)     (etc.) =>     (action 1)     (action 2)     (etc.) ) For example: (defrule useful-rule "a useful rule"                    (animal fierce)                    (animal big)                    (animal hungry)                =>                    (assert (run away))                )

  8. What this means is that if we have the following (unstructured) facts in our database                     (animal fierce)                    (animal big)                    (animal hungry) then all of the preconditions have been met to fire useful-rule, and we assert (run away) into the database.

  9. Running CLIPS 1. Create your CLIPS code in editors like notepad and save it with the extention.clp.(e.g’example1.clp’). 2.Load the CLIPS file by ctrl+l or load command from the file menu---do compilation 3.Run the reset command from the execution menu or just type CLIPS>(reset). 4.Run your program from the execution menu or just type (run). 5. before loading the new file into CLIPS, it is necessary to clear CLIPS memory.  We do this with the (clear) command (or use the menus)…due to his existing facts in the DB will be erased.

  10. Open the facts and the Agenda windows and look the effects while the reset and run commands executed. • Note the facts defined in deffacts appearing in the facts window(asserted in the database) just after the (reset).command • CLIPS> (load "C:/Users/HP/Desktop/t1.clp")-this command loads a CLIPS file t1 from desktop • If we going to load another CLIPS file (after we finish execution of for e.g t1.clp) we better clear the CLIPS memory first by using the (clear). Command or we can find it from execution menu i.e clear CLIPS

  11. Consider this CLIPS prog. (deftemplate student "a student template" (slot sname) (slot major) (slot interest)) ; ; This defines a frame with three slots (sname, major, interest) ; (deffacts initial-facts "some initial facts" (student (snamedee) (major law)) ) (defrule rule-1 "a first rule" (student (sname ?name) (major law)) => (assert (law-interest ?name)) (printout t ?name " would be interested in Law" crlf) ) Notice the format of the printout command. The 't' is there to say that the output should go to the terminal (stdout). Variables can be mixed with text (in double-quotes). crlf means produce a carriage return at the end of the text.

  12. Edit this code in notepad and save it as student.clp • Open the CLIPS program and open the Facts and Agenda window • Notice that there is an entry in the facts window f-0 (initial-fact) • Load the student.clp file • type the reset command(reset).(NB after the reset command all structured or unstructured facts will be asserted(will become facts) or will be member of the DB,all rules which got a pattern match from the already existing facts will be placed in the agenda window(with priority no rule name: the pattern matched fact(s) )

  13. So after (reset).command in the facts window f-1 (student (snamedee) (major law) (interest nil)) will be added and on the Agenda window 0 rule-1:f-1 will be added • Type the (run). Command NB the run command will enforce nothing but all the rules in the agenda window to be fired in order of their priorities. so in the e.g the only rule in the agenda window is rule-1-when it fires it takes two actions 1.asserting another third fact in the database i.e f-2 (law-interest dee) 2.priniting an output i.edee would be interested in Law. Now the agenda window becomes empty

  14. NB execution in CLIPS is over when all the rules in the agenda window fired(nothing left). • Add the following rule to student.clp (defrule rule-2 "a second rule"    ?f1 <- (student (sname ?name) (major law) (interest nil))=>    (modify ?f1 (interest law))) What will happen in the facts DB and the agenda window?

  15. The ?f1 does two things (although any variable name will do, that is ?anyname, CLIPS programmers generally use ?f1, ?f2, and so forth).  In the first occurrence of ?f1,  ?f1 <- (student (sname ?name) (major law)), we bind the fact number of the fact into the variable ?f1.  We can then use that stored value to modify the rule by changing the value of the existing (slot interest) with the value (interest law).  There must be a slot with this name, otherwise nothing works.

More Related