Spis treści

CLIPS & Prolog

Download

Please download the following files containing simple knowledge bases about a family:

Knowledge Bases

Both files have corresponding content:

In addition, files contain a single rule defining the child relation.

1. Loading The Facts

After downloading the files, they have to be loaded into corresponding Knowledge Bases (KB):

2. Display the KB

To view the contents of the KB, enter:

3. Inference

CLIPS uses the forward-chaining. The inference is implemented as a loop, that checks what rules can be executed based on the current state of the KB. Then the found rules are executed and the cycle repeats. The loop ends when it fails to find a rule to execute. The input of the forward-chaining algorithm is the set of facts in the knowledge base.

In Prolog we use backward-chaining and the process is inverted. The input of this algorithm is target — fact that we want to infer. We may say that this a goal-oriented approach. Let's ask:

4. How to use Rules

Both files contain a rule defines who/what is a child.

CLIPS failed to start this rule (previous point). In Prolog, we can query using this rule:

child(X, Y).

5. Creating Rules

In order to run the child rule, we have to define:

5.1. Adding Knowledge to the KB

5.1.1. Son and daughter

We can try now to supplement the current KB with new rules, that define other relationships:

5.1.2. Marriage

5.1.3. Other

Knowing that the concepts brother is defined as follow:

Define the following rules:

6. Tracking the execution of the program

Since CLIPS doesn't correctly find the widowers, it is necessary to track the execution of the program:

6.1. Tracking the facts

Allows you to track operations on facts: add, delete, change of the value.

  1. In the first step, we will start observing the widower rule to see what triggers it:
     (watch rules widower) 
  2. We reset the fact base:
     (reset) 
  3. Restart the inference:
     (run) 
  4. Now we see the triggers and indexes of facts from which we started.
  5. Now check which fact triggered the inference:
    (facts)

6.2. Rule tracking

Allows tracking of rules: firing, activation.

  1. Because we did learn nothing interesting tracing the fact, we will follow the widow rule and all the rules it depends on: parent, marriage:
    (unwatch all)
    (watch rules marriage widow parent)
  2. Now we reset the fact base:
     (reset) 
  3. Restart the inference:
     (run) 
  4. What is the reason behind the malfunction of the widower rule?
  5. How can we fix it?

6.3. Tracking in Prolog

Prolog allows you to follow the program. To do so, you set the so-called. trace point.

Trace points:

?- trace, woman(K), parent(K, _).

Check following code:

?- trace(parent).
[debug] ?- trace(mother).
[debug] ?- trace(father)
[debug] ?- parent(dariusz, tomasz).
[debug] ?- nodebug.