Change - Named Graph

Created on Feb. 23, 2013, 11:33 a.m. by Hevok & updated on Feb. 23, 2013, 11:35 a.m. by Hevok

In SPARQL one can selected Graph Patterns from more than one Graph. Therefore one need to distinguish in SPARQL the first (the default) Graphs that all formulated Patterns will be asked for and one can in the same SPARQL Query refer to other Graphs. These other Graphs (zero or more) are so called RDF named Graphs. So one has named Graphs that can be explicitly addressed within a Query and one has default Graphs that will be addressed whenever no named Graph is addressed in that way. For this one has the Graph keyword. ¶

Assuming one has several from Statements, the normal FROM Statements form the default Graph. Each specified Graph Pattern that is not bound to a specific Pattern belongs to the default Graph and the Query will be carried out against the default Graph. Named Graphs are indicated with the FROM NAMED followed by the Graph URI. The same Graphs can be in the Default Graph as well as in special Named Graphs for the specific parts that occur in the WHERE Clause. Everything in the WHERE Clause where there is not a specific Graph Pattern is specified will be checked against the Default Graph. Everything that is specified via the GRAPH keyword will queried against the defined Named Graph. ¶

For instance in a default graph with two triples of individuals that are characterized by two files that are two URIs. The URIs stands for Named Graphs. In the example the query selects a Graph, a mail box and who belongs to the mailbox. In the WHERE Clause it asks for the graph ad the name of the publisher. Then the GRAPH keyword specifies that the next Graph referring to where x is the mail box and mbox the name of the mailbox. Therefore, a Named Graph can also be a Variable will be computed from the evaluation of the Triples before from the default Graph. Then in the execution the Variable will be substituted by a value that has been computed when evaluated the Graph Triple Pattern from the default Graph. ¶

SPARQL queries are executed over an RDF Dataset ¶
- one (or more) default RDF graph(s) ¶
- zero or more named RDF graphs ¶
Named Graphs can explicitly addressed via keyword GRAPH and the URI of the Named Graph

GRAPH <http://example.org/graph1.rdf>] { ¶
?x foaf:mbox ?mbox ¶
} ¶

PREFIX denigma: ... ¶
SELECT ... ¶
FROM denigma:g1 ¶
FROM denigma:g4 ¶
FROM NAMED denigma:g1 ¶
FROM NAMED denigma:g2 ¶
FROM NAMED denigma:g3 ¶
WHERE { ¶
... A ... ¶
GRAPH denigma:g3 { ¶
... B ... ¶
} ¶
GRAPH ?g { ¶
... C ... ¶
} ¶
} ¶

* Example of Named Graphs ¶

- Default Graph (stored at http://example.org/dtf.ttl) ¶

@prefix dc: <http://purl.org/dc/elements/1.1/>] . ¶

<http://example.org/hevok>] dc:publisher "Hevok" . ¶
<http://example.org/eva>] dc:publisher "EVA" . ¶

- Named Graph (stored at http://example.org/hevok) ¶

@prefix foaf: <http://xmlns.com/foaf/0.1/>] . ¶

:a foaf:name "Hevok" . ¶
:a foaf:mbox <mailto:hevok@oldcorp.example.org> . ¶

- Named Graph (store at http://example.org/hevok) ¶

@prefix foaf: <http://xmlns.com/foaf/0.1/>] . ¶

:a foaf:name "EVA" ¶
:a foaf:mbox <mailto: eva@work.example.org> ¶

- Query

PREFIX foaf: <http://xmlns.com/foaf/0.1/>] ¶
PREFIX dc: <http://purl.org/dc/elements/1.1/>] ¶

SELECT ?g ?mbox ?who ¶
FROM <http://example.org/dft.ttl>] ¶
FROM NAMED <http://example.org/hevok>] ¶
FROM NAMED <http://example.org/eva>] ¶
WHERE ¶
{ ¶
?g dc:publisher ?who . ¶
GRAPH ?g { ?x foaf:mbox ?mbox } ¶
}


Comment: Corrected code blocks.

Comment on This Data Unit