query-1e96d2dadcdde0f7b9f60ce022cdbb6f
(57) Scatter chart: 108 Generals in Water Margin first-appearance chapters by part (36/72 Stars, etc.) or narrative roleNo.57 (2020.12.28T1515 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#>
# scatter chart of 108 Generals in Water Margin first-appearance chapters
# classified by part (36/72 Stars, etc.) or narrative role
# also viewable as table
#defaultView:ScatterChart
# ?first_appearance_number (1st non-item variable) as X-axis; ?108_name (2nd non-item variable) as Y-axis
# ?partLabel (3rd non-item variable, replaceable by ?narrative_roleLabel) as color group
SELECT DISTINCT ?first_appearance ?first_appearance_number ?108_name ?108 ?partLabel ?narrative_roleLabel
WHERE {
# ?108 is instance of (P31) "subclass of (P279)" [ZeroOrMorePath (*)] fictional character (Q95074)
?108 wdt:P31/wdt:P279* wd:Q95074;
# and [InversePath (^)] has part (P527) [OneOrMorePath (+)] 108 Generals (Q905173)
^wdt:P527+ wd:Q905173
# optional: ?first_appearance is instance of (P31) chapter (Q1980247)
OPTIONAL {?first_appearance wdt:P31 wd:Q1980247;
# and is part of (P361) [OneOrMorePath (+)] Water Margin's 120-chapter edition (Q70761009)
wdt:P361+ wd:Q70761009;
# ?first_appearance's "characters" (P674) statement is ?character
p:P674 ?character.
# ?character's value is ?108
?character ps:P674 ?108;
# ?character's qualifier "subject has role" (P2868) is "first appearance" (Q8563381)
### Note: This line can be removed, and the X-axis will be changed to chapters in which
### any of the 108 Generals appears, not only for the first time.
pq:P2868 wd:Q8563381
# optional: ?first_appearance's chapter (P792) is ?first_number
OPTIONAL {?first_appearance wdt:P792 ?first_number} }
# use IF to bind ?first_number's 3-character form as ?first_appearance_number:
# if ?first_number has 1 character, concatenate "00" and it;
BIND(IF(STRLEN(?first_number)=1, CONCAT("00", ?first_number),
# if ?first_number has 2 characters, concatenate "0" and it;
IF(STRLEN(?first_number)=2, CONCAT("0", ?first_number),
# otherwise (?first_number has 3 characters), don't change it
?first_number)) AS ?first_appearance_number)
# optional: ?ordinal108 is defined as follows:
# 36 Tiangang (Q16830698)'s "has part" (P527) statement is ?36
OPTIONAL { {wd:Q16830698 p:P527 ?36.
# ?36's value is ?108
?36 ps:P527 ?108;
# ?36's qualifier "series ordinal" (P1545) is ?ordinal36
### Note: Ranking (P1352), whose data type is quantity, not string as P1545,
### cannot be used to generate ?ordinal108.
pq:P1545 ?ordinal36
# use IF to bind ?ordinal36's 3-character form as ?ordinal108:
# if ?ordinal36 has 1 character, concatenate "10" and it;
BIND(IF(STRLEN(?ordinal36)=1, CONCAT("10", ?ordinal36),
# otherwise (?ordinal36 has 2 characters), concatenate "1" and it
CONCAT("1", ?ordinal36)) AS ?ordinal108) }
# OR ?ordinal108 is defined as follows:
# 72 Disha (Q16830671)'s "has part" (P527) statement is ?72
UNION {wd:Q16830671 p:P527 ?72.
# ?72's value is ?108
?72 ps:P527 ?108;
# ?72's qualifier "series ordinal" (P1545) is ?ordinal72
pq:P1545 ?ordinal72
# use IF to bind ?ordinal72's 3-character form as ?ordinal108:
# if ?ordinal72 has 1 character, concatenate "20" and it;
BIND(IF(STRLEN(?ordinal72)=1, CONCAT("20", ?ordinal72),
# otherwise (?ordinal72 has 2 characters), concatenate "2" and it
CONCAT("2", ?ordinal72)) AS ?ordinal108) }
}
# optional: ?108's name in native language (P1559) is ?native_name
OPTIONAL {?108 wdt:P1559 ?native_name}
# bind concatenation of ?ordinal108 and ?native_name as ?108_name
BIND(CONCAT(?ordinal108, ?native_name) AS ?108_name)
# optional: show ?108's "member of (P463) or part of (P361)" [OneOrMorePath (+)] as ?part
OPTIONAL {?108 (wdt:P463|wdt:P361)+ ?part}
# optional: show ?character's qualifier "narrative role" (P5800) as ?narrative_role
OPTIONAL {?character pq:P5800 ?narrative_role}
# 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;
v1("?108"):::projected
v12("?108_name"):::projected
v6("?36")
v9("?72")
v3("?character")
v2("?first_appearance"):::projected
v5("?first_appearance_number"):::projected
v4("?first_number")
v14("?narrative_role")
v11("?native_name")
v11("?ordinal108")
v7("?ordinal36")
v10("?ordinal72")
v13("?part")
a1((" "))
c4(["wd:Q905173"]):::iri
c14(["wd:Q16830698"]):::iri
c3(["wd:Q95074"]):::iri
c23(["bd:serviceParam"]):::iri
c12(["wd:Q8563381"]):::iri
c18(["wd:Q16830671"]):::iri
c25(["#91;AUTO_LANGUAGE#93;,en"]):::literal
c6(["wd:Q1980247"]):::iri
c8(["wd:Q70761009"]):::iri
v1 --"p:direct/P31"--> a1
a1 --"p:direct/P279"--> c3
c4 --"p:direct/P527"--> v1
subgraph optional0["(optional)"]
style optional0 fill:#bbf,stroke-dasharray: 5 5;
v2 -."p:direct/P31".-> c6
v2 --"p:direct/P361"--> c8
v2 --"p:P674"--> v3
v3 --"p:statement/P674"--> v1
v3 --"p:qualifier/P2868"--> c12
subgraph optional1["(optional)"]
style optional1 fill:#bbf,stroke-dasharray: 5 5;
v2 -."p:direct/P792".-> v4
end
end
bind0[/"if(string-length(?first_number) = '1^^xsd:integer',concat('00',?first_number),if(string-length(?first_number) = '2^^xsd:integer',concat('0',?first_number),?first_number))"/]
v4 --o bind0
bind0 --as--o v5
subgraph optional2["(optional)"]
style optional2 fill:#bbf,stroke-dasharray: 5 5;
subgraph union0[" Union "]
subgraph union0l[" "]
style union0l fill:#abf,stroke-dasharray: 3 3;
c18 -."p:P527".-> v9
v9 --"p:statement/P527"--> v1
v9 --"p:qualifier/P1545"--> v10
bind1[/"if(string-length(?ordinal72) = '1^^xsd:integer',concat('20',?ordinal72),concat('2',?ordinal72))"/]
v10 --o bind1
bind1 --as--o v11
end
subgraph union0r[" "]
style union0r fill:#abf,stroke-dasharray: 3 3;
c14 --"p:P527"--> v6
v6 --"p:statement/P527"--> v1
v6 --"p:qualifier/P1545"--> v7
bind2[/"if(string-length(?ordinal36) = '1^^xsd:integer',concat('10',?ordinal36),concat('1',?ordinal36))"/]
v7 --o bind2
bind2 --as--o v11
end
union0r <== or ==> union0l
end
end
subgraph optional3["(optional)"]
style optional3 fill:#bbf,stroke-dasharray: 5 5;
v1 -."p:direct/P1559".-> v11
end
bind3[/"concat(?ordinal108,?native_name)"/]
v11 --o bind3
v11 --o bind3
bind3 --as--o v12
subgraph optional4["(optional)"]
style optional4 fill:#bbf,stroke-dasharray: 5 5;
subgraph union1[" Union "]
subgraph union1l[" "]
style union1l fill:#abf,stroke-dasharray: 3 3;
v1 -."p:direct/P361".-> v13
end
subgraph union1r[" "]
style union1r fill:#abf,stroke-dasharray: 3 3;
v1 --"p:direct/P463"--> v13
end
union1r <== or ==> union1l
end
end
subgraph optional5["(optional)"]
style optional5 fill:#bbf,stroke-dasharray: 5 5;
v3 -."p:qualifier/P5800".-> v14
end
subgraph s1["http://wikiba.se/ontology#label"]
style s1 stroke-width:4px;
c23 --"wikibase:language"--> c25
end