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).
The templates for structured tasks are specified by the deftemplatecommand:
(deftemplateaTemplate "some documentation"
e.g (deftemplate student "A student template"
(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.
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.
(valve a3572 open)
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"
(defrule useful-rule "a useful rule" (animal fierce) (animal big) (animal hungry) => (assert (run away)) )
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.
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
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.
Open the facts and the Agenda windows and look the effects while the reset and run commands executed.
(deftemplate student "a student template"
; 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.
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
NB execution in CLIPS is over when all the rules in the agenda window fired(nothing left).
(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?
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.