vendredi 26 avril 2019

CLIPS: testing correct facts

I have a series of rules and a set of initial (assert) facts. Now, I want to add those facts, run the rules, and then apply another set of rules to check if the current existing facts after (run) contains correct facts and nothing else, without triggering the previous rules anymore and without destroying current facts. Then, I want to keep going applying new facts, running new rules, and test new inserted facts, etc.

How can I do that? My test (batch) file is something like:

(clear) ; just in case
(load constructs.clp) ; All loaded in the MAIN module.

(assert (blabla))
(assert (blabla2))
(run)

;; Code (rules/functions... I'm still wondering how to do it) to check
;; current facts

(assert (blabla3))
(assert (blabla4))
(run)

;; More tests.

(exit)

I have tried to create, for each deftemplate T a deftemplate T-copy with same slots and them apply a (assert (testing)) fact to make the copies first. Then I fire a set of rules with testing purposes and higher salience that "halts" the (run) execution when it's done, to avoid firing the previous rules (the rules I'm testing). The problem with that approach, apart from requiring too many steps, is that I don't know the salience of the original rules and so I cannot be sure that the testing rules will have more priority.

I'm aware of the defmodule constructs and the focus stack but I haven't understood them yet. If my guesses are correct, I think I could put all of my testing rules in a specific module and place the focus on that module to avoid execution of any MAIN rule. If something is wrong, I'll (halt) execution in one of the testing rules or just (exit) the batch script. If everything is correct, I pop the testing module to come back to MAIN, add more assert, (run) again, and them push the testing module again with new tests to see if everything is still correct.

But I'm not sure if my assumptions are right I'll like to see an example of how should I do the testing.

PD: In addition, my CLIPS version has no support for fact-set queries.

Aucun commentaire:

Enregistrer un commentaire