Project:SPARQL/examples: Difference between revisions

Line 594: Line 594:
}
}


ORDER BY ?personLabel ?s
</sparql>
=== Women's service: information about "of" qualifier, including alternatives for locations===
<sparql tryit="1">
#title: query for served on "of" info
# where a women served on committee *of* organisation, need to link to info about the organisation, including location.
# geo data for the location may be in its BN page but is more likely to need to be fetched from wikidata
# todo: check whether there are orgs that don't have location info in BN but do have it in wikidata
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 ?serviceLabel ?of ?ofLabel ?of_location ?of_locationLabel ?of_geo ?of_long ?of_lat ?person ?s
WHERE { 
  ?person bnwdt:P3 bnwd:Q3 . # select women
  FILTER NOT EXISTS {?person bnwdt:P4 bnwd:Q12 .}
 
  ?person  bnp:P102 ?s . 
    ?s bnps:P102 ?service .
    ?s bnpq:P78 ?of .
 
      #optional { ?of bnwdt:P117 ?of_wikidata.  }  #todo
      optional { ?of bnwdt:P2 ?of_location.
                  optional { ?of_location bnwdt:P153 ?bn_of_geo . }
                  optional { ?of_location bnwdt:P117 ?wd_of_loc .
                            bind(iri(concat("http://www.wikidata.org/entity/", str(?wd_of_loc))) as ?wd_of_loc_url) .
                           
                            SERVICE <https://query.wikidata.org/sparql> {
                              optional {?wd_of_loc_url wdt:P625 ?wd_of_geo .}  # wikidata geocoords
                            } # /wikidata service 
                          } #/optional location wikidata
              } #/optional P2 location.
      BIND(COALESCE(?bn_of_geo, ?wd_of_geo) AS ?of_geo).  # if we have bn_geo use that, then try wd_geo
 
                BIND(geof:longitude(?of_geo) AS ?of_long)
                BIND(geof:latitude(?of_geo)  AS ?of_lat)
 
  SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en-gb, en". }
}
ORDER BY ?personLabel ?s
ORDER BY ?personLabel ?s
</sparql>
</sparql>
579

edits