Project:SPARQL/examples: Difference between revisions

Line 1,719: Line 1,719:
WHERE {   
WHERE {   
   ?item bnwdt:P12 bnwd:Q2961 .
   ?item bnwdt:P12 bnwd:Q2961 .
    
   {
   ?item bnwdt:P2  ?location .  # item has property P2 location
   ?item bnwdt:P2  ?location .  # item has property P2 location
    
    
Line 1,740: Line 1,740:
         } # /wikidata service     
         } # /wikidata service     
   }
   }
  }
  union
  {
 
  filter not exists {?item bnwdt:P2  ?location . } # item doesn't have property P2 location
  ?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