Reopen
- The load command loads in the rule that you had previously saved to disk in the file "duck.clp" or whatever name and directory that you had saved it under. You can load a file of rules made on a text editor into CLIPS using the load command.
- File → Load → file_name.clp
- Assert fact
Show Me the Rules
- Something you may want to see a rule while you're in CLIPS. There's a command called ppdefrule- the pretty print rule - that prints a rule. To see a rule, specify the rule name as an argument to ppdefrule.
- For example,
Fire the rule
- If there is only one rule on the agenda, that rule will fire. Since the LHS pattern of the duck-sound rule is
- This pattern will be satisfied by the fact (animal-is duck) and so the duck-sound rule should fire.
- To make a program run, just enter the run command. Type (run) and press the carriage return key. Then do a (facts) to check that the fact was asserted by the rule.
- If you try this and (run) again, you'll see that the rule won't fire.
- you need do know a little more about some basic principles of expert systems.
- A rule is activated if its patterns are matched by a
- 2. a pattern entity that did exist before but was retracted and reasserted, i.e., a "clone" of the old pattern entity, and thus now a new pattern entity.
- The Inference Engine sorts the activation according to their salience. This sorting process is called conflict resolution because it eliminates the conflict of deciding which rule should fired next. CLIPS executes the RHS of the rule with the highest salience on the agenda, and removes the activation.
- This execution is called firing the rule in analogy with the firing of a neuron. A neuron emits a voltage pulse when an appropriate stimulus is applied. After a neuron a fires, it undergoes refraction and cannot fire again for a certain period of time. Without refraction, neurons would just keep firing over again on exactly the same stimulus.
Write to Me
- Besides asserting facts in the RHS of rules, you also can print out information using the printout function. CLIPS also has a carriage return/ linefeed keyword called crlf which is very useful in improving the appearance of output by formatting it on different lines.
- For a change, the crlf is not included in parentheses. As an example,
(animal-is duck)
=>
(printout ! "quack" crlf) ) ; Be sure to type in the "t"
CLIPS> (run)
Stop And Go
- Suppose you wanted to write an expert system to determine how a mobile robot should respond to a traffic light. It is best to write this type of problem using multiple rules. For example, the rules for the red and green light situations can be written as follows.
(light red)
=>
(printout t "stop" crlf) )
(defrule LG
(light green)
=>
(printout t "Go" crlf) )
- Suppose we want a rule to fire if the robot is walking and if the walk-sign says walk. A rule could be written as follows:
( status walking)
(walk-sign walk)
=>
(printout t "Go" crlf) )
Logical AND
- You can have any number of patterns or actions in a rule.
- The important point to realize is that the rule is placed on the agenda only if all the patterns are satisfied by facts.
- This type of restriction is called a logical AND conditional element (CE) in reference to the AND relation of Boolean logic.
- An AND relation is said to be true only if all its conditions are true. Because the patterns are of the logical AND type, the rule will not fire if only one of the patterns is satisfied.
- All facts must be present before the LHS of a rule is satisfied and the rule is placed on the agenda.
- 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. The general format is
- Just as in other programming languages, variable names should be meaningful for good style. Some examples of valid variables names follow. ?x ?noun ?color ?sensor ?valve ?ducks-eaten
- Before a variable can be used, it should be assigned a value. As an example of a case where a value is not assigned, try to enter the following and CLIPS will respond with the error message shown.
=>
(printout t ?x crlf)
Bind value to a variable
- CLIPS gives an error message when it cannot find a value bound to ?x. The term bound means the assignment of a variable.
- Only global variables are bound in all rules.All other variables are only bound within a rule.
- Before and after a rule fires, nonglobal variables are not bound and so CLIPS will give an error message if you try to query a nonbound variable. CLIPS> (bind ?a 5)
- One common use of variables is to match a value on the LHS and then assert this bound variable on the RHS. For example, enter
( duck-sound ?sound)
=>
(assert (sound-is ?sound) ) ) )
No comments:
Post a Comment