forked from zbw/sparql-queries
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpm20_geocode_exact_single_violation.rq
48 lines (46 loc) · 1.57 KB
/
pm20_geocode_exact_single_violation.rq
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# Single value constraint violations (multiple exact matches from an item)
#
PREFIX p: <http://www.wikidata.org/prop/>
PREFIX pq: <http://www.wikidata.org/prop/qualifier/>
PREFIX ps: <http://www.wikidata.org/prop/statement/>
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
PREFIX skos: <http://www.w3.org/2004/02/skos/core#>
PREFIX wd: <http://www.wikidata.org/entity/>
PREFIX wdt: <http://www.wikidata.org/prop/direct/>
#
select distinct ?wd ?wdLabel ?relation ?relationLabel
where {
service <https://query.wikidata.org/bigdata/namespace/wdq/sparql> {
select ?wd ?wdLabel ?relation ?relationLabel ?geoCode
where {
# identify items with multiple PM20 geo code values
{
select distinct ?wd (count(?geoCode) as ?geoCount)
where {
# statements on property PM20 geo code
?wd p:P8483 ?statement .
# mapping relation exact match
?statement pq:P4390 wd:Q39893449 ;
ps:P8483 ?geoCode .
}
group by ?wd
having (?geoCount > 1)
}
# expand to all existing PM20 geo codes and relations for the item
?wd wdt:P8483 ?geoCode .
filter(isLiteral(?geoCode))
?wd p:P8483/pq:P4390 ?relation .
#
# get label for the wd item, if exists
optional {
?wd rdfs:label ?label .
filter(lang(?label) = 'en')
bind(str(?label) as ?wdLabel)
}
?relation rdfs:label ?relationLabelLang .
filter(lang(?relationLabelLang) = 'en')
bind(str(?relationLabelLang) as ?relationLabel)
}
}
}
order by desc(?relation) ?wdLabel