[redland-dev] How does OPTIONAL work?

Marinaio di terra marinaioditerra at gmail.com
Mon May 16 12:58:29 BST 2005


Hi all,
I'm a student working at my master thesis and I'm working on a project
based on Semantic Web technologies.
I'm using Python and the Redland-Python-binding, but I'm having some
troubles querying using the OPTIONAL parameter.

If I have a data file like this:

<?xml version="1.0"?>
<!DOCTYPE rdf:RDF [<!ENTITY xsd "http://www.w3.org/2001/XMLSchema#">]>
<rdf:RDF   
  xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"  
  xmlns:rdfs="http://www.w3.org/2000/01/rdf-schema#"
  xmlns:toy="file:./toy-schema.rdf#"
  xml:base="file:./sample.rdf">

<toy:Toy rdf:ID="Ball">
  <toy:name>Ball</toy:name>
</toy:Toy>

<toy:Toy rdf:ID="BigBall">
  <toy:name>Big Ball</toy:name>
  <toy:version>2.0</toy:version>
</toy:Toy>

</rdf:RDF>

and I query for the toys name and optionally their version with this:
q = RDF.Query("PREFIX toy: <file:./toy-schema.rdf#> " +
              "SELECT ?name ?ver " +
              "WHERE (?x toy:name ?name) " +
              "OPTIONAL (?x toy:version ?ver)",
              query_language='sparql')

I obtain the expected results:
<results>
    <result>
      <name>Ball</name>
      <ver bound="false"/>
    </result>
    <result>
      <name>Big Ball</name>
      <ver>2.0</ver>
    </result>
</results>

But if the query is like this:
q = RDF.Query("PREFIX toy: <file:./toy-schema.rdf#> " +
              "SELECT ?name ?ver " +
              "WHERE (<file:./sample.rdf#Ball> toy:name ?name) " +
              "OPTIONAL (<file:/sample.rdf#Ball> toy:version ?ver)",
              query_language='sparql')

I don't obtain anything:
<results>
</results>

Is it a correct behavior or a bug in the library?

Thanks a lot and sorry for my poor english...

Christian.



More information about the redland-dev mailing list