tags:

views:

369

answers:

1

I have a Jena ontology model (OntModel) which I'm modifying programatically. This model was initially created using the default ModelFactory method to create an Ontology model (with no parameters). The problem was, as the program ran and the model was changed, the default Jena Reasoner would run (and run and run and run). The process was entirely too slow for what I need and would run out of memory on large data sets.

I changed the program to use a different ontology model factory method to create a model with no reasoner. This ran extremely fast and exhibited none of the memory problems I saw earlier (even for very large data sets). The problem with this approach is that I can only access the data by directly using it's direct class type (I can not gain access to objects using it's parent class).

For example, imagine I had two class resources, "flower" and "seed". These inherit from a common parent, "plant material". My program takes all the "seeds", runs a method called "grow" which transforms the "seed" object into a "flower" object. The "grow" method runs too slow and runs out of memory when using a Reasoner (even the micro Reasoner). If I turn off the Reasoner, then I can't access all the "flowers" and "seeds" using the "plant material" class.

Is there a preferred way (a happy medium) to doing this... allowing the ability to access objects using their superclass while also being fast and not a memory hog?

I've been looking for a way to "turn off the reasoner" while I run my "grow" method and then turn it back one once the method completes. Is this possible somehow?

+2  A: 

I got some help and suggestions, then this is how I solved this problem.

Basically, I gained access to another model without a Reasoner, batched all my changes to the basic model, then rebound the full model with the reasoner to get the updates.

Here's some psuedo code. It doesn't exactly match my "real" scenario, but you get the idea.

// Create a model with a reasoner and load the full model from owl files or
// whatever
OntModel fullModel = ModelFactory.createOntologyModel();
fullModel.read(...);

// create a model without a reasoner and load it from the full model with
// reified statements
OntModel basicModel = ModelFactory.createOntologyModel(OntModelSpec.OWL_MEM);
basicModel.add(fullModel);

// batch modifications to the basic model programatically
//(**** RUNS REALLY QUICK *****)

// rebind the full model
fullModel.rebind();

// continue on....
Vinnie