Project:SPARQL/examples: Difference between revisions

From Beyond Notability
Line 1,391: Line 1,391:
   FILTER NOT EXISTS {?person bnwdt:P4 bnwd:Q12 .} #filter out project team
   FILTER NOT EXISTS {?person bnwdt:P4 bnwd:Q12 .} #filter out project team
   ?person bnwdt:P29 ?residence . # select residences
   ?person bnwdt:P29 ?residence . # select residences
   ?residence bnwdt:P33 ?district . #select districts
 
   ?district bnwdt:P33 ?county . #select counties
   ?residence bnwdt:P33 ?district . #select p33 of residence
      optional { ?county bnwdt:P153 ?geo2 .  } # for geocoords added to BN
   ?district bnwdt:P33 ?next . #select p33 of district, mostly counties but a few region/outside uk
    
    
       optional {     
  optional {
    # is ?next a uk region?
    ?next bnwdt:P12 bnwd:Q4207 .
    BIND(BOUND(?next) AS ?region).
    }
  optional {
    # is ?next in the UK?
    ?next bnwdt:P33* bnwd:Q1741 .
    BIND(BOUND(?next) AS ?uk).
    }
 
  # if next=q4207 uk region, then use ?district for county, ifelse in uk use ?next, else not in uk use ?district.
  bind(
       if( bound(?region), ?district, # region first (because also uk)
        if( bound(?uk), ?next, # then rest of uk 
      ?district)) # then anything not in uk.
    as ?county).
 
    optional { ?county bnwdt:P153 ?geo2 .  } # for geocoords added to BN
 
    optional {     
       ?county bnp:P117 ?ws .  # wikidata id P117         
       ?county bnp:P117 ?ws .  # wikidata id P117         
         ?ws bnpq:P14 ?wikidata_url .
         ?ws bnpq:P14 ?wikidata_url .