On 05/04/13 15:09, David Jordan wrote:
Dave,
I have been getting "less than stellar" performance in my benchmarking. I would
just like to be sure that the way I am using Jena IS performing inference over in-memory
models. I have stored Models in the database. When I access them and create an OntModel,
I do it in the following manner:
Store store; // assume this is initialized
Model model = SDBFactory.connectNamedModel(store, name);
OntModelSpec spec = new OntModelSpec(OntModelSpec.OWL_MEM_MICRO_RULE_INF);
OntModel omodel = ModelFactory.createOntologyModel(spec, model);
omodel.prepare();
Does this result in an in-memory model as you recommend?
No, that's an inference model running over the database.
If not, could you show the necessary code.
Depends on what you are trying to do. Whether your data is static. What
inferences you want (all or just some interesting ones). Whether the
source data is large. Whether is available as a file or only a database
model. Etc.
In the simple case your data is essentially fixed and you can precompute
and store the inferences.
Model memmodel = ModelFactory.createDefaultModel();
// read data into model or use FileUtils.get().loadModel instead
OntModelSpec spec =
new OntModelSpec(OntModelSpec.OWL_MEM_MICRO_RULE_INF);
OntModel omodel = ModelFactory.createOntologyModel(spec, memmodel);
dbmodel.add( omodel );
If there are only some inferences you need then you might be more
selective in what the final "add" phase puts into the database model.
Then you access that data in future uses via a non-inference model:
Model dbmodel = SDBFactory.connectNamedModel(store, name);
OntModelSpec spec = new OntModelSpec(OntModelSpec.OWL_MEM);
OntModel omodel = ModelFactory.createOntologyModel(spec, dbmodel);
If your data is already in the database and you want to dynamically
compute the inferences over its current state then do something more like:
Model memmodel = ModelFactory.createDefaultModel();
memmodel.add( dbmodel );
OntModelSpec spec =
new OntModelSpec(OntModelSpec.OWL_MEM_MICRO_RULE_INF);
OntModel omodel = ModelFactory.createOntologyModel(spec, memmodel);
// use omodel
Any updates to the data will need to be reflected into the omodel. If
those updates are done in the same VM that might be OK, if they are done
by other database clients then that's problematic.
Fundamentally databases and Jena's rule-based inference do not mix well.
Depending on what you need from inference you may be able to achieve the
same effects by query rewriting, or query rewriting plus some simpler
pre-computed closure. In the worst case you need a full deductive database.
For minimal RDFS inference then there is some support in the TDB loader
for computing that more efficiently at load time than the full in-memory
rule systems do.
Dave