Project:SPARQL/examples: Difference between revisions

Line 1,617: Line 1,617:
WHERE {   
WHERE {   
   ?item bnwdt:P12 bnwd:Q38 .
   ?item bnwdt:P12 bnwd:Q38 .
  {
   ?item bnwdt:P2  ?location .  # item has property P2 location
   ?item bnwdt:P2  ?location .  # item has property P2 location
    
    
Line 1,635: Line 1,637:
             ?wikidata wdt:P625 ?wd_geo1 .   
             ?wikidata wdt:P625 ?wd_geo1 .   
         } # /wikidata service     
         } # /wikidata service     
    }
   }
   }
  union
  {
 
  filter not exists {?item bnwdt:P2  ?location . } # item doesn't have property P2 location
  optional {
  ?item bnwdt:P117 ?wikidata_id .  # but has wikidata id 
  bind(iri(concat("http://www.wikidata.org/entity/", str(?wikidata_id))) as ?wikidata) .
    
    
  SERVICE <https://query.wikidata.org/sparql> {
              ?wikidata wdt:P625 ?wd_geo1 . 
            } # /wikidata service   
    }
  }
   BIND(COALESCE(?wd_geo1, ?wd_geo2) AS ?wd_geo).  # if geo1 available use that, then try geo2
   BIND(COALESCE(?wd_geo1, ?wd_geo2) AS ?wd_geo).  # if geo1 available use that, then try geo2
    
    
579

edits