On 18/02/14 00:35, Brad Moran wrote:
Hi,

I am loading data into a TDB as named graphs via command line tdbloader utility 
with unionDefaultGraph flag specified true for example:

        tdbloader —set http://jena.hpl.hp.com/TDB#unionDefaultGraph=true 
—loc=TDBLocation —graph=‘graphName1’ rdfFile.ttl
        tdbloader —set http://jena.hpl.hp.com/TDB#unioncDefaultGraph=true 
—loc=TDBLocation —graph=‘graphName2’ rdfFile2.ttl

Then I can successfully query to get everything from the union graph with the 
following SPARQL:
        “SELECT ?s ?p ?o ?g WHERE{ GRAPH ?g{ ?s ?p ?o} }"

But now I want to query for data from just one of the named graphs. From the 
SPARQL tutorial in Jena documentation I tried:

        “SELECT ?s ?p ?o FROM NAMED <graphName1> WHERE{ GRAPH <graphName1> {?s 
?p ?o} }”

However, it returns 0 results.

I also tried:

        “SELECT ?s ?p ?o FROM NAMED <graphName1> WHERE{ ?s ?p ?o }”

and

        “SELECT ?s ?p ?o WHERE{ GRAPH <graphName1> {?s ?p ?o} }”

and

        “SELECT ?s ?p ?o ?g FROM NAMED <graphName1> WHERE{ GRAPH ?g {?s ?p ?o} 
}”

But none of the queries produce any results. I am wondering if maybe setting 
the flag unionDefaultGraph to true is incorrect for my purpose? I want to be 
able to query all graphs at once, but also be able to query individual named 
graphs.

Thanks,
Brad

This is not related to unionDefaultGraph.

When the SPARQL parser sees

SELECT * FROM NAMED <graphName1> WHERE{ GRAPH ?g {?s ?p ?o} }

then <graphName1> will be resolved against the base URI. There is always a base URI but if you don't specify it it is something unhelpful like the file: URI of the current directory.

The loader, seeing —graph="graphName1", isn't going near a parser so that is the URI and it is not resolved. The URI is just "graphName1" and does not match <graphName1>

Example:
Printing queries respects implicit the base URI so it get turned back into <g> but the algebra printing does not

qparse --print=op 'SELECT * { GRAPH <g> { ?s ?p ?o } }'

which gives, for me:

(graph <file:///home/afs/g>
  (bgp (triple ?s ?p ?o)))

<g> ==> <file:///home/afs/g>


Use an absolute URI for the graph name in tdbloader operation and a prefix in the query to make the GRAPH .. look nice.

        Andy

Reply via email to