W3C home > Mailing lists > Public > public-rdf-dawg@w3.org > July to September 2007

Auto-generated SPARQL Algebra expressions for the algebra test suites

From: Chimezie Ogbuji <ogbujic@ccf.org>
Date: Tue, 10 Jul 2007 10:35:54 -0400
To: "public-rdf-dawg" <public-rdf-dawg@w3.org>
Message-ID: <1184078154.14454.13.camel@otherland>
Attached is a first shot at a script which serializes parsed SPARQL back
into Algebra expressions similar to the (informative) syntax used in the
specification.  I have only eyeballed it, but some caveats:

* It doesn't serialize FILTERs
* The parser breaks up triple patterns in a BGP into Joins against each
triple pattern

So:  BGP([(?s,?p,?o),(?s2,?p2,?o2)]
becomes: Join(BGP([(?s,?p,?o),]),BGP([(?s2,?p2,?o2)])

Otherwise, everything else should be okay.  I wanted to make sure this
is what we have in mind and that the expressions being generated are not
malformed before turning it loose on the entire test collection.

-- 
Chimezie Ogbuji
Lead Systems Analyst
Thoracic and Cardiovascular Surgery
Cleveland Clinic Foundation
9500 Euclid Avenue/ W26
Cleveland, Ohio 44195
Office: (216)444-8593
ogbujic@ccf.org


===================================




Cleveland Clinic is ranked one of the top 3 hospitals in
America by U.S.News & World Report. Visit us online at
http://www.clevelandclinic.org for a complete listing of
our services, staff and locations.


Confidentiality Note:  This message is intended for use
only by the individual or entity to which it is addressed
and may contain information that is privileged,
confidential, and exempt from disclosure under applicable
law.  If the reader of this message is not the intended
recipient or the employee or agent responsible for
delivering the message to the intended recipient, you are
hereby notified that any dissemination, distribution or
copying of this communication is strictly prohibited.  If
you have received this communication in error,  please
contact the sender immediately and destroy the material in
its entirety, whether electronic or hard copy.  Thank you.



## Filter-placement - 2 (data-r2/algebra/filter-placement-2.rq) ##
PREFIX : <http://example/>

SELECT ?v 
{ 
    FILTER (?v = 2)
    ?s :p ?v . 
}

Join(BGP(),BGP((?s, rdflib.URIRef('http://example/p'), ?v)))
##########################

## Filter-nested - 1 (data-r2/algebra/filter-nested-1.rq) ##
PREFIX : <http://example/> 

SELECT ?v
{ :x :p ?v . FILTER(?v = 1) }

BGP((rdflib.URIRef('http://example/x'), rdflib.URIRef('http://example/p'), ?v))
#######################

## Filter-placement - 3 (data-r2/algebra/filter-placement-3.rq) ##
PREFIX : <http://example/>

SELECT ?v ?w
{ 
    FILTER (?v = 2)
    FILTER (?w = 3)
    ?s :p ?v . 
    ?s :q ?w .
}

Join(Join(BGP(),BGP()),BGP((?s, rdflib.URIRef('http://example/p'), ?v),(?s, rdflib.URIRef('http://example/q'), ?w)))
##########################

## Filter-scope - 1 (data-r2/algebra/filter-scope-1.rq) ##
PREFIX :    <http://example/>

SELECT *
{ 
    :x :p ?v . 
    { :x :q ?w 
      OPTIONAL {  :x :p ?v2 FILTER(?v = 1) }
    }
}

BGP((rdflib.URIRef('http://example/x'), rdflib.URIRef('http://example/p'), ?v))
######################

## Optional-filter - scope of variable (data-r2/algebra/opt-filter-3.rq) ##
PREFIX :    <http://example/>

SELECT *
{ 
    :x :p ?v . 
    { :x :q ?w 
      # ?v is not in scope so ?v2 never set
      OPTIONAL {  :x :p ?v2 FILTER(?v = 1) }
    }
}

BGP((rdflib.URIRef('http://example/x'), rdflib.URIRef('http://example/p'), ?v))
#########################################

## Filter-placement - 1 (data-r2/algebra/filter-placement-1.rq) ##
PREFIX : <http://example/>

SELECT ?v 
{ 
    ?s :p ?v . 
    FILTER (?v = 2)
}

BGP((?s, rdflib.URIRef('http://example/p'), ?v))
##########################

## Optional-filter - 2 filters (data-r2/algebra/opt-filter-2.rq) ##
PREFIX :    <http://example/>

SELECT *
{ 
  ?x :p ?v .
  OPTIONAL
  { 
    ?y :q ?w .
    FILTER(?v=2)
    FILTER(?w=3)
  }
}

LeftJoin(BGP((?x, rdflib.URIRef('http://example/p'), ?v)),Join(BGP((?y, rdflib.URIRef('http://example/q'), ?w)),BGP()))
#################################

## Join scope - 1 (data-r2/algebra/var-scope-join-1.rq) ##
PREFIX : <http://example/>

SELECT *
{ 
  ?X  :name "paul"
  {?Y :name "george" . OPTIONAL { ?X :email ?Z } }
}


BGP((?X, rdflib.URIRef('http://example/name'), rdflib.Literal('paul', lang=None, datatype=None)))
####################

## Filter-nested - 2 (data-r2/algebra/filter-nested-2.rq) ##
PREFIX : <http://example/> 

SELECT ?v
{ :x :p ?v . { FILTER(?v = 1) } }

BGP((rdflib.URIRef('http://example/x'), rdflib.URIRef('http://example/p'), ?v))
#######################

## Nested Optionals - 2 (data-r2/algebra/two-nested-opt-alt.rq) ##
PREFIX :    <http://example/>

## The nested optional example, rewritten to a form that is the same
## for the SPARQL algebra and the declarative semantics.
SELECT *
{ 
    :x1 :p ?v .
    OPTIONAL { :x3 :q ?w }
    OPTIONAL { :x3 :q ?w  . :x2 :p ?v }
}

LeftJoin(LeftJoin(BGP((rdflib.URIRef('http://example/x1'), rdflib.URIRef('http://example/p'), ?v)),BGP((rdflib.URIRef('http://example/x3'), rdflib.URIRef('http://example/q'), ?w))),Join(BGP((rdflib.URIRef('http://example/x3'), rdflib.URIRef('http://example/q'), ?w)),BGP((rdflib.URIRef('http://example/x2'), rdflib.URIRef('http://example/p'), ?v))))
##########################

## Optional-filter - 1 (data-r2/algebra/opt-filter-1.rq) ##
PREFIX :    <http://example/>

SELECT *
{ 
  ?x :p ?v .
  OPTIONAL
  { 
    ?y :q ?w .
    FILTER(?v=2)
  }
}

LeftJoin(BGP((?x, rdflib.URIRef('http://example/p'), ?v)),BGP((?y, rdflib.URIRef('http://example/q'), ?w)))
#########################

## Nested Optionals - 1 (data-r2/algebra/two-nested-opt.rq) ##
PREFIX :    <http://example/>

SELECT *
{ 
    :x1 :p ?v .
    OPTIONAL
    {
      :x3 :q ?w .
      OPTIONAL { :x2 :p ?v }
    }
}

LeftJoin(BGP((rdflib.URIRef('http://example/x1'), rdflib.URIRef('http://example/p'), ?v)),LeftJoin(BGP((rdflib.URIRef('http://example/x3'), rdflib.URIRef('http://example/q'), ?w)),BGP((rdflib.URIRef('http://example/x2'), rdflib.URIRef('http://example/p'), ?v))))
##########################

Received on Tuesday, 10 July 2007 14:37:46 GMT

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