java - Jena TDB: Querying a named model -
i'm trying query jena named model stored (precisely dbpedia tbox). storage done in 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 path tdb, graph contains name of named model , dbpedia contains path owl file. until point seems fine:
when later want query model, 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 resultsetformatter.out(rs)
empty, follows:
----------------- | s | p | o | g | ================= -----------------
however, in debugger mode, can see property dataset
dataset.getnamedmodel(graph)
has data there.
i assume problem query, seems fine me. missing something?
thanks!
queryexecutionfactory.create("select * { graph ?g {?s ?p ?o}}", dataset.getnamedmodel(graph)))
that asks query on graph in isolation. graphs not have names - slot in dataset has name.
querying model querying default graph of dataset (that gets created internally make query execution).
try queryexecutionfactory.create("select * { graph ?g {?s ?p ?o}}", dataset)
Comments
Post a Comment