KnowledgeWorks Rule Monitor
One of the problems with forward chaining rules is determining why they are (or are not) being matched. To deal with this KnowledgeWorks has Monitor Windows for forward chaining rules. To bring up a Monitor Window, select the DEFAULT-CONTEXT
in the Rule Browser, click on PLAY
and choose Rule > Monitor. Alternatively you can use the context menu to raise the Rule Monitor window. A Rule Monitor window appears displaying in its upper pane the conditions of the rule. Both are highlighted meaning they are matched (as single conditions without reference to any variable bindings across conditions) in the object base. If you select one or more of these conditions, the message will change from "Number of instantiations matching selected conditions: <n>" to "No instantiations matching selected conditions" depending on whether objects can be found in the object base to match all the selected conditions at once (this takes account of variables bound across conditions).
By selecting the All Unfired Instantiations button, you can list any unfired instantiations of the rule. In this case there is one unfired instantiation. Selecting this in the lower pane and then choosing Instantiations > Inspect raises an Inspector tool displaying the variable bindings in the instantiation.
You can have any number of monitor windows (though at most one per rule). At times (during rule execution, for example) the object base may change. Monitor windows can be updated by choosing Works > Refresh from the Rule Monitor menu bar, or Memory > Update Monitor Windows from the KnowledgeWorks Listener. When you are single-stepping through rules (see below) Monitor windows are updated automatically.
KnowledgeWorks Gspy Window
Select a rule, say, Y-N-QUESTION
, in the Rule Browser and choose Rule > GSpy from the menu bar. This brings up a Spy Window for the rule. In it you will see the actions of the rule.
Now enter (infer)
in the Listener to run the demo again. Execution will stop when this rule fires. A message in the listener will say that the rule Y-N-QUESTION
has been called. Click on the Creep button at the bottom of the Listener to single step through the rule. Watch the highlight move through the Spy Window as you go. If you still have a Monitor Window for the PLAY
rule it will be updated automatically as you go.
Click on Leap at the bottom of the Listener and it will "leap" to the end of the rule. When you have finished, close the Spy Window (for example by Works > Exit > Window) and press Leap in the Listener window to remove the break point and continue normally.
At any point when rule execution is suspended by this mechanism, the other KnowledgeWorks tools may be used, for example to examine the object base (with the Objects Browser) or see which rules have fired (with the forward chaining history). Spy Windows are available for backward chaining rules as well, and they work in exactly the same way (they are set by selecting the rule in the Rule Browser and choosing Rule > Gspy).
KnowledgeWorks Editor
Let us suppose that when the demo finishes we would like it to ask if we want to play again. Find the definition for GAME-FINISHED
(using the Rule Browser). One line in the definition is commented out with a ;
(semi-colon) at the start. Remove the semi-colon and compile the new definition by choosing Definitions > Compile from the editor menu bar. Press Space
to return to the editor view. This rule will now ask if the user wants to play again and execution will only stop (the (return)
instruction ends execution) if requested. Run the demo to see this happen.
The rule FETCH-NEW-ANIMAL
also has a commented-out line (repeat) which will make it repeat its prompt until given an animal it does not already know. Remove the semi-colon at the start of the line in and compile the new definition of the rule. Run the demo again and try giving the system an animal it recognizes. It will prompt again. Give it an animal it does not recognize to finish.
KnowledgeWorks and Prolog User Guide (Unix version) - 01 Dec 2021 19:35:48