Project:SPARQL/examples: Difference between revisions

m
Line 2,762: Line 2,762:
PREFIX bnpq: <https://beyond-notability.wikibase.cloud/prop/qualifier/>
PREFIX bnpq: <https://beyond-notability.wikibase.cloud/prop/qualifier/>


SELECT distinct ?residenceLabel ?residence ?wikidata ?geo ?instance ?instanceLabel ?bn_geo
 
SELECT distinct ?locationLabel ?location ?wikidata ?wd_geo ?instanceLabel ?bn_geo
WHERE {   
WHERE {   
    
    
   {?item bnwdt:P29  ?residence . } # resided at
   {?item bnwdt:P29  ?location . } # resided at
   union
   union
   {?residence bnwdt:P12 bnwd:Q2147 .} # OR has instance of locality
   {?location bnwdt:P12 bnwd:Q2147 .} # OR has instance of locality
   # this may miss a few places that lack instance of locality and aren't residences...
  union
  {?item bnwdt:P2  ?location . } # OR location P2
   # any other possibles ?
    
    
   optional { ?residence bnwdt:P12 ?instance .  } # check instance of
   optional { ?location bnwdt:P12 ?instance .  } # check instance of
    
    
   optional {     
   optional {     
       ?residence bnp:P117 ?ws .  # does it have a wikidata id         
       ?location bnp:P117 ?ws .  # wikidata id         
         ?ws bnpq:P14 ?wikidata_url .  
         ?ws bnpq:P14 ?wikidata_url .  
         BIND(IRI(REPLACE(?wikidata_url, "https://www.wikidata.org/wiki/", "http://www.wikidata.org/entity/")) as ?wikidata )  
         BIND(IRI(REPLACE(?wikidata_url, "https://www.wikidata.org/wiki/", "http://www.wikidata.org/entity/")) as ?wikidata )  
         SERVICE <https://query.wikidata.org/sparql> {
         SERVICE <https://query.wikidata.org/sparql> {
           optional {?wikidata wdt:P625 ?geo .}  # does the wikidata page have geocoords?
           optional {?wikidata wdt:P625 ?wd_geo .}  # does the wikidata page have geocoords?
         } # /wikidata service   
         } # /wikidata service   
     } #/wikidata optional
     } #/wikidata optional
    
    
   filter (!bound(?geo) ). # no geocoords in wikidata. some may have coords in BN...
   filter (!bound(?wd_geo) ). # no geocoords in wikidata. some may have coords in BN...
    
    
   optional { ?residence bnwdt:P153 ?bn_geo .  } # check for coords in BN
   optional { ?location bnwdt:P153 ?bn_geo .  } # so check for coords in BN
   ##filter (!bound(?bn_geo)) . # uncomment to filter those out as well
   ##filter (!bound(?bn_geo)) . # uncomment to filter those out as well
    
    
   SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en,en-gb". }  
   SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en,en-gb". }  
}
}
ORDER BY ?wikidata_url ?residenceLabel
ORDER BY ?wikidata ?locationLabel
 
</sparql>
</sparql>


579

edits