The point of this lab is to get a rule based system running. You
will develop your own rule and working memory. It's a simple system
but is a good first step toward building expert systems. Once you
have built the system, this lab walks you through a few more features
of Clips.
- Get Clips running, it's usually under middlesex software, programming
languages, clips
- It's also on
http://www.ghg.net/clips/CLIPS.html. You can download
it either in the lab (if it's not there) or at home.
- It is a standalone application. We'll be typing things directly
into it, but you can also save things to files and then load the
file. You should be able to load from files by the end of the
lab.
- Note that there is both in-line help (try (help); it isn't very helpful)
and a big manual in postscript.
Facts
- Clips (and other rule based systems) are based on facts. Facts are
also called working memory (WM).
- If you want to look at the facts that are defined use the (facts)
command at the input prompt. Intially, you should have no
facts because you haven't defined any.
- Note that all functions in Clips are inside parentheses, so the (facts)
command is a function.
- First, lets say that Chris is 39 years old.
- You do this by asserting a fact.
- CLIPS> (assert (age-is Chris 39))
- I've defined this fact in the format (age-is ?person ?age). There is
no reason that I couldn't have made it (age ?age ?person) or even
(person ?firstname ?lastname ?age)
- The way your facts look is important later for the rules. In brief,
a fact is a series of arguments with the first one being a word. You
can use dashes - in the word.
- Add a fact for your own age.
- Look at the facts you've defined
Rules
- Now we'll implement my rule, then you should implement your own.
- Lets make a rule that says if a person is 39 then he is middle aged.
- You do this by using defrule command. Its format is
(defrule name if-part => then-part)
An example rule definition is 3 lines below.
- You fill in name, if-part, and then-part; they are variables.
- The arrow is made by an equal sign followed by a greater than sign
- CLIPS>(defrule make-middle (age-is ?X 39) =>
(assert (age-category ?X middle-aged)))
- (That ?X thing is a variable in a rule; we'll talk about it more
later.)
- Now (run). This tells the system to run any rules it can.
- Look at facts (facts) to see that there are two including the initial
one, and the one that the rule put in.
- You can (reset) to get rid of all the facts.
Your own ES
- Now make a rule of your own, and make sure it isn't about age.
- Do you have any questions about case-sensitivity, predicate numbers
or anything else?
- Save the file in something like lab1.clp. This saves all the
rules but not the asserts. Make sure you put just the rules in
the clip file not the entire dialog.
- (clear) to get rid of the rules and the asserts.
- (load) the rules again, and test.
- Use the initial-fact to make a rule that puts the asserts in;
save, clear, load and test again
- When you're done, you can (exit) to leave Clips.