query-d497ccdee6414feed2197f9695ad676a
Propertiesinstance of (P31)part of (P361)publication date (P577)
Use at
- https://query.wikidata.org/sparql
PREFIX xsd: <http://www.w3.org/2001/XMLSchema#>
PREFIX wikibase: <http://wikiba.se/ontology#>
PREFIX wdt: <http://www.wikidata.org/prop/direct/>
PREFIX wd: <http://www.wikidata.org/entity/>
PREFIX psv: <http://www.wikidata.org/prop/statement/value/>
PREFIX p: <http://www.wikidata.org/prop/>
PREFIX bd: <http://www.bigdata.com/rdf#>
SELECT ?weekday (COUNT(?xkcd) AS ?count) (xsd:integer(?offset + 1) AS ?dayorder)
WHERE {
?xkcd wdt:P31 wd:Q838795;
wdt:P361 wd:Q13915;
p:P577/psv:P577 [
wikibase:timeValue ?date;
wikibase:timePrecision ?precision
].
FILTER(?precision >= "11"^^xsd:integer)
# calculate the weekday as the offset from January first, 1973 (arbitrary Monday that preceeds the first xkcd) modulo 7
# SPARQL has no modulo operator, so this gets finicky
BIND(?date - "1973-01-01"^^xsd:date AS ?offsetInt)
BIND(?offsetInt - (7 * xsd:integer(xsd:float(?offsetInt) / 7.0)) AS ?offsetSigned)
BIND(IF(?offsetSigned < 0, ?offsetSigned + 7, ?offsetSigned) AS ?offset)
BIND(IF(?offset = 0, "Monday"@en,
IF(?offset = 1, "Tuesday"@en,
IF(?offset = 2, "Wednesday"@en,
IF(?offset = 3, "Thursday"@en,
IF(?offset = 4, "Friday"@en,
IF(?offset = 5, "Saturday"@en,
IF(?offset = 6, "Sunday"@en,
"unknown day"@en)))))))
AS ?weekday)
SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en". }
} GROUP BY ?weekday ?offset ORDER BY ?dayorder
Query found at
graph TD
classDef projected fill:lightgreen;
classDef literal fill:orange;
classDef iri fill:yellow;
v9("?count")
v4("?date")
v10("?dayorder")
v7("?offset"):::projected
v5("?offsetInt")
v6("?offsetSigned")
v2("?precision")
v8("?weekday"):::projected
v3("?xkcd"):::projected
a2((" "))
a1((" "))
c5(["wd:Q13915"]):::iri
c3(["wd:Q838795"]):::iri
c11(["bd:serviceParam"]):::iri
c13(["#91;AUTO_LANGUAGE#93;,en"]):::literal
f0[["?precision >= '11^^xsd:integer'"]]
f0 --> v2
v3 --"p:direct/P31"--> c3
v3 --"p:direct/P361"--> c5
a1 --"wikibase:timeValue"--> v4
a1 --"wikibase:timePrecision"--> v2
v3 --"p:P577"--> a2
a2 --"p:statement/value/P577"--> a1
bind1[/"?date - '1973-01-01^^xsd:date'"/]
v4 --o bind1
bind1 --as--o v5
bind2[/"?offsetInt - '7^^xsd:integer' * http://www.w3.org/2001/XMLSchema#integer(http://www.w3.org/2001/XMLSchema#float(?offsetInt) / '7.0^^xsd:decimal')"/]
v5 --o bind2
bind2 --as--o v6
bind3[/"if(?offsetSigned < '0^^xsd:integer',?offsetSigned + '7^^xsd:integer',?offsetSigned)"/]
v6 --o bind3
bind3 --as--o v7
bind4[/"if(?offset = '0^^xsd:integer',sMonday^^<http://www.w3.org/1999/02/22-rdf-syntax-ns#langString>',if(?offset = '1^^xsd:integer',sTuesday^^<http://www.w3.org/1999/02/22-rdf-syntax-ns#langString>',if(?offset = '2^^xsd:integer',sWednesday^^<http://www.w3.org/1999/02/22-rdf-syntax-ns#langString>',if(?offset = '3^^xsd:integer',sThursday^^<http://www.w3.org/1999/02/22-rdf-syntax-ns#langString>',if(?offset = '4^^xsd:integer',sFriday^^<http://www.w3.org/1999/02/22-rdf-syntax-ns#langString>',if(?offset = '5^^xsd:integer',sSaturday^^<http://www.w3.org/1999/02/22-rdf-syntax-ns#langString>',if(?offset = '6^^xsd:integer',sSunday^^<http://www.w3.org/1999/02/22-rdf-syntax-ns#langString>',sunknown day^^<http://www.w3.org/1999/02/22-rdf-syntax-ns#langString>')))))))"/]
v7 --o bind4
bind4 --as--o v8
subgraph s1["http://wikiba.se/ontology#label"]
style s1 stroke-width:4px;
c11 --"wikibase:language"--> c13
end
bind6[/"count(?xkcd)"/]
v3 --o bind6
bind6 --as--o v9
bind7[/"http://www.w3.org/2001/XMLSchema#integer(?offset + '1^^xsd:integer')"/]
v7 --o bind7
bind7 --as--o v10