10 Rule-based Shell, Diagnosis
Write a simple shell for rule-based expert systems. The knowledge is represented in if-then rules that have the following syntax:
Rule : if Premise then Conclusion /* '#' instead of ':' in SWI Prolog */
Premise can be built out of simpler Premises using
and, or, not
The rule grammar is given by the operator definitions. The needed operators can be defined in the file that is consulted:
define_operators :- op( 920, xfy, and), op( 930, xfy, or), op( 950, xfx, then), op( 960, fx, if), op( 970, xfx, #). /* '#' used instead of ':' in SWI Prolog */ :- define_operators.
The shell operates backwards according to the Prolog proof method. A goal G is proven either when it is known to be true, or the user say so, or when there is a rule
R: if G1 then G. /* Use '#' in SWI Prolog instead of ':' */
and G1 is proven. If the user is be asked he should be asked only once for a specific goal. This means that the user's answers have to be stored.
Use the rule-based shell from Example 10.1 for the fault finding according to the method of hypothesis testing. The rules are formulated such that they show from symptoms (observations) to causes (diagnosis, faults). A possible diagnosis (priamary fault) is guessed and then tried to be proven by ackward chaining.
Test this method on the example of a steam iron:
- If the cloth is burnt, then the temperature is too high.
- If the temperature is too high or to low, then the temperature is wrong.
- If the temperature is wrong and the thermostat is set correctly, then the thermostat is faulty.
- If the temperature is wrong and the thermostat is not set correctly, then the thermostat should be set correctly.
- If no steam comes out, then the temperature is too low or there is a problem in the steam system.
- If there is a problem in the steam system, then there is no water or the nozzle is congested.
- If the iron result is poor, then the temperature is too low.
- If the iron is cold and the control lamp shines, then we need to wait.
- If the iron is cold and the control lamp does not shine, then there is no power.
Start with only a few rules. Improve the provided rules and add further rules as you like.
The rule 5 can be approximated by two rules:
5a) If no steam comes out, then the temperature is too low.
5b) If no steam comes out, then there is a problem in the steam system.
The interpretation of the implication is: "It could be that ...".