query-6b568b52092d1977b2db90b11e973db3
.on Mastodon and on TwitterOriginally posted
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 bd: <http://www.bigdata.com/rdf#>
SELECT ?item ?itemLabel ?itemDescription ?somePositionLabel ?died ?kind WHERE {
{
SELECT ?item (MAX(?died_) AS ?died) (SAMPLE(?kind_) AS ?kind) (SAMPLE(?position) AS ?somePosition) {
# death in battle or killed in action
{ ?item wdt:P1196 wd:Q18663901. BIND("death in battle"@en AS ?kind_) } UNION
{ ?item wdt:P509|wdt:P1347 wd:Q210392. BIND("killed in action"@en AS ?kind_) }
# suitable item
?item wdt:P31 wd:Q5;
wdt:P570 ?died_.
# head of state or government
{
VALUES ?class { wd:Q2285706 wd:Q48352 }
?item wdt:P39 ?position.
?position wdt:P279* ?class.
} UNION {
?state wdt:P6 ?item.
OPTIONAL { ?state wdt:P1313 ?position_. }
BIND(COALESCE(?position_, wd:Q2285706) AS ?position)
} UNION {
?state wdt:P35 ?item.
OPTIONAL { ?state wdt:P1906 ?position_. }
BIND(COALESCE(?position_, wd:Q48352) AS ?position)
}
}
GROUP BY ?item ?died_
}
SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en". }
}
ORDER BY DESC(?died)
LIMIT 100
Query found at
graph TD
classDef projected fill:lightgreen;
classDef literal fill:orange;
classDef iri fill:yellow;
v5("?class")
v9("?died"):::projected
v4("?died_")
v2("?item"):::projected
v9("?kind"):::projected
v4("?kind_")
v9("?position")
v8("?position_")
v10("?somePosition")
v7("?state")
c4(["wd:Q210392"]):::iri
c2(["wd:Q18663901"]):::iri
c16(["bd:serviceParam"]):::iri
c7(["wd:Q5"]):::iri
c18(["#91;AUTO_LANGUAGE#93;,en"]):::literal
subgraph union0[" Union "]
subgraph union0l[" "]
style union0l fill:#abf,stroke-dasharray: 3 3;
subgraph union1[" Union "]
subgraph union1l[" "]
style union1l fill:#abf,stroke-dasharray: 3 3;
v2 --"wdt:P1347"--> c4
end
subgraph union1r[" "]
style union1r fill:#abf,stroke-dasharray: 3 3;
v2 --"wdt:P509"--> c4
end
union1r <== or ==> union1l
end
bind0[/"skilled in action^^<http://www.w3.org/1999/02/22-rdf-syntax-ns#langString>'"/]
bind0 --as--o v4
end
subgraph union0r[" "]
style union0r fill:#abf,stroke-dasharray: 3 3;
v2 --"wdt:P1196"--> c2
bind1[/"sdeath in battle^^<http://www.w3.org/1999/02/22-rdf-syntax-ns#langString>'"/]
bind1 --as--o v4
end
union0r <== or ==> union0l
end
v2 --"wdt:P31"--> c7
v2 --"wdt:P570"--> v4
subgraph union2[" Union "]
subgraph union2l[" "]
style union2l fill:#abf,stroke-dasharray: 3 3;
subgraph union3[" Union "]
subgraph union3l[" "]
style union3l fill:#abf,stroke-dasharray: 3 3;
v7 --"wdt:P35"--> v2
subgraph optional0["(optional)"]
style optional0 fill:#bbf,stroke-dasharray: 5 5;
v7 -."wdt:P1906".-> v8
end
bind2[/"?position_'wd:Q48352'"/]
v8 --o bind2
bind2 --as--o v9
end
subgraph union3r[" "]
style union3r fill:#abf,stroke-dasharray: 3 3;
v7 --"wdt:P6"--> v2
subgraph optional1["(optional)"]
style optional1 fill:#bbf,stroke-dasharray: 5 5;
v7 -."wdt:P1313".-> v8
end
bind3[/"?position_'wd:Q2285706'"/]
v8 --o bind3
bind3 --as--o v9
end
union3r <== or ==> union3l
end
end
subgraph union2r[" "]
style union2r fill:#abf,stroke-dasharray: 3 3;
bind4[/VALUES ?class/]
bind4-->v5
bind40(["wd:Q2285706"])
bind40 --> bind4
bind41(["wd:Q48352"])
bind41 --> bind4
v2 --"wdt:P39"--> v9
v9 --"wdt:P279"--> v5
end
union2r <== or ==> union2l
end
bind8[/"max(?died_)"/]
v4 --o bind8
bind8 --as--o v9
bind9[/"sample(?kind_)"/]
v4 --o bind9
bind9 --as--o v9
bind10[/"sample(?position)"/]
v9 --o bind10
bind10 --as--o v10
subgraph s1["http://wikiba.se/ontology#label"]
style s1 stroke-width:4px;
c16 --"wikibase:language"--> c18
end