Reputation: 189
I'm trying to query a Jena named model that I previously stored (precisely DBPedia TBox). Storage is done in the following way
Dataset dataset = TDBFactory.createDataset(path);
dataset.begin(ReadWrite.WRITE);
Model model = dataset.getNamedModel(graph);
OntModel ontModel = ModelFactory.createOntologyModel();
model.add(FileManager.get().readModel(ontModel, dbpedia));
model.commit();
model.close();
dataset.commit();
dataset.end();
dataset.close();
path contains the path to TDB, graph contains the name of the named model and dbpedia contains the path to the OWL file. Until this point everything seems fine:
When I later want to query the model, I do the following:
Dataset dataset = TDBFactory.createDataset(path);
dataset.begin(ReadWrite.READ);
List<String> out = Lists.newArrayList();
try(QueryExecution qExec = QueryExecutionFactory.create("SELECT * { GRAPH ?g {?s ?p ?o}}", dataset.getNamedModel(graph))) {
ResultSet rs = qExec.execSelect();
ResultSetFormatter.out(rs);
rs.forEachRemaining(triple -> out.add(triple.toString()));
} catch (Exception e) {
e.printStackTrace();
}
dataset.close();
The output from ResultSetFormatter.out(rs)
is empty, as follows:
-----------------
| s | p | o | g |
=================
-----------------
However, in debugger mode, I can clearly see that the property dataset
from dataset.getNamedModel(graph)
clearly has data there.
I assume then that my problem is the query, but that seems fine to me. Am I missing something?
Thanks!
Upvotes: 0
Views: 291
Reputation: 16630
QueryExecutionFactory.create("SELECT * { GRAPH ?g {?s ?p ?o}}", dataset.getNamedModel(graph)))
That asks the query on the graph in isolation. Graphs do not have names - their slot in the dataset has the name.
Querying just a model is querying the default graph of the dataset (that gets created internally to make the query execution).
Try QueryExecutionFactory.create("SELECT * { GRAPH ?g {?s ?p ?o}}", dataset)
Upvotes: 1