On 28/08/13 04:00, Deyan Chen wrote:
> Hi all,
> 
> I want to read an ontology file which imports several other ontology
> files to a TDB store.
> 
> The test code is as follows:
> 
> Dataset ds = TDBFactory.createDataset(location);
> Model base = ds.getDefaultModel();
> OntModel model =
> ModelFactory.createOntologyModel(OntModelSpec.OWL_DL_MEM, base);
> // need to process imports
> model.read(sourceURL);
> ds.close();
> 
> I can get imported model from the ontology model by:
> 
> ...
> OntModel model1 = model.getImportedModel(uri);
> ...
> 
> But I can't get it from the TDB store. Although I can add these imported
> models to TDB by method:
> 
> ds.addNamedModel(uri, model);
> 
> but it's very inconvenient. Are there any good methods can be used to
> achieve it automatically?

When you read an OntModel which does imports processing then it reads
only the base model into the underlying model and loads the imported
models separately. How those imported models are stored is defined by
the OntDocumentManager settings and associated ModelMaker.

It is possible to arrange for the imported models to be persisted in a
store like TDB (e.g. as separate graphs). However, the documentation for
that is a little out of date and doesn't directly cover the TDB case
specifically. Have a look at:
http://jena.apache.org/documentation/ontology/index.html#working-with-persistent-ontologies

[The link to the example code is not working, I suspect because it used
a now-obsolete persistence module.]

The alternative would be to merge all your data into one model. If you
don't need the separate submodel mechanism then once your ontology is
loaded you could list all the submodels and add each of those to your
base model so that the dataset default graph would then contain the
union of your ontology and all its imports. When you reopen that TDB
store in another jvm instance then switch off import processing.

Dave

Reply via email to