Search code examples
sparqlrdfdbpedia

Test for absence of a pattern returns triples that match it


Why the first result of this query is matching both tests for absence while the values appear on the page?

#Leaders of Member states of the EU for which there is no value for gender or depiction in DBpedia

SELECT DISTINCT ?leader_No_gender ?leader_No_image

WHERE { 
?MS a dbo:Country; dct:subject <http://dbpedia.org/resource/Category:Member_states_of_the_European_Union>. 

{?MS dbo:leader ?leader_No_gender . 
FILTER NOT EXISTS {?leader_No_gender foaf:gender ?gender}
} 

UNION 

{?MS dbo:leader ?leader_No_image . 
FILTER NOT EXISTS {?leader_No_image foaf:depiction ?image}
} 
}

Solution

  • The property path-based queries suggested by @AKSW work on the latest Virtuoso Enterprise Edition (08.03.3312) as hosts DBpedia-Live. (Of course, these results are different than you'll find on the static DBpedia, still based on the 2016-10 dataset, and still running on Virtuoso 07.20.3230 which does still have the property path bug.)

    PREFIX dbo: <http://dbpedia.org/ontology/>
    PREFIX dct: <http://purl.org/dc/terms/>
    
    SELECT DISTINCT 
      ?leader_No_gender 
      ?leader_No_image
    
    WHERE 
      { 
        ?MS a           dbo:Country ; 
            dct:subject <http://dbpedia.org/resource/Category:Member_states_of_the_European_Union> . 
    
        { ?MS dbo:leader ?leader_No_gender . 
          FILTER NOT EXISTS { ?leader_No_gender dbo:wikiPageRedirects?/foaf:gender ?gender }
        } 
    
        UNION
    
        { ?MS dbo:leader ?leader_No_image . 
          FILTER NOT EXISTS { ?leader_No_image dbo:wikiPageRedirects?/foaf:depiction ?image }
        }
      }