The following examples demonstrate querying paths in nested graphs. This investigates the issue that Olaf raised in his formalization. The good news is that the issue seems under control. The bad news is it seems that it's not as easy as hoped for to query over multiple (nested) graphs. It's not hard - always the same pattern, e.g. in the second example below { graph nng:embeddings { ?root nng:transcludes* ?what . } }
- but it's not pretty either. To make it nicer requires an addition to SPARQL, and we haven't got a prototype for that yet.
:Z {
:Y {
:X {
:Dog :eats :Fish .
THIS :says :Alice ;
nng:domain [ :name "Dodger" ]
} :says :Bob ;
:believes :Ben .
:Goat :has :Ideas .
:Beatrice :claims [] {" :Jake :knows :Larry .
:Larry a :Star . "} .
} :says :Carol ;
:believes :Curt ;
nng:tree :Example .
} :says :Zarathustra ,
:source :Source_1 .
Note
The fragment identifier
nng:tree
is not implemented yet. Its purpose is to annotate a graph and all nested graphs recursively.
In the following some example queries are given, together with different versions of expected results and the respective query. A complete documentation of Dydra's implementation of the queries and their results plus some comments is available in the query shell script.
Prefix declarations are always
prefix : <http://example.org/>
prefix nng: <http://nested-named-graph.org/>
prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#>
Expected results are:
> :Alice # give me only the result(s) from the THIS level
> :Alice :Bob :Carol :Zarathustra # give me results on all levels of nesting
> :Alice :Bob # give me results from the first n=2 levels of nesting
# nesting level count starts inside a graph
# (to account e.g. for self references like THIS)
For the complete example see query shell script line 39 ff.
Respective queries are:
select ?who
from included nng:NestedGraph
where {
{ :Dog :eats :Fish . } :says ?who .
}
See query shell script line 87 ff.
select ?orator
from named all
where {
{ graph ?what { :Dog :eats :Fish . } }
{ graph nng:embeddings { ?root nng:transcludes* ?what . } }
{ graph ?venue { ?root :says ?orator } }
}
See query shell script starting from line 106, in particular 167 ff.
nesting level count starts with THIS
select ?what ?root ?orator
from named all
where {
{ graph ?what { :Dog :eats :Fish . } }
{ graph nng:embeddings { ?root nng:transcludes{0,1} ?what . } }
{ graph ?root { ?about :says ?orator } }
}
See query shell script line 185 ff.
Expected results are:
> # give me only the result(s) from the THIS level
> :Ben :Curt # give me results on all levels of nesting
> :Ben # give me results from the first n=2 levels of nesting
# nesting level count starts with THIS
For the complete example see query shell script line 206 ff.
Respective queries are:
[TODO]
select ?orator
from named all
where {
{ graph ?what { :Dog :eats :Fish . } }
{ graph nng:embeddings { ?root nng:transcludes* ?what . } }
{ graph ?venue { ?root :believes ?orator } }
}
See query shell script line 215 ff.
nesting level count starts with THIS
select ?orator
from included nng:NestedGraph
where {
{ graph ?what { :Dog :eats :Fish . } }
{ graph ?venue { ?what :believes ?orator } }
}
See query shell script line 248 ff.
Expected results are:
> # give me only results annotated with THIS
> :Y # give me only the nearest graph
> :Y :Z # give me all enclosing graphs (Olaf's case 3)
# BUT not the DEFAULT graph, because :Z is not nested
# in the default graph
For the complete example see query shell script line 266 ff.
Respective queries are:
select ?what
where {
{ graph ?what { :Goat :has ?o . ?what ?annotated ?with} }
}
See query shell script line 276 ff.
select ?what
where {
{ graph ?what { :Goat :has ?o . } }
}
See query shell script line 290 ff.
select distinct ?what ?root
where {
{ graph ?what { :Goat :has ?o . } }
{ graph nng:embeddings { ?root nng:transcludes* ?what . } }
}
See query shell script line 304 ff.
Expected results are:
> :Y
Respective queries are:
[TODO]
Expected results are:
> :Y :X _:Report1 # _:Report1 referring to Beatrice' claim
Respective queries are:
[TODO]
Expected results are:
> :Example _:b1 # the value space of fragment identifiers nng:domain
# and nng:tree is interpreted as class
# _:b1 refers to the dog named "Dodger"
Respective queries are:
[TODO]
> :Example, :Star
Respective queries are:
[TODO]