I want to match a complex pattern with clips: It involves the detection of simple facts and, in a second step, the detection of more complex instances whose creation requires processing the simple facts. Currently, I approach this with three rules:
Rule1checks for a large number of simple facts and, if present, creates a complex class instancei_complexbased on the matched simple facts.Rule2also looks for the simple facts andi_complexand, if present, uses them to create an even more complex instancei_really_complex.Rule3also looks for the simple facts,i_complex, andi_really_complexand, if all present, prints something to the screen.
My current approach is to copy paste the large number of simple facts from the LHS of Rule1 to the LHS of Rule2 and Rule3. This is obviously not perfect.
I have considered the following alternative:
Putting everything in one rule. This is in fact my favored solution. The problem is that one cannot add facts/instances on the LHS of a rule. This means, for example, that I cannot check if the requirements for
i_complexare met, and if yes, create and assert it. Yet this is necessary to correctly matchi_really_complex.I have thought of a self-modifying rule which is called/matched twice: The first time it creates
i_complexon the RHS. The second time it can matchi_complexon the LHS and createi_really_complexand so on.
What is the preferred approach to match a pattern like this?