Hi Urtza,
Glad you've got it sorted.
Dave
On 26/11/15 09:31, Iturraspe Barturen, Urtza wrote:
Thanks Dave.
At the end I solve my problem!!,
I have made some changes in my code, the main changes consist on:
1.- Rewriting the rule
String rule="[AddingPizza: ->
(http://www.co-ode.org/ontologies/pizza/2005/10/18/pizza.owl#PizzaXXX rdf:type
http://www.co-ode.org/ontologies/pizza/2005/10/18/pizza.owl#Pizza)]";
2.- Reasoner object
Reasoner reasoner = new GenericRuleReasoner(Rule.parseRules(rule));
I put you my code if just in case someone has the same problem, it works!!!
public void executeReasoning(){
try{
datasetJena.begin(ReadWrite.WRITE);
Model jenaModel=datasetJena.getDefaultModel();
String rule="[AddingPizza: ->
(http://www.co-ode.org/ontologies/pizza/2005/10/18/pizza.owl#PizzaXXX rdf:type
http://www.co-ode.org/ontologies/pizza/2005/10/18/pizza.owl#Pizza)]";
Reasoner reasoner = new GenericRuleReasoner(Rule.parseRules(rule));
InfModel infModel = ModelFactory.createInfModel(reasoner, jenaModel);
infModel.prepare();
//check the infModel
Model aux=infModel.getDeductionsModel();
StmtIterator stmIt=aux.listStatements();
if (stmIt.hasNext()){
StatementImpl stmIterator= (StatementImpl) stmIt.next();
System.out.println("Sentencia:"+stmIterator.toString());
}
//end of checking
//add infModel to JenaModel
jenaModel.add(infModel.getDeductionsModel());
datasetJena.commit();
}
catch(Exception e){
System.out.println(e.getMessage());
}
finally{
datasetJena.end();
}
}
Thanks.
Urtza
OPTIMA - Optimization Modelling & Analytics Area
ICT - European Software Institute Division
TECNALIA
Parque Tecnológico de Bizkaia, Edificio 700
C/ Geldo. E-48160 Derio- Bizkaia (Spain)
Mobile: 664 00 21 51
Telephone: 902 760 002 / 946 430 850 (International calls)
[email protected]
www.tecnalia.com
-----Mensaje original-----
De: Dave Reynolds [mailto:[email protected]]
Enviado el: miércoles, 25 de noviembre de 2015 15:11
Para: [email protected]
Asunto: Re: Jena TDB and JenaRules execution
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