forked from zbw/sparql-queries
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcount_folder_type.rq
46 lines (45 loc) · 1.67 KB
/
count_folder_type.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
# Count pm20 ids in total, with docs and with link in WD, by folder type
#
PREFIX dcterms: <http://purl.org/dc/terms/>
PREFIX hint: <http://www.bigdata.com/queryHints#>
PREFIX wdt: <http://www.wikidata.org/prop/direct/>
PREFIX zbwext: <http://zbw.eu/namespaces/zbw-extensions/>
#
select ?type (str(count(distinct ?pm20Id)) as ?totalCount) (str(sum(?hasDocs)) as ?withDocs) (str(sum(?hasWd)) as ?withWd) (str(sum(?hasWdAndDocs)) as ?withWdAndDocs) (concat(str(round((sum(?hasWdAndDocs)/sum(?hasDocs))*1000)/10), ' %') as ?percentage)
(concat('| ', substr(str(now()),0,11), ' || ', ?totalCount, ' || ', ?withDocs, ' || ', ?withWd, ' || ', ?withWdAndDocs, ' || ', ?percentage ) as ?statsLine)
where {
{
# all folders
?pm20 a zbwext:Pm20Folder ;
dcterms:identifier ?pm20Id .
# check if documents are available
optional {
?pm20 zbwext:freeDocCount ?docCount .
}
bind(if(bound(?docCount) && (?docCount > 0), 1, 0) as ?hasDocs)
bind(0 as ?hasWd)
bind(0 as ?hasWdAndDocs)
} union {
# folders linked from WD
service <https://query.wikidata.org/sparql> {
# since one pm20Id may be linked to multiple wd items,
# we need 'distinct' here
select distinct ?pm20 ?pm20Id
where {
hint:Query hint:optimizer "None" .
?wd wdt:P4293 ?pm20Id .
bind(uri(concat('https://pm20.zbw.eu/folder/', ?pm20Id)) as ?pm20)
}
}
bind(1 as ?hasWd)
# check if documents are available
optional {
?pm20 zbwext:freeDocCount ?docCount .
}
bind(if(bound(?docCount) && (?docCount > 0), 1, 0) as ?hasWdAndDocs)
bind(0 as ?hasDocs)
}
bind(substr(?pm20Id, 0, 3) as ?type)
}
group by ?type
order by ?type