I am trying to query my newly created TDB database use the tdbquery program. However, I am having a hard time writing a query that targets the correct named graph. I am doing the following:
First a create a new dataset and add a name graph called "facts"
Dataset dataset = TDBFactory.createDataset("/tdb/");
dataset.begin(ReadWrite.WRITE) ;
try {
Model facts = RDFDataMgr.loadModel("lineitem.ttl") ;
dataset.addNamedModel("facts", facts);
dataset.commit();
TDB.sync(dataset);
dataset.end();
} finally {
dataset.close();
}
When I query all graphs in my TDB database it looks fine.
./tdbquery --loc /tdb/ "SELECT * { GRAPH ?g { ?s ?p ?o } }"
--------------------------------------------------
| s | p | o | g |
==================================================
| <fact1> | <predicate> | <nation> | <facts> |
| <fact2> | <predicate> | <region> | <facts> |
--------------------------------------------------
If I try to query the named graph I do not find and triples.
./tdbquery -v --loc /tdb/ "SELECT * { GRAPH <facts> { ?s ?p ?o } }"
OR
./tdbquery -v --loc /tdb/ "SELECT * FROM NAMED <facts> WHERE { ?s ?p ?o }"
-------------
| s | p | o |
=============
-------------
When I look at the algebra version of the query I see that the context (the graph) in my quad is wrong.
INFO exec :: ALGEBRA
(quadpattern (quad <file:///usr/local/apache-jena-2.12.1/bin/facts> ?s ?p ?o))
I know that the quad pattern should be: (quad ?s ?p ?o)
How do I query a named graph in a TDB database?
Regards