[redland-dev] How does OPTIONAL work?

Benno Blumenthal benno at iri.columbia.edu
Mon Dec 19 13:12:45 GMT 2005


I too had trouble with OPTIONAL (wrote in detail to redland-dev serveral 
months ago) -- switched to JENA, and the same queries worked fine (and 
much faster).  Sesame-alpha also supports SPARQL, but I haven't got that 
working yet.

Benno

Marinaio di terra wrote:

>Hi all,
>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 datafile 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="http://www.example.org/toy-schema.rdf#"
>  xml:base="http://www.example.org/sample.rdf">
>
><toy:Toy rdf:ID="Ball">
>  <toy:name>BallName</toy:name>
></toy:Toy>
>
><toy:Toy rdf:ID="BigBall">
>  <toy:name>Big Ball Name</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:
>
>RDF.Query("PREFIX toy: <http://www.example.org/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>
>      <binding name="name"><literal>Big Ball</literal></binding>
>      <binding name="ver"><literal>2.0</literal></binding>
>    </result>
>    <result>
>      <binding name="name"><literal>BallName</literal></binding>
>      <binding name="ver"><unbound/></binding>
>    </result>
></results>
>
>
>But if the query is like this (i.e. I specify the subject of the triple):
>
>RDF.Query("PREFIX toy: <http://www.example.org/toy-schema.rdf#> " +
>          "SELECT ?name ?ver " +
>          "WHERE { <http://www.example.org/sample.rdf#Ball> toy:name ?name . " +
>          "OPTIONAL {<http://www.example.org/sample.rdf#Ball> toy:version ?ver} }",
>           query_language='sparql')
>
>I don't obtain anything:
><results>
></results>
>
>Is it a correct behavior (and why) or a bug in the library?
>
>Thanks a lot!
>
>Christian.
>
>_______________________________________________
>redland-dev mailing list
>redland-dev at lists.librdf.org
>http://lists.gnomehack.com/mailman/listinfo/redland-dev
>  
>



More information about the redland-dev mailing list