query-fcdb7cd434a3ae5abffa7d6cf7cc36c2
(74) Graph of locations by level: Romance of the Three KingdomsNo.74 (2024.07.27T1836 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 p: <http://www.wikidata.org/prop/>
PREFIX bd: <http://www.bigdata.com/rdf#>
# title of the query
#title: graph of locations by level in Romance of the Three Kingdoms
# viewed as graph
#defaultView:Graph
SELECT DISTINCT ?place ?placeLabel ?upper ?upperLabel ?edgeLabel
WHERE {
# ?place is instance of (P31) "subclass of (P279)" [ZeroOrMorePath (*)] fictional location (Q3895768)
?place wdt:P31/wdt:P279* wd:Q3895768;
# present in work (P1441): Romance of the Three Kingdoms (Q70806)
### This query, as far as I remember, was created originally for Dream of the Red Chamber (Q8265)
### between 4 September 2021 and 4 January 2022.
wdt:P1441 wd:Q70806
# use IF and EXISTS to bind a property as ?p:
# if ?place has location (P276), bind location (P276) as ?p
BIND(IF(Exists{?place wdt:P276 ?a}, wdt:P276,
# if ?place has "located in the administrative territorial entity" (P131),
# bind "located in the administrative territorial entity" (P131) as ?p
IF(Exists{?place wdt:P131 ?b}, wdt:P131,
# if ?place is instance of (P31) "subclass of (P279)" [ZeroOrMorePath (*)] fictional country (Q1145276),
# bind continent (P30) as ?p
IF(Exists{?place wdt:P31/wdt:P279* wd:Q1145276}, wdt:P30,
# otherwise, bind country (P17) as ?p
wdt:P17))) AS ?p)
# optional: ?place's ?p is ?upper
OPTIONAL {?place ?p ?upper.
# get ?p's property label and allow it to appear on graph edge
?edge wikibase:directClaim ?p}
# 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
- https://www.wikidata.org/wiki/User:Neo-Jay/Query
- https://www.wikidata.org/wiki/User:Neo-Jay/Query/1.1
graph TD
classDef projected fill:lightgreen;
classDef literal fill:orange;
classDef iri fill:yellow;
v4("?edge")
v2("?p")
v1("?place"):::projected
v3("?upper"):::projected
a1((" "))
c5(["wd:Q70806"]):::iri
c3(["wd:Q3895768"]):::iri
c8(["bd:serviceParam"]):::iri
c10(["#91;AUTO_LANGUAGE#93;,en"]):::literal
v1 --"p:direct/P31"--> a1
a1 --"p:direct/P279"--> c3
v1 --"p:direct/P1441"--> c5
v1 --"p:direct/P276"--> null
v1 --"p:direct/P131"--> null
v1 --"p:direct/P31"--> null
null --"p:direct/P279"--> null
bind0[/"if( ,'p:direct/P276',if( ,'p:direct/P131',if( ,'p:direct/P30','p:direct/P17')))"/]
subgraph bind0e0["Exists Clause"]
e0v1 --"p:direct/P276"--> e0v2
e0v2("?a"):::projected
e0v1("?place"):::projected
end
bind0--EXISTS--> bind0e0
subgraph bind0e1["Exists Clause"]
e1v1 --"p:direct/P131"--> e1v2
e1v2("?b"):::projected
e1v1("?place"):::projected
end
bind0--EXISTS--> bind0e1
subgraph bind0e2["Exists Clause"]
e2v1 --"p:direct/P31"--> e2a1
e2a1 --"p:direct/P279"--> e2c3
e2v1("?place"):::projected
e2a1((" ")):::projected
e2c3(["wd:Q1145276"]):::iri
end
bind0--EXISTS--> bind0e2
v1 --o bind0
null --o bind0
null --o bind0
null --o bind0
null --o bind0
c1 --o bind0
null --o bind0
c2 --o bind0
null --o bind0
bind0 --as--o v2
subgraph optional0["(optional)"]
style optional0 fill:#bbf,stroke-dasharray: 5 5;
v1 -->v2--> v3
v4 -."wikibase:directClaim".-> v2
end
subgraph s1["http://wikiba.se/ontology#label"]
style s1 stroke-width:4px;
c8 --"wikibase:language"--> c10
end