You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@jena.apache.org by Yoga Indra Pamungkas <yo...@ymail.com> on 2012/08/29 15:30:48 UTC

Jena Inference and store to database

I'm using Jena 2.6.4 and build digital library over JSF Framework. The digital library have feature that let users can make anotation to the thesis document base on ontology. What I'm asking is, every anotation is represent by triple rdf, and this rdf will be inference to the ontology. 

1. I have done the inference, and the triple statement anotation is store to the database, but I don't know how to store the inference statement to database.
2. My ontology isn's store in the database, but as a file, and called every time to inference the rdf statement anotation. Is it better to store it in database and save the inference ontology to database? and if this the best way, how to inference my rdf statement from anotation?

Thanks for the help. 

Re: Jena Inference and store to database

Posted by Dave Reynolds <da...@gmail.com>.
On 29/08/12 14:30, Yoga Indra Pamungkas wrote:
> I'm using Jena 2.6.4 and build digital library over JSF Framework. The digital library have feature that let users can make anotation to the thesis document base on ontology. What I'm asking is, every anotation is represent by triple rdf, and this rdf will be inference to the ontology.

> 1. I have done the inference, and the triple statement anotation is store to the database, but I don't know how to store the inference statement to database.

The details depend slightly on the sort of inference configuration you 
are using.

Assuming you are using one of the built in RDFS/OWL rule configurations 
then you presumably have an InfModel (or an OntModel) which includes the 
annotation data, ontology and deductions.

The brute force way to store those in a database backed model is:

   // appropriate locking or transaction creation
   datamodel.add( infModel );
   // appropriate unlocking or transaction commit

However, this will add a copy of the ontology and all of the inferences 
to your datamodel.

If you just want some of the inferences, for example just inferred 
statements that have as subject one of the terms in your annotation then 
you can be more selective on the statements you copy. For example:

   // appropriate locking or transaction creation
   ResIterator ri = annotationModel.listSubjects();
   while (ri.hasNext()) {
       Resource subject = ri.next().inModel( infModel );
       datamodel.add( subject.listProperties() );
   }
   // appropriate unlocking or transaction commit

If you are doing the inference using your own rule set and you use only 
forward rules then your best bet would be:

   // appropriate locking or transaction creation
   datamodel.add( infModel.getDeductionsModel() );
   // appropriate unlocking or transaction commit

However, that option isn't useful for the general case because it will 
only persist the forward deductions and the default RDFS/OWL rule sets 
use hybrid rules.

> 2. My ontology isn's store in the database, but as a file, and called every time to inference the rdf statement anotation. Is it better to store it in database and save the inference ontology to database? and if this the best way, how to inference my rdf statement from anotation?

 From the point of view of doing the inference there's no advantage to 
storing the ontology in the database. You are better off using an 
in-memory copy which can as easily be initialized from a file.

However, depending on the rest of your application it is often useful to 
*also* put the ontology in the data store so that it can be referenced 
in queries.

Dave