forked from zbw/sparql-queries
-
Notifications
You must be signed in to change notification settings - Fork 0
/
pm20_company_country.rq
55 lines (54 loc) · 1.9 KB
/
pm20_company_country.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
47
48
49
50
51
52
53
54
# Get the country of the company seat
# (for multiple country items per country code, use that with the lowest item number)
#
PREFIX dc: <http://purl.org/dc/elements/1.1/>
PREFIX dct: <http://purl.org/dc/terms/>
PREFIX frapo: <http://purl.org/cerif/frapo/>
PREFIX hint: <http://www.bigdata.com/queryHints#>
PREFIX p: <http://www.wikidata.org/prop/>
PREFIX pq: <http://www.wikidata.org/prop/qualifier/>
PREFIX ps: <http://www.wikidata.org/prop/statement/>
PREFIX schema: <http://schema.org/>
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/>
PREFIX zbwext: <http://zbw.eu/namespaces/zbw-extensions/>
#
select ?pm20Id ?pm20 ?pm20Label ?qid ?countryCode (concat('Q', str( min(?geoId) )) as ?geoQid)
where {
hint:Query hint:optimizer "None" .
#
# all companies with country from PM20
service <https://zbw.eu/beta/sparql/pm20/query> {
?pm20 a zbwext:CompanyFolder ;
skos:prefLabel ?pm20Label ;
dct:identifier ?pm20Id ;
zbwext:totalDocCount ?docCount ;
frapo:hasCountryCode ?countryCode .
# WD part of the query hits timeout, therefore only use segments
##filter(?countryCode = 'NL')
##filter(?countryCode = 'GB')
##filter(?countryCode = 'DE')
##filter(?countryCode not in ( 'DE', 'GB', 'NL') )
}
# "main" items - exclude items linked with mapping relations
?statement ps:P4293 ?pm20Id .
?wd p:P4293 ?statement .
filter (not exists {
?statement pq:P4390 [] .
})
bind(strafter(str(?wd), str(wd:)) as ?qid)
#
# exclude items with already existing country
filter(not exists {
?wd wdt:P17 [] .
})
#
optional {
?geoWd wdt:P297 ?countryCode .
bind(xsd:integer(strafter(str(?geoWd), 'http://www.wikidata.org/entity/Q')) as ?geoId)
}
filter(bound(?geoId))
}
group by ?pm20Id ?pm20 ?pm20Label ?qid ?countryCode
order by ?pm20Id $geoId