Discussion:
Problems with SPARQL and named graphs
Andy Seaborne
2016-12-21 16:07:59 UTC
Permalink
szQuery = "" + " PREFIX dc: <http://purl.org/dc/elements/1.1/>" + "
PREFIX foaf: <http://xmlns.com/foaf/0.1/>" + " SELECT ?graph ?who ?mbox"
+ " FROM NAMED <http://example.org/alice>" + " FROM NAMED
<http://example.org/bob>" + " WHERE " + " { \n" + " ?graph dc:publisher
?who . " + " GRAPH ?graph { ?x foaf:mbox ?mbox . } " + " }";
Take out the FROM NAMED.
Adding FROM or FROM NAMED creates a view of the original data - in this
case with just 2 named graphs. You don't want a view - you want the
real thing.
Andy
But then, how can I define to search only in some graphs? I was planning
to have more than two in total, and only search on some of them.
There are various ways

1/ Use FROM <urn:x-arq:DefaultGraph> to include the default graph in
the view dataset.

2/ Make a union model and query that.

3/ Use GRAPH <g> in a query (when it is just one graph)

4/ Use GRAPH ?g {} FILTER( ... ?g ....) in a query (when it is just one
graph)

(They are not exactly equivalent. )

The details of the usage will suggest a particular approach as will the
total volume of data.

Andy
See you
Jorge
Andy Seaborne
2016-12-22 11:48:02 UTC
Permalink
Post by Andy Seaborne
szQuery = "" + " PREFIX dc: <http://purl.org/dc/elements/1.1/>" + "
PREFIX foaf: <http://xmlns.com/foaf/0.1/>" + " SELECT ?graph ?who ?mbox"
+ " FROM NAMED <http://example.org/alice>" + " FROM NAMED
<http://example.org/bob>" + " WHERE " + " { \n" + " ?graph dc:publisher
?who . " + " GRAPH ?graph { ?x foaf:mbox ?mbox . } " + " }";
Take out the FROM NAMED.
Adding FROM or FROM NAMED creates a view of the original data - in this
case with just 2 named graphs. You don't want a view - you want the
real thing.
Andy
But then, how can I define to search only in some graphs? I was planning
to have more than two in total, and only search on some of them.
There are various ways
1/ Use FROM <urn:x-arq:DefaultGraph> to include the default graph in
the view dataset.
Thanks a lot for that one. I didn't know how to access the default graph
in a SPARQL sentence.
Post by Andy Seaborne
2/ Make a union model and query that.
3/ Use GRAPH <g> in a query (when it is just one graph)
4/ Use GRAPH ?g {} FILTER( ... ?g ....) in a query (when it is just one
graph)
(They are not exactly equivalent. )
The details of the usage will suggest a particular approach as will the
total volume of data.
Bluff :-)
is it better to have many named graphs and
restrict queries to them or a union of some o them, or would it be
better to have just only one big graph?
I think the answer is quite straight ;) but just for curiosity.
You said on the other thread that you have thousands of triples - it
probably makes no difference. Better to be driven by how you manage the
data.

By the way, copying graphs is not as bad as it might appear. Only the
graph structure of built; the triples themselves aren't copied but
shared. Triples are immutable values - no need to duplicate.

Andy
Regards
Jorge
Post by Andy Seaborne
Andy
See you
Jorge
Loading...