Hi Olga,
On 25-Jun-14 6:50 PM, Olga Medvedeva wrote:
Hi everyone,Does the location of OPTIONAL clause matters in SPAQRL query? Here are the examples of non-intersecting results on dbpedia:1. Without any OPTIONAL numNames = 2143 PREFIX dbprop: <http://dbpedia.org/property/> SELECT count(DISTINCT ?name) AS ?numNames WHERE { ?country rdf:type dbpedia-owl:Country . ?country dbprop:commonName ?name . } 2. OPTIONAL at the beginning returns numNames = 1922 PREFIX dbprop: <http://dbpedia.org/property/> SELECT count(DISTINCT ?name) AS ?numNames WHERE { OPTIONAL {?country dbpprop:yearEnd ?yearEnd} ?country rdf:type dbpedia-owl:Country . ?country dbprop:commonName ?name . }3. OPTIONAL at the end returns numNames = 2143 - same as in #1 (without OPTIONAL)PREFIX dbprop: <http://dbpedia.org/property/> SELECT count(DISTINCT ?name) AS ?numNames WHERE { ?country rdf:type dbpedia-owl:Country . ?country dbprop:commonName ?name . OPTIONAL {?country dbpprop:yearEnd ?yearEnd} }The difference is 221. And it's not equal to the number of not bounded ?yearEnd:4. OPTIONAL at the end with not bound filter returns numNames = 338 PREFIX dbprop: <http://dbpedia.org/property/> SELECT count(DISTINCT ?name) AS ?numNames WHERE { ?country rdf:type dbpedia-owl:Country . ?country dbprop:commonName ?name . OPTIONAL {?country dbpprop:yearEnd ?yearEnd} ## numNames = 2143 FILTER (!bound(?yearEnd)) }I thought that the position of OPTIONAL clause in query should not affect the result. Why the results are so different?
In general yes, position for OPTIONAL should not matter.However, in your case ( let's say we run the queries against dbpedia.org/sparql endpoint ), there is data for ?yearEnd having different datatypes: integer, and non integer -- ex:
-- integer: http://bit.ly/1lrGGHN -- not integer: -- http://bit.ly/1lZ3L67 -- ex. string: -- http://bit.ly/TAgOyl I would suggest you to specify the type of the ?yearEnd ex.: filter ( bif:isinteger (?yearEnd)) . # demo link: -- http://bit.ly/1qe8eUf PREFIX dbprop: <http://dbpedia.org/property/> SELECT count(DISTINCT(?name)) WHERE { ?country rdf:type dbpedia-owl:Country . ?country dbprop:commonName ?name . optional {?country dbpprop:yearEnd ?yearEnd }. filter ( bif:isinteger (?yearEnd)) . } limit 100 or # demo link: -- http://bit.ly/UMdpgS PREFIX dbprop: <http://dbpedia.org/property/> SELECT count(DISTINCT(?name)) WHERE { optional {?country dbpprop:yearEnd ?yearEnd }. ?country rdf:type dbpedia-owl:Country . ?country dbprop:commonName ?name . filter ( bif:isinteger (?yearEnd)) . } limit 100both of which result in same total of 1839 and in both of which the position in OPTIONAL is different.
Best Regards, Rumi Kocis
Thank you, Olga Medvedeva. ------------------------------------------------------------------------------ Open source business process management suite built on Java and Eclipse Turn processes into business applications with Bonita BPM Community Edition Quickly connect people, data, and systems into organized workflows Winner of BOSSIE, CODIE, OW2 and Gartner awards http://p.sf.net/sfu/Bonitasoft _______________________________________________ Virtuoso-users mailing list Virtuoso-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/virtuoso-users
smime.p7s
Description: S/MIME Cryptographic Signature
------------------------------------------------------------------------------ Open source business process management suite built on Java and Eclipse Turn processes into business applications with Bonita BPM Community Edition Quickly connect people, data, and systems into organized workflows Winner of BOSSIE, CODIE, OW2 and Gartner awards http://p.sf.net/sfu/Bonitasoft
_______________________________________________ Virtuoso-users mailing list Virtuoso-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/virtuoso-users