query-71f76e2aa28e31d53106453337cdd88a
TODO
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 ps: <http://www.wikidata.org/prop/statement/>
PREFIX pqv: <http://www.wikidata.org/prop/qualifier/value/>
PREFIX pq: <http://www.wikidata.org/prop/qualifier/>
PREFIX p: <http://www.wikidata.org/prop/>
PREFIX bd: <http://www.bigdata.com/rdf#>
SELECT ?raceLabel ?team ?teamNameLabel ?person ?personLabel ?et ?et_tp ?et_year_end WHERE {
# person participated in a Tour de France race of a given year
?race wdt:P31 wd:Q33881.
?person wdt:P1344 ?race.
?race wdt:P580 ?raceStart.
?race wdt:P582 ?raceEnd.
bind(year(?raceStart) as ?raceYear)
filter(?raceYear = 2018)
# person's team membership
?person p:P54 ?teamStatement .
?teamStatement ps:P54 ?team .
optional {?teamStatement pq:P580 ?st}
optional {?teamStatement pq:P582 ?et .
?teamStatement pqv:P582 [wikibase:timePrecision ?et_tp] . # timePrecision: ... 11 = day, 10 = month, 9 = year ...
BIND(IF(?et_tp<11,xsd:dateTime(CONCAT(STR(YEAR(?et)),'-12-31T00:00:00Z')),?et) AS ?et_year_end)
# ?et_year_end now contains the last day of the year if ?et have a lower precision than day
}
filter(?st <= ?raceStart && if(bound(?et), year(?et) >= year(?raceEnd), true))
# team name at the time
?team p:P1448 ?nameStatement .
?nameStatement ps:P1448 ?teamName .
optional {?nameStatement pq:P580 ?stName}
optional {?nameStatement pq:P582 ?etName}
filter(?stName <= ?raceStart && if(bound(?etName), year(?etName) >= year(?raceEnd), true))
SERVICE wikibase:label { bd:serviceParam wikibase:language "en". }
} order by asc(?teamNameLabel) asc(?personLabel)
Query found at
graph TD
classDef projected fill:lightgreen;
classDef literal fill:orange;
classDef iri fill:yellow;
v8("?et"):::projected
v5("?etName")
v14("?et_tp"):::projected
v15("?et_year_end"):::projected
v16("?nameStatement")
v11("?person"):::projected
v2("?personLabel"):::projected
v10("?race")
v6("?raceEnd")
v4("?raceStart")
v12("?raceYear")
v7("?st")
v3("?stName")
v13("?team"):::projected
v17("?teamName")
v1("?teamNameLabel"):::projected
v12("?teamStatement")
a1((" "))
c19(["en"]):::literal
c17(["bd:serviceParam"]):::iri
c4(["wd:Q33881"]):::iri
f0[["?stName <= ?raceStartif(bound(?etName),year-from-dateTime(?etName) >= year-from-dateTime(?raceEnd),'true^^xsd:boolean')"]]
f0 --> v3
f0 --> v4
f0 --> v5
f0 --> v6
f1[["?st <= ?raceStartif(bound(?et),year-from-dateTime(?et) >= year-from-dateTime(?raceEnd),'true^^xsd:boolean')"]]
f1 --> v7
f1 --> v4
f1 --> v8
f1 --> v6
f2[["?raceYear = '2018^^xsd:integer'"]]
f2 --> v12
v10 --"p:direct/P31"--> c4
v11 --"p:direct/P1344"--> v10
v10 --"p:direct/P580"--> v4
v10 --"p:direct/P582"--> v6
bind3[/"year-from-dateTime(?raceStart)"/]
v4 --o bind3
bind3 --as--o v12
v11 --"p:P54"--> v12
v12 --"p:statement/P54"--> v13
subgraph optional0["(optional)"]
style optional0 fill:#bbf,stroke-dasharray: 5 5;
v12 -."p:qualifier/P580".-> v7
end
subgraph optional1["(optional)"]
style optional1 fill:#bbf,stroke-dasharray: 5 5;
v12 -."p:qualifier/P582".-> v8
a1 --"wikibase:timePrecision"--> v14
v12 --"p:qualifier/value/P582"--> a1
bind4[/"if(?et_tp < '11^^xsd:integer',http://www.w3.org/2001/XMLSchema#dateTime(concat(str(year-from-dateTime(?et)),'-12-31T00:00:00Z')),?et)"/]
v14 --o bind4
v8 --o bind4
bind4 --as--o v15
end
v13 --"p:P1448"--> v16
v16 --"p:statement/P1448"--> v17
subgraph optional2["(optional)"]
style optional2 fill:#bbf,stroke-dasharray: 5 5;
v16 -."p:qualifier/P580".-> v3
end
subgraph optional3["(optional)"]
style optional3 fill:#bbf,stroke-dasharray: 5 5;
v16 -."p:qualifier/P582".-> v5
end
subgraph s1["http://wikiba.se/ontology#label"]
style s1 stroke-width:4px;
c17 --"wikibase:language"--> c19
end