You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@jena.apache.org by Paul Houle <pa...@ontology2.com> on 2016/07/06 14:59:48 UTC

Triggering Rules Execution

One scenario I am looking at with the Jena Rules Engine is:

(i) facts get put into the model when something happens outside the
"system",  and
(ii) this causes head actions to run which cause things to happen

One specific case is that there is a calculation that has many steps, 
most of the data gets passed through an execution fabric (data plane)
but the control plane is written with JRE.  When the data plane finishes
a step,  facts get punched into the model,  then the JRE tears down the
last step and sets up the new steps that are possible with the data now
available.

I sent in a pull request (JENA-1204) which adds support for multiple
BuiltinRegistries and in the unit test I discovered some details of how
this work,  particularly around
TestGenericRuleReasonerConfig.testRuleLoadingWithOverridenBuiltins.

In particular,  I found that the rules don't seem to execute when you
add facts,  but rule execution is triggered when the listStatements(...)
method of the InfModel gets called.  The way this shows up is that the
head actions fires when I call the size() method of the InfModel on line
166 (thus I see an item in the savedNode list on line 167.)  If I don't
call size() or otherwise look at the InfModel,  nothing happens.

So I am wondering what the "right" way is to trigger rule execution in
this case.  I am happy to punch a few rules in and then trigger
execution,  but I'd like some way to do it that doesn't do any work I
don't need done.

-- 
  Paul Houle
  paul.houle@ontology2.com

Re: Triggering Rules Execution

Posted by Dave Reynolds <da...@gmail.com>.
On 06/07/16 15:59, Paul Houle wrote:
> One scenario I am looking at with the Jena Rules Engine is:
>
> (i) facts get put into the model when something happens outside the
> "system",  and
> (ii) this causes head actions to run which cause things to happen

Generally reactive or "ECA" (Event Condition Action) rule engines have a 
different design centre to deductive rule engines - but it's true that 
the RETE type engine could be used for both.

> One specific case is that there is a calculation that has many steps,
> most of the data gets passed through an execution fabric (data plane)
> but the control plane is written with JRE.  When the data plane finishes
> a step,  facts get punched into the model,  then the JRE tears down the
> last step and sets up the new steps that are possible with the data now
> available.
>
> I sent in a pull request (JENA-1204) which adds support for multiple
> BuiltinRegistries and in the unit test I discovered some details of how
> this work,  particularly around
> TestGenericRuleReasonerConfig.testRuleLoadingWithOverridenBuiltins.
>
> In particular,  I found that the rules don't seem to execute when you
> add facts,  but rule execution is triggered when the listStatements(...)
> method of the InfModel gets called.  The way this shows up is that the
> head actions fires when I call the size() method of the InfModel on line
> 166 (thus I see an item in the savedNode list on line 167.)  If I don't
> call size() or otherwise look at the InfModel,  nothing happens.
>
> So I am wondering what the "right" way is to trigger rule execution in
> this case.  I am happy to punch a few rules in and then trigger
> execution,  but I'd like some way to do it that doesn't do any work I
> don't need done.

prepare() should do this in the case of a forward or hybrid reasoner. 
You can also use getDeductionsGraph/getDeductionsModel but all that does 
is a prepare() under the hood.

Dave