Incomplete support of SPARQL OPTIONAL in PHP frameworks
While working on the Knowledge Engineering Group community website, which is completely implemented on top of RDF-based repository, I faced an issue about incompatibility with SPARQL standard. We used the RDF API for PHP framework, which was so-called "standard" for PHP aplication handling any RDF. Let's describe the use case. We had a list of foaf:Group instances in the repository; some of them had one foaf:name property with value in English language, and some had two foaf:names, one in English, second in Czech langauge. We want to select both names using one query and present them in the XHTML form. The SPARQL select would be like this:
PREFIX foaf: <http://xmlns.com/foaf/0.1/> PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns# > SELECT ?group ?nameEn ?nameCs WHERE { ?group rdf:type foaf:Group . ?group foaf:name ?nameEn . OPTIONAL { ?group foaf:name ?nameCs . FILTER (lang(?nameCs) = "cs") } FILTER (lang(?nameEn) = "en") }
But, if we executed the query against the RAP database repository, we received incorrect result - it contained only resources having both names. I have been debugging the query for two hours but a friend of mine proved that the query is right. OpenLink Virtuoso service hosted on DBpedia selected the data correctly. Because the RAP project seems to be frozen, we have realized to move our code from RAP to ARC2 framework and expected to run this query and receive correct results. Unfortunately, moving the code to ARC did not solve our trouble. After re-running the script, we got different, but still incorrect results. This forced us to abandon Czech names to be implemented in our website for now and to search the source of trouble. A brief answer gave us W3C SPARQL Implementation Coverage report. RAP, nor ARC does not support OPTIONAL variables for 100%. In fact, from the most commonly used RDF frameworks only Jena and Sesame2 have complete support for SPARQL. We will use ARC in future development and hope the support for SPARQL will be completed one time...
