Project:SPARQL/examples: Difference between revisions

Line 2,749: Line 2,749:
}
}
ORDER BY ?residenceLabel
ORDER BY ?residenceLabel
</sparql>
=== Locations that don't have Wikidata links or their Wikidata pages lack geocoordinates===
<sparql tryit="1">
PREFIX bnwd: <https://beyond-notability.wikibase.cloud/entity/>
PREFIX bnwds: <https://beyond-notability.wikibase.cloud/entity/statement/>
PREFIX bnwdv: <https://beyond-notability.wikibase.cloud/value/>
PREFIX bnwdt: <https://beyond-notability.wikibase.cloud/prop/direct/>
PREFIX bnp: <https://beyond-notability.wikibase.cloud/prop/>
PREFIX bnps: <https://beyond-notability.wikibase.cloud/prop/statement/>
PREFIX bnpq: <https://beyond-notability.wikibase.cloud/prop/qualifier/>
SELECT distinct ?residenceLabel ?residence ?wikidata ?geo ?instance ?instanceLabel ?bn_geo
WHERE { 
 
  {?item bnwdt:P29  ?residence . } # resided at
  union
  {?residence bnwdt:P12 bnwd:Q2147 .} # OR has instance of locality
  # this may miss a few places that lack instance of locality and aren't residences...
 
  optional { ?residence bnwdt:P12 ?instance .  } # check instance of
 
  optional {   
      ?residence bnp:P117 ?ws .  # does it have a wikidata id       
        ?ws bnpq:P14 ?wikidata_url .
        BIND(IRI(REPLACE(?wikidata_url, "https://www.wikidata.org/wiki/", "http://www.wikidata.org/entity/")) as ?wikidata )
        SERVICE <https://query.wikidata.org/sparql> {
          optional {?wikidata wdt:P625 ?geo .}  # does the wikidata page have geocoords?
        } # /wikidata service 
    } #/wikidata optional
 
  filter (!bound(?geo) ). # no geocoords in wikidata. some may have coords in BN...
 
  optional { ?residence bnwdt:P153 ?bn_geo .  } # check for coords in BN
  ##filter (!bound(?bn_geo)) . # uncomment to filter those out as well
 
  SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en,en-gb". }
}
ORDER BY ?wikidata_url ?residenceLabel
</sparql>
</sparql>


579

edits