On 26/04/12 15:21, Crapo, Andrew (GE Global Research) wrote:
I’m trying out TDB as a triple store. I’m not sure if this is a bug or a
misunderstanding. I have the following JUnit test code:

Which version?
I don't think the sync bug affects this example, but if you could run the current development version where it's fixes, that would be great.

Otherwise, can this be turned into a test case I might be able to run? All the OWL and specifics of the data are unlikely to be related.

        Andy



*private**static*String /assetFN/= "assetcore.owl";

*private**static*String /locoFN/= "locomotive.owl";

*private**static*String /evolutionFN/= "evolution.owl";

*private**static*String /es44c4FN/= "es44c4.owl";

...

Dataset ds = *null*;

File tdbDir = *new*File(/tdbFolder/);

*if*(!tdbDir.exists()) {

ds = TDBFactory./createDataset/(/tdbFolder/);

ds.addNamedModel(/assetUri/, loadModel(/blueprintsFolder/+
File./separator/+ /assetFN/));

ds.addNamedModel(/locoUri/, loadModel(/blueprintsFolder/+
File./separator/+ /locoFN/));

ds.addNamedModel(/evolutionUri/, loadModel(/blueprintsFolder/+
File./separator/+ /evolutionFN/));

ds.addNamedModel(/es44c4Uri/, loadModel(/blueprintsFolder/+
File./separator/+ /es44c4FN/));

}

*else*{

ds = TDBFactory./createDataset/(/tdbFolder/);

}

Iterator<String> mniter = ds.listNames();

*while*(mniter.hasNext()) {

System./out/.println("TDB repository contains model '"+ mniter.next() +
"'");

}

ds.close();

When I run it the first time it works as I expected, listing the four
OWL models that I have added to the repository. However, if I run it a
second time, now that the tdbFolder exists, I get a null pointer
exception in the call to mniter.hasNext(). The Dataset (ds) created from
an existing TDB folder doesn’t appear to be a valid Dataset. Am I doing
something wrong?

The loadModel method is as follows:

*private*OntModel loadModel(String owlFilename) *throws*IOException {

OntModel model = ModelFactory./createOntologyModel/(OntModelSpec./OWL_MEM/);

OntDocumentManager docMgr = model.getDocumentManager();

docMgr.setProcessImports(*false*); // we don't want to do the import
yet, just load the model

File modelFile = *new*File(owlFilename);

InputStream is = *new*FileInputStream(modelFile);

BufferedReader in = *new*BufferedReader(*new*InputStreamReader(is));

String base = *null*;

RDFReader reader = model.getReader();

reader.read(model, is, base);

in.close();

*return*model;

}

*Andrew Crapo*
Information Scientist
GE Global Research

T +1 518 387 5729
F +1 518 387 6104
D *833 5729
E cr...@research.ge.com
www.research.ge.com

One Research Circle
Niskayuna, NY 12309 USA
General Electric Company

GE imagination at work


Reply via email to