-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathgnd_wikidata_wikipedia.rq
81 lines (81 loc) · 2.78 KB
/
gnd_wikidata_wikipedia.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
# All GND authors mapped to Wikidata, with Wikipedia pages
#
# (to be executed against econ_corp endpoint)
#
PREFIX bd: <http://www.bigdata.com/rdf#>
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
PREFIX schema: <http://schema.org/>
PREFIX skos: <http://www.w3.org/2004/02/skos/core#>
PREFIX wdt: <http://www.wikidata.org/prop/direct/>
PREFIX wikibase: <http://wikiba.se/ontology#>
PREFIX dcterms: <http://purl.org/dc/terms/>
PREFIX wd: <http://www.wikidata.org/entity/>
#
select distinct ?gnd (?gndId as ?gndLabel) ?wd ?wdLabel
?wikipediaEn ?wikipediaEnLabel ?wikipediaDe ?wikipediaDeLabel ?allLanguages
where {
{
select distinct ?gndId
where {
?gnd skos:prefLabel [] .
bind(strafter(str(?gnd), 'http://d-nb.info/gnd/') as ?gndId)
}
}
#
service <https://query.wikidata.org/bigdata/namespace/wdq/sparql> {
select ?gndId ?wd ?wdLabel
(max(?wpEnStr) as ?wpEnUrl) (str(max(?wpEnName)) as ?wikipediaEnLabel)
(max(?wpDeStr) as ?wpDeUrl) (str(max(?wpDeName)) as ?wikipediaDeLabel)
?allLanguages
where {
# aggregate all language tags
{
select ?gndId ?wd ?wdLabel
(concat('[', group_concat(distinct ?langTag;
separator = '] ['), ']') as ?allLanguages)
where {
select ?gndId ?wd ?langTag
where {
# VALUES clause with language does not work as expected
#
# get all wikidata items and labels linked to gnd
?wd wdt:P227 ?gndId ;
wdt:P31 wd:Q5 .
# get all wikipedia site links
optional {
?wpPage schema:about ?wd ;
schema:name ?pageName ;
schema:inLanguage ?langTag .
filter (contains(str(?wpPage), 'wikipedia'))
}
}
order by ?gndId ?langTag
}
group by ?gndId ?wd ?wdLabel
}
# get some label
service wikibase:label {
bd:serviceParam wikibase:language 'en, de, fr, pt, nb, cs, ja' .
}
#
# expose English and German Wikipedia pages
# (url as string, for the max() function
optional {
?wpPage schema:about ?wd ;
schema:name ?pageName ;
schema:inLanguage ?langTag .
filter (contains(str(?wpPage), 'wikipedia'))
filter(?langTag in ('de', 'en'))
}
bind(if(?langTag = 'de', str(?wpPage), '') as ?wpDeStr)
bind(if(?langTag = 'de', ?pageName, '') as ?wpDeName)
bind(if(?langTag = 'en', str(?wpPage), '') as ?wpEnStr)
bind(if(?langTag = 'en', ?pageName, '') as ?wpEnName)
}
group by ?gndId ?wd ?wdLabel ?allLanguages
}
bind(uri(?wpEnUrl) as ?wikipediaEn)
bind(uri(?wpDeUrl) as ?wikipediaDe)
bind(uri(concat('http://d-nb.info/gnd/', $gndId)) as ?gnd)
}
order by ?gndLabel