query-96cfae8d7350625667c4580e62f760d0
(36) Graph of position holders by succession: presidents of the United StatesNo.36 (2020.07.09T0036 created)
Use at
- https://query.wikidata.org/sparql
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 pq: <http://www.wikidata.org/prop/qualifier/>
PREFIX p: <http://www.wikidata.org/prop/>
PREFIX bd: <http://www.bigdata.com/rdf#>
# graph of presidents of the United States by succession (also viewable as table)
# querying qualifier
#defaultView:Graph
SELECT ?position_holder ?position_holderLabel ?image ?series_ordinal ?start ?end ?end_causeLabel ?predecessorLabel ?successor ?successorLabel ?edgeLabel ?birth_date ?death_date ?death_mannerLabel ?start_age ?end_age ?death_age
WHERE {
# ?position_holder is instance of (P31) human (Q5)
?position_holder wdt:P31 wd:Q5;
# ?position_holder's "position held" (P39) statment is ?x
p:P39 ?x.
# ?x's value is President of the United States (Q11696)
?x ps:P39 wd:Q11696.
# optional: show ?position_holder's image (P18) as ?image
OPTIONAL {?position_holder wdt:P18 ?image}
# optional: show ?x's qualifier "series ordinal" (P1545) as ?series_ordinal
OPTIONAL {?x pq:P1545 ?series_ordinal}
# optional: show ?x's qualifier "start time" (P580) as ?start
OPTIONAL {?x pq:P580 ?start}
# optional: show ?x's qualifier "end time" (P582) as ?end
OPTIONAL {?x pq:P582 ?end}
# optional: show ?x's qualifier "end cause" (P1534) as ?end_cause
OPTIONAL {?x pq:P1534 ?end_cause}
# optional: show ?x's qualifier "replaces" (P1365) as ?predecessor
OPTIONAL{?x pq:P1365 ?predecessor}
# optional: show ?x's qualifier "replaced by" (P1366) as ?successor
OPTIONAL {?x pq:P1366 ?successor.
# get P1366 (replaced by)'s property label and allow it to appear on graph edge
### Note: Property label can be got when property is used as main value (wdt), not when used as qualifier (pq).
### So it doesn't work to define ?relation as a group of properties from ?a to ?b and get ?relation's property label
### if the properties are used as qualifiers.
?edge wikibase:directClaim wdt:P1366;
a wikibase:Property}
# optional: show ?position_holder's birth date (P569) as ?birth_date
OPTIONAL {?position_holder wdt:P569 ?birth_date}
# optional: show ?position_holder's death date (P570) as ?death_date
OPTIONAL {?position_holder wdt:P570 ?death_date}
# optional: show ?position_holder's manner of death (P1196) as ?death_manner
OPTIONAL {?position_holder wdt:P1196 ?death_manner}
# use IF to calculate the age when term started, and bind the age as ?start_age
BIND(IF(MONTH(?start)>MONTH(?birth_date) || (MONTH(?start)=MONTH(?birth_date) && DAY(?start)>=DAY(?birth_date)), YEAR(?start)-YEAR(?birth_date), YEAR(?start)-YEAR(?birth_date)-1) AS ?start_age)
# use IF to calculate the age when term ended, and bind the age as ?end_age
BIND(IF(MONTH(?end)>MONTH(?birth_date) || (MONTH(?end)=MONTH(?birth_date) && DAY(?end)>=DAY(?birth_date)), YEAR(?end)-YEAR(?birth_date), YEAR(?end)-YEAR(?birth_date)-1) AS ?end_age)
# use IF to calculate the age of death, and bind the age as ?death_age
BIND(IF(MONTH(?death_date)>MONTH(?birth_date) || (MONTH(?death_date)=MONTH(?birth_date) && DAY(?death_date)>=DAY(?birth_date)), YEAR(?death_date)-YEAR(?birth_date), YEAR(?death_date)-YEAR(?birth_date)-1) AS ?death_age)
# show label in auto language as default, and English when no default label exists
SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en". }
}
Query found at
graph TD
classDef projected fill:lightgreen;
classDef literal fill:orange;
classDef iri fill:yellow;
v11("?birth_date"):::projected
v16("?death_age"):::projected
v12("?death_date"):::projected
v13("?death_manner")
v10("?edge")
v6("?end"):::projected
v15("?end_age"):::projected
v7("?end_cause")
v3("?image"):::projected
v1("?position_holder"):::projected
v8("?predecessor")
v4("?series_ordinal"):::projected
v5("?start"):::projected
v14("?start_age"):::projected
v9("?successor"):::projected
v2("?x")
c16(["wikibase:Property"]):::iri
c14(["p:direct/P1366"]):::iri
c21(["bd:serviceParam"]):::iri
c2(["wd:Q5"]):::iri
c23(["#91;AUTO_LANGUAGE#93;,en"]):::literal
c5(["wd:Q11696"]):::iri
v1 --"p:direct/P31"--> c2
v1 --"p:P39"--> v2
v2 --"p:statement/P39"--> c5
subgraph optional0["(optional)"]
style optional0 fill:#bbf,stroke-dasharray: 5 5;
v1 -."p:direct/P18".-> v3
end
subgraph optional1["(optional)"]
style optional1 fill:#bbf,stroke-dasharray: 5 5;
v2 -."p:qualifier/P1545".-> v4
end
subgraph optional2["(optional)"]
style optional2 fill:#bbf,stroke-dasharray: 5 5;
v2 -."p:qualifier/P580".-> v5
end
subgraph optional3["(optional)"]
style optional3 fill:#bbf,stroke-dasharray: 5 5;
v2 -."p:qualifier/P582".-> v6
end
subgraph optional4["(optional)"]
style optional4 fill:#bbf,stroke-dasharray: 5 5;
v2 -."p:qualifier/P1534".-> v7
end
subgraph optional5["(optional)"]
style optional5 fill:#bbf,stroke-dasharray: 5 5;
v2 -."p:qualifier/P1365".-> v8
end
subgraph optional6["(optional)"]
style optional6 fill:#bbf,stroke-dasharray: 5 5;
v2 -."p:qualifier/P1366".-> v9
v10 --"wikibase:directClaim"--> c14
v10 --"a"--> c16
end
subgraph optional7["(optional)"]
style optional7 fill:#bbf,stroke-dasharray: 5 5;
v1 -."p:direct/P569".-> v11
end
subgraph optional8["(optional)"]
style optional8 fill:#bbf,stroke-dasharray: 5 5;
v1 -."p:direct/P570".-> v12
end
subgraph optional9["(optional)"]
style optional9 fill:#bbf,stroke-dasharray: 5 5;
v1 -."p:direct/P1196".-> v13
end
bind0[/"if((month-from-dateTime(?start) > month-from-dateTime(?birth_date) || month-from-dateTime(?start) = month-from-dateTime(?birth_date)day-from-dateTime(?start) >= day-from-dateTime(?birth_date)),year-from-dateTime(?start) - year-from-dateTime(?birth_date),year-from-dateTime(?start) - year-from-dateTime(?birth_date) + '-1^^xsd:integer')"/]
v5 --o bind0
v11 --o bind0
bind0 --as--o v14
bind1[/"if((month-from-dateTime(?end) > month-from-dateTime(?birth_date) || month-from-dateTime(?end) = month-from-dateTime(?birth_date)day-from-dateTime(?end) >= day-from-dateTime(?birth_date)),year-from-dateTime(?end) - year-from-dateTime(?birth_date),year-from-dateTime(?end) - year-from-dateTime(?birth_date) + '-1^^xsd:integer')"/]
v6 --o bind1
v11 --o bind1
bind1 --as--o v15
bind2[/"if((month-from-dateTime(?death_date) > month-from-dateTime(?birth_date) || month-from-dateTime(?death_date) = month-from-dateTime(?birth_date)day-from-dateTime(?death_date) >= day-from-dateTime(?birth_date)),year-from-dateTime(?death_date) - year-from-dateTime(?birth_date),year-from-dateTime(?death_date) - year-from-dateTime(?birth_date) + '-1^^xsd:integer')"/]
v12 --o bind2
v11 --o bind2
bind2 --as--o v16
subgraph s1["http://wikiba.se/ontology#label"]
style s1 stroke-width:4px;
c21 --"wikibase:language"--> c23
end