forked from zbw/sparql-queries
-
Notifications
You must be signed in to change notification settings - Fork 0
/
wikidata_mapping.rq
58 lines (57 loc) · 2.1 KB
/
wikidata_mapping.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
# Get all mappings from Wikidata to STW (with labels in German and English)
#
# needs to run from an endpoint holding the vocabulary of the external-id
# in order to get the labels
#
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 wdt: <http://www.wikidata.org/prop/direct/>
PREFIX wd: <http://www.wikidata.org/entity/>
#
select distinct ?wd ?wdLabel ?skosRelation ?stw ?stwLabel
where {
service <https://query.wikidata.org/bigdata/namespace/wdq/sparql> {
# wd items with STW ID
## CAUTION: the following line does not retrive multiple qualified statements
## ?wd wdt:P3911 ?stwId .
?wd p:P3911 ?statement .
?statement ps:P3911 ?stwId .
filter(isLiteral(?stwId))
#
# mapping relation
optional {
?statement pq:P4390 ?relation .
# URI of the equivalent skos property
?relation wdt:P2888 ?skosRelation .
}
# get label for the wd item, if exists
optional {
?wd rdfs:label ?wdLabelDe .
filter(lang(?wdLabelDe) = 'de')
}
optional {
?wd rdfs:label ?wdLabelEn .
filter(lang(?wdLabelEn) = 'en')
}
#bind(concat(if(bound(?wdLabelEn), str(?wdLabelEn), ''), ' | ', if(bound(?wdLabelDe), str(?wdLabelDe), '')) as ?wdLabel)
bind(concat(if(bound(?wdLabelDe), str(?wdLabelDe), ''), ' | ', if(bound(?wdLabelEn), str(?wdLabelEn), '')) as ?wdLabel)
}
# look up STW descriptors
bind(uri(concat('http://zbw.eu/stw/descriptor/', ?stwId)) as ?stw)
#
# restrict to certain subthes/notation range
?stw skos:broader* ?thsys .
?thsys skos:notation ?notation .
##filter(strstarts(?notation, "P.0"))
#
# add labels
?stw skos:prefLabel ?stwLabelDe .
filter(lang(?stwLabelDe) = 'de')
?stw skos:prefLabel ?stwLabelEn .
filter(lang(?stwLabelEn) = 'en')
bind(concat(if(bound(?stwLabelDe), str(?stwLabelDe), ''), ' | ', if(bound(?stwLabelEn), str(?stwLabelEn), '')) as ?stwLabel)
}
order by ?wdLabel str(?skosRelation) ?stwLabelLang