Jess issue about facts and rules

392 views Asked by At

i use Jess rule engine with java and i have a template person with a number of facts. I excecute a rule concerning persons and i would like to get the number of facts that satisfy the rule and made it fire. Is this possible; e.g.Command engine.executeCommand("(run)") returns only 0 or 1 in case a rule fired

1

There are 1 answers

1
Ernest Friedman-Hill On

Depending on what exactly you need, there are several things you might do. The function (run) actually returns the number of rules that fired, so if each fact activates one rule, then the return value of (run) would do it.

If you need to do anything more complex, then you can register a JessEventListener to be notified when each rule fires. The JessEvent will contain the whole activation record for the rule, so you can walk through it and count the facts however you like. Since rules can match the non-existence of facts, or the existence of at least one fact that fits a pattern, etc, the question of "how many facts activated a rule" isn't completely straightforward. But with the activation record in hand, you can count them however you like.