Re: Using SPARQL CONSTRUCT with named graphs

On 18/12/2013 10:17, John Walker wrote:
> Hi There,
>
> A question was posed to me by a colleague if it is possible to use
> CONSTRUCT query to return results including named graphs.
>
> As far as I know this is not possible, but am happy to be shown otherwise.

You can only return plain ol' RDF through CONSTRUCT, but the RDF can 
contain data about named graphs. Assuming the correct graphs were 
selected, you could (for example) dump the entire SPARQL repository to 
reified RDF as:

PREFIX ...
CONSTRUCT {
    _:stmt rdf:subject ?s ;
         rdf:predicate ?p ;
         rdf:object ?o ;
         ex:graph ?g .
}
WHERE { GRAPH ?g {?s ?p ?o } }


You can apply the same pattern to more specific examples:

PREFIX ...
CONSTRUCT {
    _:knows ex:knower ?s ;
        ex:knowee ?o ;
        ex:graph ?g .
}
WHERE { GRAPH ?g {?s foaf:knows ?o } }

> One possible workaround I can think of is to create a new (empty)
> repository and from this repository do a SPARQL DELETE/INSERT query
> federating across to whatever SPARQL endpoint contains your data set
> using SERVICE keyword.
>
> Once the query is complete, one can then serialize the contents of the
> new repository in the quads format of your choice.
>
> Any other suggestions of how this could be done?

Hmm ... I'm not sure how SPARQL SERVICE/federation is relevant to the 
original question. :/ Could you clarify what exactly you would like to 
do? Is it that you want to serialise/deserialise named graphs across 
endpoints?

Best,
Aidan

Received on Wednesday, 18 December 2013 13:39:14 UTC