Project:SPARQL/examples: Difference between revisions

From Beyond Notability
Line 2,282: Line 2,282:
group by ?wd_io ?wd_io_label
group by ?wd_io ?wd_io_label
order by ?wd_io_label
order by ?wd_io_label
</sparql>
=== Localities not in the UK ===
<sparql tryit="1">
##admin_paths lists the linked P33 for the item. Unfortunately, they aren't reliably returned in ascending order.
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/>
#title:localities not in the UK
select  ?item ?itemLabel (group_concat(distinct ?admin_label; separator=", " ) as ?admin_path)
where {
  ?item bnwdt:P12 bnwd:Q2147 . # i/o locality
  ?item bnwdt:P33* ?admin.   
    ?admin rdfs:label ?admin_label. filter(lang(?admin_label)="en") .
 
  filter not exists { ?item bnwdt:P33* bnwd:Q1741.  } # filter out anything in the UK
  filter (?item not in (bnwd:Q619, bnwd:Q2961, bnwd:Q4207, bnwd:Q86) ). # and a few things that are not specific places
  SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en,en-gb". }
}
group by ?item ?itemLabel
order by ?itemLabel
</sparql>
</sparql>