forked from zbw/sparql-queries
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpm20_mnm_search.rq
93 lines (89 loc) · 3.59 KB
/
pm20_mnm_search.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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
# Create list of search statements in parallel to Wikidata Mix'n'match catalog
# for PM20 companies (excluding entries which are already exactly linked)
#
PREFIX dct: <http://purl.org/dc/terms/>
PREFIX frapo: <http://purl.org/cerif/frapo/>
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 ?id ?pm20 (?name as ?pm20Label) ?wdSearch ("wd" as ?wdSearchLabel)
?wpSearch ("wp" as ?wpSearchLabel) ?qs ("qs" as ?qsLabel)
?item ('id' as ?itemLabel) ?description
where {
{
select ?pm20 ?id ?name ?docCount ?prefLabel ?fromTo
(group_concat(distinct ?location; separator = '; ') as ?locations)
(group_concat(distinct ?industry; separator='; ') as ?industries)
(group_concat(distinct ?note; separator='; ') as ?notes)
where {
values ( ?language ?filterLang ) {
( 'de' 'und' )
}
# query restricts result to folders with documents
?pm20 a zbwext:CompanyFolder ;
dct:identifier ?id ;
skos:prefLabel ?prefLabel ;
zbwext:adjustedLabel ?name ;
frapo:hasCountryCode ?country ;
zbwext:totalDocCount ?docCount .
#
# this is the filter for defining the separate mnm catalogs (parts)
bind(
if(?country in ('NL', 'ID', 'AO'), 'nl',
if(?country in ('GB', 'US', 'CA', 'AU', 'ZA', 'IE', 'MY', 'ZW'), 'en',
if(?country in ('FR', 'VN', 'BE', 'CD', 'LU', 'DZ'), 'fr',
if(?country in ('DE', 'AT', 'CH', 'HU', 'TZ', 'PL', 'CZ', 'WS'), 'de',
'und')))) as ?wikiLang)
##filter(?wikiLang = ?filterLang)
#
optional {
?pm20 zbwext:fromTo ?fromTo .
}
optional {
?pm20 schema:location ?location .
filter(lang(?location) = ?language)
}
optional {
?pm20 schema:industry ?industry .
filter(lang(?industry) = ?language)
}
optional {
?pm20 skos:note ?note .
}
}
group by ?pm20 ?id ?name ?docCount ?prefLabel ?fromTo
}
# exclude alreday exactly linked entries
optional {
service <https://query.wikidata.org/sparql> {
?wd p:P4293 ?statement .
?statement ps:P4293 ?id .
optional {
?statement pq:P4390 ?relType .
}
# let related matches pass
filter(!bound(?relType) || ?relType!=wd:Q39894604)
}
}
filter(!bound(?wd))
# info
bind(concat('{', str(?docCount), '} ', if(bound(?fromTo), concat(?fromTo, ', '), ''), if(bound(?locations), ?locations, ''),
' (', if(bound(?industries), ?industries, ''), '): ', $prefLabel, ' -. ', if(bound(?notes), ?notes, '')) as ?description)
# create search and qs links
bind(replace(replace(replace(?name, " ", "+"), "&", "%26"), "'", "%27") as ?name_enc)
bind(uri(concat("https://duckduckgo.com/?q=", ?name_enc, "+site:wikidata.org")) as ?wdSearch)
bind(uri(concat("https://startpage.com/search?q=", ?name_enc, "+site:wikipedia.org")) as ?wpSearch)
bind(uri(concat('https://zbw.eu/beta/tmp/pm20_qs_create.html#', replace(?id, "/", "_"))) as ?qs)
#
# link to existing items with this id
bind(uri(concat('http://zbw.eu/beta/sparql-lab/?endpoint=https://query.wikidata.org/sparql',
'&queryRef=https://api.github.com/repos/zbw/sparql-queries/contents/wikidata/item_by_pm20_id.rq',
'&pm20Id="', ?id, '"')) as ?item)
}
order by desc(?docCount) ?name