On Fri, 2011-08-19 at 21:12 +0400, Andrey Razumovsky wrote:
> Hi Jena folks,
>
> I would like to know how to know what reasoner has added to my OntModel,
> i.e. given Graph and InfGraph get all newly added triples. In fact, I could
> not even implement straightforward way - I've not found any way to get all
> triples from the Graph.
> Could you advice some handy mehods please? I'm using Jena 2.6.4
If you are talking about the built in Rule reasoners then the first
thing to be aware of is that some triples are added as new deductions
straight away and then more are determined dynamically in response to
questions.
So while you can get the basic forward deductions using
getDeductionsModel() if you want all the deducible triples you need to
ask the reasoner for everything.
One easy way to do that is to create a plain no-inference model to hold
the materialized deductions:
OntModel inf = ModelFactory.createOntologyModel(infspec, baseModel);
OntModel plain =
ModelFactory.createOntologyModel(OntModelSpec.OWL_MEM);
plain.add(inf);
If you want only the deductions then do:
plain.remove(baseModel);
If you want the deductions on the fly rather than storing them, then
instead use:
inf.listStatements()
If you want the deductions on the fly but not the base data then use:
inf.listStatements().filterDrop( f )
where f is a filter to drop the statments which were in base Model
(exercise for the reader :)).
Dave