I have used CLIPS previously and I refreshed my memory by reading Chapers 1 through 7 of the CLIPS User's Guide.
I analyzed the "Who owns the Zebra?" problem (i.e., zebra.clp). I can see that everything hinges on the correct coding of the find-solution rule, which is huge.
I tried to use the matches command to debug the run, but I did not get the output that I expected.
(My input and output are at the end of this post.)
I naively entered (matches find-solution) after (watch facts) and before (run) and got a snapshot of the matches at that particular moment (which was none).
So, my question is how does one debug a huge rule like this?
Am I on the right track or is there a better approach?
(My input and output.)
==> f-0 (initial-fact)
CLIPS> (load "C:/Program Files/CLIPS/Examples/zebra.clp")
Defining deftemplate: avh
Defining defrule: find-solution +j+j+j+j+j+j+j+j+j+j+j+j+j+j+j+j+j+j+j+j+j+j+j+j+j+j
Defining defrule: print-solution +j+j+j+j+j+j+j+j+j+j+j+j+j+j+j+j+j+j+j+j+j+j+j+j+j+j
Defining defrule: startup +j+j
Defining defrule: generate-combinations +j+j
CLIPS> (watch facts)
CLIPS> (matches find-solution)
Matches for Pattern 1
Matches for Pattern 2
Matches for Pattern 24
Matches for Pattern 25
Partial matches for CEs 1 - 2
Partial matches for CEs 1 - 3
Partial matches for CEs 1 - 24
Partial matches for CEs 1 - 25
There are five houses, each of a different color, inhabited by men of
different nationalities, with different pets, drinks, and cigarettes.
The Englishman lives in the red house.
This rule is a bit atypical in that it's solving a constraint satisfaction problem with a single rule so it's not that easy to step through what's happening, but the general techniques for using the matches command are still applicable. In the cases that I've primarily used it for I'm trying to find out why a particular rule didn't fire. I've developed an expert system with around 600 rules that can have thousands of facts as input. The users will come across an issue with unexpected behavior and report it with some key pieces of information that identify the pertinent data. Typically I know what rules are involved with the problem. If the users indicate that the xyz flag isn't being set, I know the rule(s) in question that need to be debugged. I'll step through execution until I get to the point where the rule should be firing. At that point, I'll examine the facts that are relevant to the rule(s). I know what patterns are involved with the rules so I know which fact types need to be examined. If the users said that the xyz flag wasn't set for the order with id number 8738, I use the fact query functions to find the relevant fact. Once I know some of the key facts that I'm expecting to match the rule, I can start using the matches command to see why the rule isn't firing. If there are a large number of matches, I'll use the dribble command to capture the output from the matches command so I can search through it in a text editor. I look through the matches output until I see the point in the rule where there are no partial matches. Using the fact IDs I'd previously identified, I can trace back at that point to see which pattern is not being matched in the rule. I can then go look back through the facts to see if I can find the fact that was supposed to match the rule and try to determine why it didn't.