Path Variables

 

 

 

Hi

As a preparation for talking about path variables, the below shows how
Virtuoso SQL/SPARQL can return whole paths as result set columns.


select "path", xmlelement ('path', xmlagg (xmlelement ('step', "o"))) from 
(sparql select ?o ?via ?dist ?path where
  {
    {select ?s ?o
      where {?s foaf:knows ?o
        }} option (transitive, t_distinct, t_in(?s), t_out(?o), t_min (1),
t_max (4), t_step ('step_no') as ?dist, t_step ("path_id") as ?path, t_step
(?s) as ?via) .
    filter (?s= <http://myopenlink.net/dataspace/person/kidehen#this>)
  } order by ?dist ) paths group by "path" ;


Applied to live data, this gives results like:
185
<path><step>http://www.dajobe.org/foaf.rdf#i</step><step>nodeID://b1551785</
step></path>

...
2016
<path><step>http://inamidst.com/sbp/foaf#Sean</step><step>http://tommorris.o
rg/foaf#me</step><step>nodeID://b13151365</step></path>
...



The syntax is complex but it allows doing almost anything with transitive
things.
Here we have combined SQL and SPARQL just because SPARQL does not know
xmlagg, the standard SQLX XML aggregate implemented by most RDBMS's.

The innermost subquery returns all paths of length 1 to 4 starting with
kidehen, one row per step.  The distinct steps and paths ar differentiated
by the path id and step number for which a variable is specified in the
transitive clause.
These are then used for sorting and grouping so as to return XML fragments,
one per path, with the steps inside.
 
The path variable syntax referenced in the path length feature request could
be easily macroexpanded into a use of this feature.  The path variable
suggestion is shorter for the cases it covers.  Having a path as an object
in SPARQL would however entail some sort of structured data type support.
XML would be our choice, since we already have it from SQL and it has all
the related W3C specs to import into SPARQL.  Whether WG consensus can be
reached on something as big is another question.

 

The Virtuoso 6 documentation about  transitivity for SQL and SPARQL is at:

 

http://linkeddata.uriburner.com/home/iv_an_ru/Public/rdfsparqlrule.html

and

http://linkeddata.uriburner.com/home/iv_an_ru/Public/transitivityinsQL.html

 

 

It is prerelease, so not on the official docs site.

Orri

 

 

 

 

 

 

 

 

 

 

 

 

 

 

Received on Tuesday, 17 March 2009 13:36:45 UTC