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?

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

Reply via email to