You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@jena.apache.org by Deyan Chen <ch...@neusoft.com> on 2013/08/22 08:39:58 UTC

How to load OntModel including imported sub-models to TDB?

Hi All,

I want to load an ontology file to persistent TDB store. The ontology
file imports other ontologies that are also located in the same local
directory. The code is as follows:

......
Dataset dataset = TDBFactory.assembleDataset(assemblerFile);
dataset.begin(ReadWrite.WRITE);
try {

Model base = dataset.getDefaultModel();
OntModel model = ModelFactory.createOntologyModel(OntModelSpec.OWL_MEM,
base);

OntDocumentManager dm = model.getDocumentManager();
dm.setProcessImports(true);
dm.setCacheModels(true);

FileInputStream inputStream =
FileIOManager.getFileInputStream(inputFileName);
model.read(inputStream);

// Finally, commit the transaction.
dataset.commit();
} finally {
dataset.end();
}

Then I want to get a sub-model from the dataset,
......
Dataset dataset = TDBFactory.assembleDataset(assemblerFile);
dataset.begin(ReadWrite.READ);
try {

Model subModel = dataset.getNamedModel("http://...");
Query query = QueryFactory.read(queryString);
QueryExecution qexec = QueryExecutionFactory.create(query, subModel);
try {
ResultSet results = qexec.execSelect();
ResultSetFormatter.out(results);
} finally {
qexec.close();
}
} finally {
dataset.end();
}

But the output is null. Can you tell me how to do?
Thank you very much.

Deyan
---------------------------------------------------------------------------------------------------
Confidentiality Notice: The information contained in this e-mail and any accompanying attachment(s) 
is intended only for the use of the intended recipient and may be confidential and/or privileged of 
Neusoft Corporation, its subsidiaries and/or its affiliates. If any reader of this communication is 
not the intended recipient, unauthorized use, forwarding, printing,  storing, disclosure or copying 
is strictly prohibited, and may be unlawful.If you have received this communication in error,please 
immediately notify the sender by return e-mail, and delete the original message and all copies from 
your system. Thank you. 
---------------------------------------------------------------------------------------------------