W3C home > Mailing lists > Public > public-rdf-dawg@w3.org > October to December 2004

Untrusted graphs - examples

From: Seaborne, Andy <andy.seaborne@hp.com>
Date: Tue, 07 Dec 2004 11:02:37 +0000
Message-ID: <41B58DCD.9030505@hp.com>
To: RDF Data Access Working Group <public-rdf-dawg@w3.org>

Some examples of untrusted graphs and queries.

Dataset:

=== Default graph
@prefix : <http://example.org/ns#> .
:aRoot :q :a .
=== untrusted graph a.n3
@prefix : <http://example.org/ns#> .
:a :b :c .
=== untrusted graph b.n3
@prefix : <http://example.org/ns#> .
:c :p :z .
----

That is, a query starting with:

FROM <dft.n3>
GRAPH <a.n3> <b.n3>


Note: there is a path a.n3/b.n3 via the :c node and a path default
graph/a.n3 via the node :a



Query 1: path of length 2:
SELECT *
WHERE
      ( ?x ?y ?z )
      ( ?z ?r ?s )

Results:
None.

There is no merge of a.n3 and b.n3 nor a.n3/b.n3 into the default graph so
there are no paths of length two to be found.

The FROM/GRAPH need not be included - the query context may define the dataset 
as would be the case in many query services over large data collections.

Query 2:
SELECT *
WHERE
    SOURCE ?src1 ( ?x ?y ?z )
    SOURCE ?src2 ( ?z ?r ?s )

Results:
--------------------------------------------------
| src1     | x      | y  | z  | src2   | r  | s  |
==================================================
| <a.n3>   | :a     | :b | :c | <b.n3> | :p | :z |
--------------------------------------------------
One path, involving a.n3 and b.n3.

The other path isn't found because the default graph isn't a named graph.


Query 3:
SELECT *
WHERE
    ( ?x ?y ?z )
    SOURCE ?src2 ( ?z ?r ?s )

Results:
---------------------------------------
| x      | y  | z  | src2   | r  | s  |
=======================================
| :aRoot | :q | :a | <a.n3> | :b | :c |
---------------------------------------

The first triple pattern accesses the default graph, not any of the named
(untrusted) graphs.  So there is one path, matching the first triple pattern
in the default graph and the second in <a.n3>

If the application does want paths involving the default graph and the
untrusted graphs, then a way to do it is to give the default graph a name as
an untrusted named graph as well:

Query 4:

FROM <dft.n3>
GRAPH <dft.n3> <a.n3> <b.n3>
SELECT *
WHERE
    SOURCE ?src1 ( ?x ?y ?z )
    SOURCE ?src2 ( ?z ?r ?s )

--------------------------------------------------
| src1     | x      | y  | z  | src2   | r  | s  |
==================================================
| <a.n3>   | :a     | :b | :c | <b.n3> | :p | :z |
| <dft.n3> | :aRoot | :q | :a | <a.n3> | :b | :c |
--------------------------------------------------

Query 5:
which is the same Q4 because no non-SOURCE matches were done.

GRAPH <dft.n3> <a.n3> <b.n3>
SELECT *
WHERE
    SOURCE ?src1 ( ?x ?y ?z )
    SOURCE ?src2 ( ?z ?r ?s )

[These results were semi-automatically created - I haven't modified my
parser but a one line change in the code causes graphs not to be merged
so I just used that feature with a "named" default graph like Q5 then
I had to tweak things to cover over the "named" default graph.]

	Andy
Received on Tuesday, 7 December 2004 11:03:02 GMT

This archive was generated by hypermail 2.3.1 : Tuesday, 26 March 2013 16:15:21 GMT