-
Notifications
You must be signed in to change notification settings - Fork 173
VirtualGraphs
Virtual graphs offer a means to address large numbers of graphs in the
default graph or named graphs of a query. A predicate used to model the
membership of a virtual graph. The following assertions declare the
membership of a virtual graph as the graphs (:g1,:g2)
.
:vg bd:virtualGraph :g1
:vg bd:virtualGraph :g2
Virtual graphs are addressed through a SPARQL syntax extension:
FROM VIRTUAL GRAPH
FROM NAMED VIRTUAL GRAPH
If :vg
as declared above is addressed using FROM VIRTUAL GRAPH
then
its member graphs (:g1,:g2)
are added to the default graph for the
query.
For example, the following two SPARQL clauses have identical semantics.
They both identify a default graph composed of the two graphs
(:g1,:g2)
.
FROM :g1
FROM :g2
and
FROM VIRTUAL GRAPH :vg
If :vg
as declared above is addressed using FROM NAMED VIRTUAL GRAPH
then its member graphs (:g1,:g2)
are added to the named graphs for the
query.
For example, the following two SPARQL clauses have identical semantics.
They both identify a collection of named graphs composed of the two
graphs (:g1,:g2)
.
FROM NAMED :g1
FROM NAMED :g2
and
FROM NAMED VIRTUAL GRAPH :vg
Query:
prefix : <http://bigdata.com/>
SELECT ?s ?p
FROM VIRTUAL GRAPH :vg
WHERE {
?s ?p :mary
}
Data: Note that the data includes the virtual graph membership declarations in :xx. Those declarations can be in any graph, or even spread across more than one graph.
@prefix : <http://bigdata.com/> .
:c1 {
:john :loves :mary .
}
:c2 {
:mary :loves :paul .
}
:c4 {
:paul :loves :sam .
}
:xx {
:vg bd:virtualGraph :c1 .
:vg bd:virtualGraph :c2 .
}
Solutions:
<?xml version="1.0"?>
<sparql
xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
xmlns:xs="http://www.w3.org/2001/XMLSchema#"
xmlns="http://www.w3.org/2005/sparql-results#" >
<head>
<variable name="s"/>
<variable name="p"/>
</head>
<results>
<result>
<binding name="s">
<uri>http://bigdata.com/john</uri>
</binding>
<binding name="p">
<uri>http://bigdata.com/loves</uri>
</binding>
</result>
</results>
</sparql>