query-79124e6cc1da689d905c4e51527e4201

rq turtle/ttl

(59) Scatter chart: 108 Generals in Water Margin death chapters by part (36/72 Stars, etc.) or narrative role or manner/cause/place/date of deathNo.59 (2021.02.08T1748 created)

Use at

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 death chapters
# classified by part (36/72 Stars, etc.) or narrative role or manner/cause/place/date of death
# also viewable as table
#defaultView:ScatterChart
# ?death_chapter_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 ?death_chapter ?death_chapter_number ?108_name ?108 ?partLabel ?narrative_roleLabel ?death_mannerLabel ?death_causeLabel ?death_placeLabel ?death_dateLabel
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.
  # ?death_chapter is instance of (P31) chapter (Q1980247)
  ?death_chapter wdt:P31 wd:Q1980247;
                 # and is part of (P361) [OneOrMorePath (+)] Water Margin's 120-chapter edition (Q70761009)
                 wdt:P361+ wd:Q70761009;
                 # ?death_chapter's "characters" (P674) statement is ?character
                 p:P674 ?character.
  # ?character's value is ?108
  ?character ps:P674 ?108;
             # ?character's qualifier "significant event" (P793) is "death" (Q4)
             pq:P793 wd:Q4
  # optional: ?death_chapter's chapter (P792) is ?death_number
  OPTIONAL {?death_chapter wdt:P792 ?death_number}
  # use IF to bind ?death_number's 3-character form as ?death_chapter_number:
  # if ?death_number has 1 character, concatenate "00" and it;
  BIND(IF(STRLEN(?death_number)=1, CONCAT("00", ?death_number),
       # if ?death_number has 2 characters, concatenate "0" and it;
       IF(STRLEN(?death_number)=2, CONCAT("0", ?death_number),
       # otherwise (?death_number has 3 characters), don't change it
       ?death_number)) AS ?death_chapter_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}
  # optional: show ?108's manner of death (P1196) as ?death_manner
  OPTIONAL {?108 wdt:P1196 ?death_manner}
  # optional: show ?108's cause of death (P509) as ?death_cause
  OPTIONAL {?108 wdt:P509 ?death_cause}
  # optional: show ?108's place of death (P20) as ?death_place
  OPTIONAL {?108 wdt:P20 ?death_place}
  # optional: show ?108's date of death (P570) as ?death_date
  OPTIONAL {?108 wdt:P570 ?death_date}
  # 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") v16("?death_cause") v2("?death_chapter"):::projected v5("?death_chapter_number"):::projected v18("?death_date") v15("?death_manner") v4("?death_number") v17("?death_place") 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 c27(["bd:serviceParam"]):::iri c12(["wd:Q4"]):::iri c18(["wd:Q16830671"]):::iri c29(["#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 v2 --"p:direct/P31"--> c6 v2 --"p:direct/P361"--> c8 v2 --"p:P674"--> v3 v3 --"p:statement/P674"--> v1 v3 --"p:qualifier/P793"--> c12 subgraph optional0["(optional)"] style optional0 fill:#bbf,stroke-dasharray: 5 5; v2 -."p:direct/P792".-> v4 end bind0[/"if(string-length(?death_number) = '1^^xsd:integer',concat('00',?death_number),if(string-length(?death_number) = '2^^xsd:integer',concat('0',?death_number),?death_number))"/] v4 --o bind0 bind0 --as--o v5 subgraph optional1["(optional)"] style optional1 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 optional2["(optional)"] style optional2 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 optional3["(optional)"] style optional3 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 optional4["(optional)"] style optional4 fill:#bbf,stroke-dasharray: 5 5; v3 -."p:qualifier/P5800".-> v14 end subgraph optional5["(optional)"] style optional5 fill:#bbf,stroke-dasharray: 5 5; v1 -."p:direct/P1196".-> v15 end subgraph optional6["(optional)"] style optional6 fill:#bbf,stroke-dasharray: 5 5; v1 -."p:direct/P509".-> v16 end subgraph optional7["(optional)"] style optional7 fill:#bbf,stroke-dasharray: 5 5; v1 -."p:direct/P20".-> v17 end subgraph optional8["(optional)"] style optional8 fill:#bbf,stroke-dasharray: 5 5; v1 -."p:direct/P570".-> v18 end subgraph s1["http://wikiba.se/ontology#label"] style s1 stroke-width:4px; c27 --"wikibase:language"--> c29 end