BNF for SquishQL

This was originally generated using javacc and jjdoc. I've made some alterations to make it more readable. Here are some example queries.

The query language is similar to and based on R. V. Guha's RDFDB QL


CompilationUnit ::= Query <EOF>
Query ::= SelectClause ( FromClause )? TriplePatternClause ( ConstraintClause )? ( UsingClause )?
SelectClause ::= 'SELECT' VarList
FromClause ::= 'FROM' UriList
TriplePatternClause ::= 'WHERE' TriplePatternList
ConstraintClause ::= 'AND' ConstraintList
UsingClause ::= 'USING' ( ForList )+
TriplePatternList ::= TriplePattern ( TriplePattern )*
TriplePattern ::= '(' VarOrLiteral VarOrLiteral VarOrLiteral ')'
VarOrLiteral ::= Var
| Literal
Var ::= '?' Identifier
VarList ::= Var ( ( ',' )? Var )*
UriList ::= UriLiteral ( ( "," )? UriLiteral )*
ConstraintList ::= Expression ( 'AND' Expression )*
ForList ::= Identifier 'FOR' UriLiteral
Expression ::= Var SomeFunction
SomeFunction ::= ( NumExpression | StringExpression )+
NumExpression ::= ( '>' | '<' | '==' | '=' | '!=' | '<=' | '>=' ) NumericLiteral
StringExpression ::= ( 'like' | 'ne' | 'eq' | '~' ) Literal
Literal ::= TextLiteral
| UriLiteral
| NumericLiteral
NumericLiteral ::= An integer
| A floating point number
UriLiteral ::= A letter followed by none or more letters, numbers or other characters allowed in RFC 2396
TextLiteral ::= One or more letters or numbers enclosed in inverted commas
Identifier ::= A letter followed by optional numbers and letters.

Examples

These are examples from my SquishQL testcases

select ?dd, ?date, ?x, ?val, ?mb 
 from  file:rdf/000068.rdf 
 where 
  (dc:description ?x ?dd) 
  (dc:date ?x ?date) 
  (foaf:location ?x ?l) 
  (rdf:value ?l ?val) 
  (foaf:depiction ?per ?x) 
  (foaf:mbox ?per ?mb) 
 using dc for http://purl.org/dc/elements/1.1/ 
 foaf for http://xmlns.com/foaf/0.1/ 
 rdf for http://www.w3.org/1999/02/22-rdf-syntax-ns# 

SELECT ?signer, ?signerMail, ?signee, ?signeeMail, ?hex  
FROM 
 file:rdf/danbri.wot.rdf 
WHERE 
 (wot:identity ?pk ?id) 
 (foaf:name ?id ?signee) 
 (foaf:mbox ?id ?signeeMail) 
 (wot:signed ?id ?e) 
 (foaf:name ?e ?signer) 
 (foaf:mbox ?e ?signerMail) 
 (wot:signerLongHexID ?e ?hex) 
 USING wot FOR http://xmlns.com/wot/0.1/ 
 foaf FOR http://xmlns.com/foaf/0.1/ 

