-
Notifications
You must be signed in to change notification settings - Fork 3
/
query.rq
53 lines (48 loc) · 2.25 KB
/
query.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
SELECT ?date ?work ?workLabel ?topics (GROUP_CONCAT(DISTINCT ?object_label; separator=" // ") AS ?objects) (GROUP_CONCAT(DISTINCT ?place_label; separator=" // ") AS ?places) (GROUP_CONCAT(?authorLabel; separator= " - ") AS ?authors) (GROUP_CONCAT(?authorstring; separator= " - ") AS ?authorstrings) (GROUP_CONCAT(?editorLabel; separator= " - ") AS ?editors) ?publisherLabel
WITH {
SELECT DISTINCT ?work WHERE {
?work wdt:P921 / (wdt:P361+ | wdt:P1269+ | (wdt:P31* / wdt:P279*) ) wd:Q58681669 .
}
} AS %works
WITH {
SELECT (MIN(?dates) as ?datetime) ?work (GROUP_CONCAT(?topic_label; separator=" // ") AS ?topics) WHERE {
INCLUDE %works
?work wdt:P921 ?topic .
FILTER NOT EXISTS {
?topic wdt:P31 wd:Q839954} .
FILTER NOT EXISTS {
?topic wdt:P31 wd:Q220659}
OPTIONAL { ?work wdt:P577 ?dates . }
?topic rdfs:label ?topic_label . FILTER (lang(?topic_label) = 'en')
}
GROUP BY ?work
} AS %result
WHERE {
INCLUDE %result
OPTIONAL { ?work wdt:P50 ?author .
?author rdfs:label ?authorLabel . FILTER (lang(?authorLabel) = 'en')
}
# no extra label assignment here, because we already have an author string
OPTIONAL { ?work wdt:P2093 ?authorstring . }
OPTIONAL { ?work wdt:P98 ?editor .
?editor rdfs:label ?editorLabel . FILTER (lang(?editorLabel) = 'en')
}
OPTIONAL { ?work wdt:P123 ?publisher . }
#collect related places (are in topic list; are instance of archaeological site
OPTIONAL {?work wdt:P921 ?place
FILTER EXISTS {?place wdt:P31 wd:Q839954}
?place rdfs:label?place_label . FILTER (lang(?place_label) = 'en')
}
#collect related objects (are in topic list; are instance of archaeological artifact
OPTIONAL {?work wdt:P921 ?object .
FILTER EXISTS {?object wdt:P31 wd:Q220659}
?object rdfs:label?object_label . FILTER (lang(?object_label) = 'en')
}
# There is a problem with BC dates
# BIND(xsd:date(?datetime) AS ?date)
BIND(REPLACE(STR(?datetime), 'T.*', '') AS ?date)
SERVICE wikibase:label { bd:serviceParam wikibase:language "en,da,de,es,fr,jp,nl,no,ru,sv,zh". }
}
GROUP BY ?date ?work ?workLabel ?topics ?publisher ?publisherLabel
ORDER BY ASC(?author)
LIMIT 500