forked from zbw/sparql-queries
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathadd_category_code.rq
66 lines (65 loc) · 2.08 KB
/
add_category_code.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
# Get PM20 category codes for WD items mapped to PM20
# here: ag vocab and PM20 geo code (P8483)
#
PREFIX dct: <http://purl.org/dc/terms/>
PREFIX skos: <http://www.w3.org/2004/02/skos/core#>
PREFIX wdt: <http://www.wikidata.org/prop/direct/>
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
PREFIX zbwext: <http://zbw.eu/namespaces/zbw-extensions/>
PREFIX wd: <http://www.wikidata.org/entity/>
#
select ?wd ?wdLabel ?rel ?relProp ?signature ?category ?categoryLabel ?qsStatement
where {
values ( ?rel ?relProp ) {
( skos:exactMatch 'Q39893449' )
( skos:closeMatch 'Q39893184' )
( skos:relatedMatch 'Q39894604' )
# the following two statements are reversed due to
# direction in the source data
( skos:broadMatch 'Q39893967' )
( skos:narrowMatch 'Q39894595' )
}
# exclude existing signatures in WD
{
graph <http://zbw.eu/beta/geo/ng> {
?category a skos:Concept ;
?rel ?wd ;
skos:prefLabel ?categoryLabelLang ;
skos:notation ?signature .
filter(strstarts(str(?wd), str(wd:)))
filter(lang(?categoryLabelLang) = 'en')
bind(str(?categoryLabelLang) as ?categoryLabel)
#
# restrict to categories used for sh or wa folders
optional {
?category zbwext:shFolderCount ?shCnt .
}
optional {
?category zbwext:waFolderCount ?waCnt .
}
filter(bound(?shCnt) || bound(?waCnt))
# remove root entry of category system
filter(?signature != 'AG')
}
} minus {
service <https://query.wikidata.org/sparql> {
?wd wdt:P8483 ?signature .
}
}
#
# add Wikidata labels (informative)
graph <http://zbw.eu/beta/wikidata/ng> {
optional {
?wd rdfs:label ?wdLabelLang .
filter(lang(?wdLabelLang) = 'en')
bind(str(?wdLabelLang) as ?wdLabel)
}
}
#
# QS statement (QS does not work for unknown values!)
bind(concat(strafter(str(?wd), str(wd:)),'|P8483|"', ?signature,
## TODO use perhaps English label? Or both?
'"|P1810|"', ?categoryLabel,
'"|P4390|', ?relProp) as ?qsStatement)
}
order by ?wdLabel