RE: RDF query testcase requirements: IRC chat?

Libby wrote:
> The main issue for me is how to express the query itself.
> My inclination is to try and express queries as graphs with parts missing,
that > is, to interpret an RDF graph as a query, as Jos de Roo suggested
[5].
> 
> I think this would give us one big win, which is that we could ignore the
> syntactic differences between several very similar query languages for RDF
> (although this will by no means encompass all RDF query languages). Plus
of
> course, we get the query parser for free.

Following on from Jos's message[1], I wrote the query in cwm/N3 and captured
the result set bindings as RDF.  (The result set vocabulary is given at [2]
and is unfinished.)  Encoding the result set in RDF does have the feature
that we can merge it with the testcase RDF and annotate it.  Use in a real
application is more limited as the application is going to have to process
the output graph again when (as Geoff notes) it wants the SELECT variables
or it wanted the matching subgraph, in which case the application is going
to substitute the bindings back into the query.

Using the example taken from Jos's message: (all files are attached for
convenience and in case this email gets reformatted):

Data set:
data.n3 ---------------------------------
@prefix : <http://example.com/> .
:a :b :c.
:d :c :f.
:g :c :i.
-----------------------------------------

Encoded for cwm:
query.n3 --------------------------------
@prefix rs:   <http://somewhere/2003/01/result-set-vocab#> .
@prefix ex: <http://example.com/> .

{ ?x ex:b ?u .
  ?y ?u [] . }
    =>
{
  <> rs:hasSolution
     [
         rs:hasBinding [ rs:variable "u" ; rs:value ?u ] ;
         rs:hasBinding [ rs:variable "y" ; rs:value ?y ]
     ]
} .
-----------------------------------------

which uses a bNode [] for a "don't care" slot in the triple pattern (was
?z).  The output is a series of variable bindings for ?u and ?y (?x is not
selected - could be replaced by another []) according to the result set
vocabulary.  We give the template for one row of the result table; multiple
occurences of this get generated by the formula matching several times. The
RDF produced encodes a result set - a number of solutions, provided by the
bindings.  The RDF produced is a bit rough-and-ready as it does not record
the data source or some other details in the vocabulary.

So running the query with cwm (cwm 1.126)
  cwm data.n3 -filter=query.n3 > result-set
and then tidying the results into

result-set-tidy ------------------------
@prefix rs: <http://somewhere/2003/01/result-set-vocab#> . @prefix ex:
<http://example.com/> .

<query.n3>
  rs:hasSolution  [
      rs:hasBinding  [ rs:value ex:c; rs:variable "u" ] ;
      rs:hasBinding  [ rs:value ex:g; rs:variable "y" ]
                  ] ;
  rs:hasSolution  [
      rs:hasBinding  [ rs:value ex:c; rs:variable "u" ] ;
      rs:hasBinding  [ rs:value ex:d; rs:variable "y" ]
                  ]
  .
-----------------------------------------

which uses rs:variable to quote the variable.  Substituting this back into
the original query gives the ways the pattern matched the graph.  Merging
all these gives the smallest subgraph of the original graph that generates
the same answers.

To check the tidying: compare the two graphs with:
  jena.rdfcompare result-set result-set-tidy N3 N3
gives
  models are equal (i.e. isomorphic structures)

For comparison: the RDQL query on data set data.n3:
    SELECT ?u ?y
    FROM <data.n3>
    WHERE (?x ex:b ?u) (?y ?u ?z)
    USING ex FOR <http://example.com/>
gives:

u                      | y
===============================================
<http://example.com/c> | <http://example.com/d>
<http://example.com/c> | <http://example.com/g>


    Andy



[1] http://lists.w3.org/Archives/Public/www-rdf-rules/2003Feb/0003.html
[2] http://lists.w3.org/Archives/Public/public-esw/2003Jan/0046.html

Received on Saturday, 15 February 2003 16:00:30 UTC