There's no support for dynamically adding forward rules to a "running"
reasoner that I recall.
You can dynamically add backward rules to a hybrid reasoner, but that's
not relevant here.
Your code example suggests you are calling addRule on a
BasicForwardRuleInfGraph but, unless I'm missing something, that method
is not in the jena source. Is it something you have added?
You can add rules to a reasoner but then would essentially have to build
a new InfGraph or reset the engine state of the current infgraph. Either
way that's why you are seeing the original deduction retrigger.
If you need to fire some action when adding triples to a model, and
dynamically change the processing, I'd suggest using the listener
machinery rather than the rule system.
Dave
On 28/03/2023 18:43, L B wrote:
I am currently still trying to figure out the solution.
1. If I do not call coreInfModel.prepare(), nothing happens during the
triple update which is WAD, I believe.
2. When one triple is updated, all the rules which have true condition will
be triggered, rather than the rules related. I am expecting the other rules
will not be triggered unless its related triplets are updated. Is it
possible?
L B <[email protected]> 于2023年3月24日周五 16:10写道:
1) Init code:
GenericRuleReasoner reasoner = new GenericRuleReasoner(new
ArrayList<Rule>());
reasoner.setMode(GenericRuleReasoner.FORWARD);
mCoreInfModel = ModelFactory.createInfModel(reasoner,
mCoreModel);
2) Statement exits
(:A :B :C)
3) Rule exists and triggered before
[ alwaysTrue:
(:A :B :C)
-> triggerAction
]
4) Now, I am trying to add rules at runtime.
[ rule2:
(:X :Y :Z)
-> triggerAction2
]
InfModel infModel = getCoreInfModel();
BasicForwardRuleInfGraph infGraph = (BasicForwardRuleInfGraph)
infModel.getGraph(); infGraph.addRule(rule)
coreInfModel.prepare()
5) add triple (:X :Y :Z)
val infGraph = infModel.graph as BasicForwardRuleInfGraph
infGraph.add(triple)
*The problem comes, both "alwaysTrue" and "rule2" triggered.*
*I am expecting only "rule2" is triggered. *
Is there anyway that only "rule2" can be triggered since the updated
triple is only X, Y Z?
Many thanks