select ?link 
from 
file:rdf/events.xml 
where 
 (http://purl.org/rss/1.0/items
http://chewbacca.ilrt.bris.ac.uk/events/events.xml ?seq) 
 (?anything ?seq ?link) 

SELECT  ?month, ?name, ?wp, ?dnum, ?doc 
FROM 
http://fireball.danbri.org/~libby/_esw_projdata.rdf 
WHERE 
  (rdf:type ?doc pm::DeliverableSpec) 
  (pm:name ?doc ?name) 
  (pm:number ?doc ?dnum) 
  (pm:description ?doc ?desc) 
  (pm:workpackage ?doc ?wp) 
  (pm:mainStartDate ?doc ?st) 
  (pm:relMonthDue ?doc ?due) 
USING pm for http://www.w3.org/2002/02/esw/pm# 
rdf for http://www.w3.org/1999/02/22-rdf-syntax-ns#

SELECT ?sal, ?t, ?x 
 FROM 
 file:rdf/jobs.rss 
 WHERE  
   (job:advertises ?x ?y) 
   (job:salary ?y ?sal) 
   (job:title ?y ?t) 
 USING job for  http://ilrt.org/discovery/2000/11/rss-query/jobvocab.rdf# 

SELECT ?sal, ?t, ?x 
 FROM  
 file:rdf/jobs-rss.rdf, file:rdf/jobs.rss 
 WHERE  
  (job:advertises ?x ?y)  
  (job:salary ?y ?sal) 
  (job:title ?y ?t)  
USING job for http://ilrt.org/discovery/2000/11/rss-query/jobvocab.rdf# 

select ?dd, ?date, ?x, ?mb  from 
 file:rdf/000068.rdf 
 where 
  (dc:description ?x ?dd) 
  (dc:date ?x ?date) 
  (foaf:depiction ?per ?x) 
  (foaf:mbox ?per ?mb) 
 and ?mb ne 'mailto:love26@gorge.net' 
 using dc for http://purl.org/dc/elements/1.1/ 
 foaf for http://xmlns.com/foaf/0.1/ 

select ?dd, ?date, ?x, ?mb  
 from 
 file:rdf/000068.rdf 
 where 
   (dc:description ?x ?dd) 
   (dc:date ?x ?date) 
   (foaf:depiction ?per ?x) 
   (foaf:mbox ?per ?mb) 
 and ?mb eq "mailto:love26@gorge.net" 
 using dc for http://purl.org/dc/elements/1.1/ 
 foaf for http://xmlns.com/foaf/0.1/ 

select ?dd, ?date, ?x, ?mb  from 
 file:rdf/000068.rdf 
 where
  (dc:description ?x ?dd) 
  (dc:date ?x ?date) 
  (foaf:depiction ?per ?x) 
  (foaf:mbox ?per ?mb) 
 and ?mb like 'mailto:love26@gorge.net' 
 using dc for http://purl.org/dc/elements/1.1/ 
 foaf for http://xmlns.com/foaf/0.1/ 

select ?dd, ?date, ?x, ?mb  from 
 file:rdf/000068.rdf 
 where 
  (dc:description ?x ?dd) 
  (dc:date ?x ?date) 
  (foaf:depiction ?per ?x) 
  (foaf:mbox ?per ?mb) 
 and ?mb ~ 'mailto:love26@gorge.net' 
 using dc for http://purl.org/dc/elements/1.1/ 
 foaf for http://xmlns.com/foaf/0.1/ 

select ?dd, ?date, ?x, ?mb  from 
 file:rdf/000068.rdf 
 where 
  (dc:description ?x ?dd) 
  (dc:date ?x ?date) 
  (foaf:depiction ?per ?x)
  (foaf:mbox ?per ?mb) 
 and ?mb = 'mailto:love26@gorge.net' 
 using dc for http://purl.org/dc/elements/1.1/ 
 foaf for http://xmlns.com/foaf/0.1/ 

SELECT ?sal, ?t, ?x 
 FROM 
 file:rdf/jobs-rss.rdf, 
 file:rdf/jobs.rss 
 WHERE 
   (job:advertises ?x ?y) 
   (job:salary ?y ?sal) 
   (job:title ?y ?t) 
  USING job for  http://ilrt.org/discovery/2000/11/rss-query/jobvocab.rdf# 

SELECT ?sal, ?t, ?x 
 FROM 
 file:rdf/jobs-rss.rdf,                                       
 file:rdf/jobs.rss
 WHERE 
  (job:advertises ?x ?y) 
  (job:salary ?y ?sal) 
  (job:title ?y ?t) 
 and ?sal != 60000 
 USING job for  http://ilrt.org/discovery/2000/11/rss-query/jobvocab.rdf# 

SELECT ?sal, ?t, ?x  FROM 
 file:rdf/jobs-rss.rdf,                                       
 file:rdf/jobs.rss
 WHERE  
  (job:advertises ?x ?y) 
  (job:salary ?y ?sal) 
  (job:title ?y ?t) 
 and ?sal > 60000 
 USING job for  http://ilrt.org/discovery/2000/11/rss-query/jobvocab.rdf# 

SELECT ?sal, ?t, ?x 
  FROM 
 file:rdf/jobs-rss.rdf,                                       
 file:rdf/jobs.rss
 WHERE 
  (job:advertises ?x ?y) 
  (job:salary ?y ?sal) 
  (job:title ?y ?t) 
 and ?sal >= 60000 
 USING job for  http://ilrt.org/discovery/2000/11/rss-query/jobvocab.rdf# 

SELECT ?sal, ?t, ?x  FROM 
 file:rdf/jobs-rss.rdf,                                       
 file:rdf/jobs.rss
 WHERE 
   (job:advertises ?x ?y) 
   (job:salary ?y ?sal) 
   (job:title ?y ?t) 
 and ?sal < 60000 
 USING job for  http://ilrt.org/discovery/2000/11/rss-query/jobvocab.rdf# 

SELECT ?sal, ?t, ?x 
 FROM 
 file:rdf/jobs-rss.rdf,                                       
 file:rdf/jobs.rss
 WHERE 
   (job:advertises ?x ?y) 
   (job:salary ?y ?sal) 
   (job:title ?y ?t) 
 and ?sal <= 60000 
 USING job for http://ilrt.org/discovery/2000/11/rss-query/jobvocab.rdf# 

SELECT ?sal, ?t, ?x 
 FROM 
 file:rdf/jobs-rss.rdf,                                       
 file:rdf/jobs.rss
 WHERE 
  (job:advertises ?x ?y)  
  (job:salary ?y ?sal) 
  (job:title ?y ?t) 
 and ?sal = 60000 
 USING job for http://ilrt.org/discovery/2000/11/rss-query/jobvocab.rdf# 

SELECT ?sal, ?t, ?x 
 FROM 
 file:rdf/jobs-rss.rdf,                                       
 file:rdf/jobs.rss
 WHERE 
  (job:advertises ?x ?y) 
  (job:salary ?y ?sal) 
  (job:title ?y ?t) 
 and ?sal == 60000 
 USING job for http://ilrt.org/discovery/2000/11/rss-query/jobvocab.rdf# 

SELECT ?sal, ?t, ?x 
 FROM 
 file:rdf/jobs-rss.rdf,                                       
 file:rdf/jobs.rss
 WHERE 
  (job:advertises ?x ?y) 
  (job:salary ?y ?sal) 
  (job:title ?y ?t) 
 and ?sal > 60000 
 and ?t ~ "2" 
 USING job for  http://ilrt.org/discovery/2000/11/rss-query/jobvocab.rdf# 

select ?dd, ?date, ?x, ?val, ?mb 
 from  file:rdf/000068.rdf 
 where
 (dc:description ?x ?dd) 
 (dc:date ?x ?date) 
 (foaf:location ?x ?l) 
 (rdf:value ?l ?val) 
 (foaf:depiction ?per ?x) 
 (foaf:mbox ?per ?mb) 
 using dc for http://purl.org/dc/elements/1.1/ 
 foaf for http://xmlns.com/foaf/0.1/ 
 rdf for http://www.w3.org/1999/02/22-rdf-syntax-ns# 

select ?dd, ?date, ?x, ?val, ?mb 
 from 
 file:rdf/000068.rdf 
 where
 (dc:madeup ?x ?dd) 
 (dc:date ?x ?date) 
 (foaf:location ?x ?z) 
 (rdf:value ?l ?val) 
 (foaf:depiction ?per ?x) 
 (foaf:mbox ?per ?mb) 
 using dc for http://purl.org/dc/elements/1.1/ 
 foaf for http://xmlns.com/foaf/0.1/ 
 rdf for http://www.w3.org/1999/02/22-rdf-syntax-ns#

select ?dd, ?mb 
 from 
 file:rdf/000068.rdf 
 where
 (dc:description http://swordfish.rdfweb.org/photos/2001/04/23/000068.JPG ?dd) 
 (foaf:depiction ?per http://swordfish.rdfweb.org/photos/2001/04/23/000068.JPG) 
 (foaf:mbox ?per ?mb) 
 using dc for http://purl.org/dc/elements/1.1/ 
 foaf for http://xmlns.com/foaf/0.1/ 
 rdf for http://www.w3.org/1999/02/22-rdf-syntax-ns# 

select ?pred, ?dd 
 from 
 file:rdf/000068.rdf 
 where 
 (?pred http://swordfish.rdfweb.org/photos/2001/04/23/000068.JPG ?dd) 
 using dc for http://purl.org/dc/elements/1.1/ 
 foaf for http://xmlns.com/foaf/0.1/ 
 rdf for http://www.w3.org/1999/02/22-rdf-syntax-ns#

 SELECT ?desc, ?hourstart, ?minstart, ?dend, ?hourend, ?minend FROM 
 file:rdf/cal2.rdf  
 WHERE 
  (foaf:mbox ?person mailto:libby.miller@bristol.ac.uk)  
  (ical:attendee ?event ?person) 
  (ical:description ?event ?desc) 
  (ical:dstart ?event ?date) 
  (rdfs:label ?date ?q) 
  (ical:hour ?date ?hourstart) 
  (ical:minute ?date ?minstart) 
  (ical:dtend ?event ?bla) 
  (rdfs:label ?bla ?dend) 
  (ical:hour ?bla ?hourend) 
  (ical:minute ?bla ?minend)  
 AND ?q ~ '2001-01-11'  
 USING ical FOR http://www.ietf.org/rfc/rfc2445.txt# 
 foaf FOR http://xmlns.com/foaf/0.1/ 
 rdfs FOR http://www.w3.org/2000/01/rdf-schema# 

 SELECT ?desc, ?hourstart, ?minstart, ?dend, ?hourend, ?minend, ?q FROM 
 file:rdf/cal2.rdf  
 WHERE 
  (foaf:mbox ?person mailto:libby.miller@bristol.ac.uk)  
  (ical:attendee ?event ?person) 
  (ical:description ?event ?desc) 
  (ical:dstart ?event ?date) 
  (rdfs:label ?date ?q) 
  (ical:hour ?date ?hourstart) 
  (ical:minute ?date ?minstart) 
  (ical:dtend ?event ?bla) 
  (rdfs:label ?bla ?dend) 
  (ical:hour ?bla ?hourend) 
  (ical:minute ?bla ?minend)  
 AND ?q ~ '2001-01-11'  
 USING ical FOR http://www.ietf.org/rfc/rfc2445.txt# 
 foaf FOR http://xmlns.com/foaf/0.1/ 
 rdfs FOR http://www.w3.org/2000/01/rdf-schema# 

SELECT ?y, ?x 
 FROM 
 file:rdf/jobs-rss.rdf 
 WHERE  
   (job:title ?y ?x) 
 and ?x eq 'Job title for job1 goes here' 
 USING job for  http://ilrt.org/discovery/2000/11/rss-query/jobvocab.rdf# 

SELECT ?y 
 FROM 
 file:rdf/jobs-rss.rdf 
 WHERE  
   (job:title ?y 'Job title for job1 goes here') 
 USING job for  http://ilrt.org/discovery/2000/11/rss-query/jobvocab.rdf# 


libby.miller@bristol.ac.uk
2002-07-09