[redland-dev] Limited optional parameters in SPARQL?

Phil Archer phil.archer at icra.org
Mon Apr 18 16:03:25 BST 2005


Dear all,

My first post to this list so a (very) brief introduction. The organisation 
I work for, ICRA, is working with others on creating a successor to the PICS 
system for labelling content (largely for child protection purposes). The 
basic method of using RDF is now pretty well tied down and we're working on 
some tools to read the new labels which will use Redland.

With this in mind I've been using the online demo of RASQL to run some 
tests. The schema and method we're using allows an RDF node to have a 
variety of properties, all of which are optional. My question arises from 
the fact that I get different answers depending on the length of the query.

Given the data source: http://www.icra.org/test/rdftests/labels11.rdf I 
offer 2 versions of the same query:

PREFIX label: <http://www.w3.org/2004/12/q/contentlabel#>
SELECT ?uri ?action ?label ?classification ?management ?frequent ?several
?occasional ?single
WHERE
  (?x rdf:type label:Ruleset)
  (?x label:rules ?o1)
  (?o1 rdf:first ?node)
  OPTIONAL (?node label:hasURI ?uri)
  OPTIONAL (?node rdf:type ?action)
  OPTIONAL (?node label:hasLabel ?label)

If I run this I get the expected result:

1  \.jpg$ http://www.w3.org/2004/12/q/contentlabel#intersectionOf
http://www.icra.org/test/rdftests/labels11.rdf#label_2

 2 nude http://www.w3.org/2004/12/q/contentlabel#intersectionOf
http://www.icra.org/test/rdftests/labels11.rdf#label_2

(plus a load of empty variables because I declared more than there is data 
for).

The full query is this:

PREFIX label: <http://www.w3.org/2004/12/q/contentlabel#>
SELECT ?uri ?action ?label ?classification ?management ?frequent ?several 
?occasional ?single
WHERE
  (?x rdf:type label:Ruleset)
  (?x label:rules ?o1)
  (?o1 rdf:first ?node)
  OPTIONAL (?node label:hasURI ?uri)
  OPTIONAL (?node rdf:type ?action)
  OPTIONAL (?node label:hasLabel ?label)
  OPTIONAL (?node label:hasManagementInfo ?management)
  OPTIONAL (?node label:hasClassification ?classification)
  OPTIONAL (?node label:hasFrequentScenes ?frequent)
  OPTIONAL (?node label:hasSeveralScenes ?several)
  OPTIONAL (?node label:hasOccasionalScenes ?occasional)
  OPTIONAL (?node label:hasSingleScene ?single)

If I run this, I get a single result of

1 nude http://www.w3.org/2004/12/q/contentlabel#intersectionOf
http://www.icra.org/test/rdftests/labels11.rdf#label_2

Hmmm...  OK, so I play around and I find that I can remove _any_ of the 
OPTIONAL lines after (?node label:hasLabel :label) and get the expected 
result (i.e. both if the bindings that are present).

At first I thought it might be because the demo front end on librdf was just 
that, a demo, but, we've now built Redland into a little application that 
downloads the RDF instance and runs the query locally. We get a similar 
problem there (including error messages about running out of memory) but the 
essential point remains - more than a certain number of optional items in 
the query produces incomplete results.

Is there a limit on the number of OPTIONAL items that can be in a query?

If so, is this something that is in the SPARQL spec (I can't find it) or in 
Redland? If it's in Redland is it deliberate or a bug?

Phil. 



More information about the redland-dev mailing list