forked from zbw/sparql-queries
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsubject_folders_for_wikidata.rq
86 lines (84 loc) · 3.08 KB
/
subject_folders_for_wikidata.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
# Extract information for creating subject folder items in Wikidata
#
PREFIX dct: <http://purl.org/dc/terms/>
PREFIX p: <http://www.wikidata.org/prop/>
PREFIX pq: <http://www.wikidata.org/prop/qualifier/>
PREFIX ps: <http://www.wikidata.org/prop/statement/>
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 distinct ?pm20Id ?labelDe ?labelEn
('Mappe aus dem Pressearchiv 20. Jahrhundert' as ?descrDe)
('folder of the 20th Century Press Archives' as ?descrEn)
(concat(?countryCode, ' ', ?subjectCode) as ?alias)
?countryCode ?subjectCode ('Q91257459' as ?classQid) ('Q36948990' as ?partOf)
?countryQid ?subjectQid
where {
{
# main table
?pm20 a zbwext:SubjectFolder ;
dct:identifier ?pm20Id ;
zbwext:country ?country ;
zbwext:subject ?subject .
#
# countries
graph <http://zbw.eu/beta/geo/ng> {
?country a skos:Concept ;
zbwext:notationLong ?countryNtaLong ;
skos:notation ?countryCode .
?country skos:prefLabel ?countryLabelLangDe .
filter(lang(?countryLabelLangDe) = 'de')
bind(str(?countryLabelLangDe) as ?countryLabelDe)
optional {
?country skos:prefLabel ?countryLabelLangEn .
filter(lang(?countryLabelLangEn) = 'en')
bind(str(?countryLabelLangEn) as ?countryLabelEn)
}
}
# subjects
graph <http://zbw.eu/beta/subject/ng> {
?subject a skos:Concept ;
zbwext:notationLong ?subjectNtaLong ;
skos:notation ?notation .
bind(replace(?notation, ' ', '_') as ?subjectCode)
?subject skos:prefLabel ?subjectLabelLangDe .
filter(lang(?subjectLabelLangDe) = 'de')
bind(str(?subjectLabelLangDe) as ?subjectLabelDe)
optional {
?subject skos:prefLabel ?subjectLabelLangEn .
filter(lang(?subjectLabelLangEn) = 'en')
bind(str(?subjectLabelLangEn) as ?subjectLabelEn)
}
# restriction to real notations (no keywords)
filter(regex(?subjectNtaLong, "^[a-z]"))
#
# filter out special topics for SM
filter(!regex(?subjectCode, "^[a-z]0"))
filter(!strends(?subjectNtaLong, '-'))
}
} minus {
# filter out folders already existing in WD
service <https://query.wikidata.org/sparql> {
?wd wdt:P31 wd:Q91257459 ;
wdt:P4293 ?pm20Id .
}
}
# Look up linked Wikidata items
service <https://query.wikidata.org/sparql> {
?wdSubject wdt:P8484 ?subjectCode .
# only exact matching countries
?wdCountry p:P8483 ?statement .
?statement pq:P4390 wd:Q39893449 ;
ps:P8483 ?countryCode .
}
# concatenated fields
bind(concat(?countryLabelDe, ' : ', ?subjectLabelDe) as ?labelDe)
bind(concat(?countryLabelEn, ' : ', ?subjectLabelEn) as ?labelEn)
bind(concat(?countryNtaLong, ' ', ?subjectNtaLong) as ?notationLong)
#
bind(strafter(str(?wdCountry), str(wd:)) as ?countryQid)
bind(strafter(str(?wdSubject), str(wd:)) as ?subjectQid)
}
order by ?notationLong