On 25/11/15 12:24, Iturraspe Barturen, Urtza wrote:
Hi everybody,

I am trying to execute a Jena Rule using Jena TDB.
I have already expertise using Jena rules in Jena SDB but now I was trying 
using TBD.

The rule inserts an instance in an ontology. The content of jena.rule file has 
this rule:

@prefix pi: <http://www.co-ode.org/ontologies/pizza/2005/10/18/pizza.owl#>. @prefix rdf: 
<http://www.w3.org/1999/02/22-rdf-syntax-ns#>. [AddingPizza: -> (pi:PizzaXXXX 
rdf:type pi:Pizza) ]



The code that I use is the following. Perhaps is something is wrong,  please 
anyone can help me ?

You haven't said what the problem is.

Model jenaModel=datasetJena.getDefaultModel();

Reasoner reasoner = new 
GenericRuleReasoner(Rule.rulesFromURL("file:./src/jena.rule"));

InfModel infModel = ModelFactory.createInfModel(reasoner, jenamodel);

infModel.prepare();

Need to start the transaction:

 datasetJena.begin(ReadWrite.WRITE) ;
 try {

jenamodel.add(infModel);

This has different spelling to the above so suggests this is not actually the code you are running.

With correct spelling this should work but causes redundant adds, if you are only using forward rules then better to use:

  jenaModel.add( infModel.getDeductionsModel() );

so as to only add new statements.

datasetJena.commit();

 } finally {
   datasetJena.end() ;
 }

TDB.sync(jenamodel);

Not necessary if you are using transactions.

infmodel.close();

datasetJena.commit();

datasetJena.end();

No need to call these again, you did the commit earlier.

If, with fixed transaction handling, it doesn't work then (a) check what is in the infModel.getDeductionsModel() and (b) try with an in-memory dataset.

Dave


Reply via email to