From: Seaborne, A. <and...@hp...> - 2006-01-26 09:58:26
|
John Vandenberg wrote: > Hi, > > I am trying to select a set of data out of a Mozilla extension > install.rdf file. I am using SPARQL because it will be easy for > developers to pick up and learn. > > My problem is that when an optional entry doesnt exist (iconURL), none > of the fields are returned. This is the query I was trying to > perform. > > SELECT ?version, ?name, ?description, ?creator, ?icon > WHERE (?x, <em:version>, ?version), > (?x, <em:name>, ?name), > (?x, <em:description>, ?description), > (?x, <em:creator>, ?creator), > (?x, <em:iconURL>, ?icon) > USING em FOR <http://www.mozilla.org/2004/em-rdf#> > > To work around this, I am individually selecting each optional piece > of data. Can this be improved on? > > -- > John That syntax is RDQL not SPARQL. That query exactly translated is: PREFIX em: <http://www.mozilla.org/2004/em-rdf#> SELECT ?version ?name ?description ?creator ?icon WHERE { ?x em:version ?version ; em:name ?name ; em:description ?description ; em:creator ?creator ; em:iconURL ?icon . } (Mechanical translation by program - but not a PHP program :-() and adding optional for iconURL: PREFIX em: <http://www.mozilla.org/2004/em-rdf#> SELECT ?version ?name ?description ?creator ?icon WHERE { ?x em:version ?version . ?x em:name ?name . ?x em:description ?description . ?x em:creator ?creator . OPTIONAL { ?x em:iconURL ?icon . } } a little more neatly that is: PREFIX em: <http://www.mozilla.org/2004/em-rdf#> SELECT ?version ?name ?description ?creator ?icon WHERE { ?x em:version ?version ; em:name ?name ; em:description ?description ; em:creator ?creator . OPTIONAL { ?x em:iconURL ?icon .} } Hope that helps, Andy |