query-06f1f6432696c8cb0cf731ff9e6f5e1b

rq turtle/ttl

(26) Graph of an expanded fictional universe: Dream of the Red ChamberNo.26 (2019.11.12T0056 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 bd: <http://www.bigdata.com/rdf#>
# expand the Dream of the Red Chamber Universe ?x to ?x_ by adding family name, then find the relations between entities within ?x_, i.e.,
# ?x_ is the same size as ?y, and is larger than ?x in size, so that all the entities in ?x_ can have image.
# in comparison with "Jia Baoyu's relatives and teachers/students and roommates as well as their family names and residences", this query 
# removes relative (P1038, too flexible, hard to define, may generate even stronger connection than nuclear family), and
# adds member of (P463, for Haitang Poets Society), work location (P937, for servants), location (P276, for Haitang Poets society, events, buildings, etc.), and
# participant of (P1344) and participant (P710) for events
#defaultView:Graph
SELECT DISTINCT ?x_ ?x_Label ?image ?y ?yLabel ?edgeLabel
WHERE {
  # define ?x as what is present in work (P1441) Dream of the Red Chamber (Q8265)
  ?x wdt:P1441 wd:Q8265;
  # use "?" to expand ?x to ?x_, which includes ?x's family name (P734)
     wdt:P734? ?x_
  # optional: define ?y as ?x_'s father (P22) or mother (P25) or child (P40) or sibling (P3373) or spouse (P26), i.e., nuclear family member,
  # or teacher (P1066) or student (P802) or member of (P463) or family name (P734)
  # or residence (P551) or occupant (P466) or work location (P937) or location (P276) or part of (P361) or has part (P527)
  # or participant of (P1344) or participant (P710)
  OPTIONAL {?x_ (wdt:P22|wdt:P25 |wdt:P40 |wdt:P3373 |wdt:P26 |wdt:P1066 |wdt:P802 |wdt:P463 |wdt:P734 |wdt:P551 |wdt:P466 |wdt:P937 |wdt:P276 |wdt:P361 |wdt:P527 |wdt:P1344 |wdt:P710) ?y
            # To avoid showing any other relation
            # define ?relation as only father (P22) or mother (P25) or child (P40) or sibling (P3373) or spouse (P26)
            # or teacher (P1066) or student (P802) or member of (P463) or family name (P734)
            # or residence (P551) or occupant (P466) or work location (P937) or location (P276) or part of (P361) or has part (P527)
            # or participant of (P1344) or participant (P710)
            VALUES ?relation {wdt:P22 wdt:P25 wdt:P40 wdt:P3373 wdt:P26 wdt:P1066 wdt:P802 wdt:P463 wdt:P734 wdt:P551 wdt:P466 wdt:P937 wdt:P276 wdt:P361 wdt:P527 wdt:P1344 wdt:P710}
            # ?relation is from ?x_ to ?y
            ?x_ ?relation ?y.
            # show ?relation on graph edges
            ?edge wikibase:directClaim ?relation;
               a wikibase:Property}
  # optional: show ?x_'s image (P18), which appears directly in graph, and as link in table
  OPTIONAL {?x_ wdt:P18 ?image}
  # show label in simplified Chinese (zh-hans) as default, and English when no default label exists
  SERVICE wikibase:label { bd:serviceParam wikibase:language "zh-hans,en". }
}

Query found at

graph TD classDef projected fill:lightgreen; classDef literal fill:orange; classDef iri fill:yellow; v5("?edge") v6("?image"):::projected v4("?relation") v1("?x") v2("?x_"):::projected v3("?y"):::projected c22(["wikibase:Property"]):::iri c27(["zh-hans,en"]):::literal c25(["bd:serviceParam"]):::iri c2(["wd:Q8265"]):::iri v1 --"wdt:P1441"--> c2 subgraph union0[" Union "] subgraph union0l[" "] style union0l fill:#abf,stroke-dasharray: 3 3; v1 --"wdt:P734"--> v2 end subgraph union0r[" "] style union0r fill:#abf,stroke-dasharray: 3 3; end union0r <== or ==> union0l end subgraph optional0["(optional)"] style optional0 fill:#bbf,stroke-dasharray: 5 5; subgraph union1[" Union "] subgraph union1l[" "] style union1l fill:#abf,stroke-dasharray: 3 3; 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; subgraph union4[" Union "] subgraph union4l[" "] style union4l fill:#abf,stroke-dasharray: 3 3; subgraph union5[" Union "] subgraph union5l[" "] style union5l fill:#abf,stroke-dasharray: 3 3; subgraph union6[" Union "] subgraph union6l[" "] style union6l fill:#abf,stroke-dasharray: 3 3; subgraph union7[" Union "] subgraph union7l[" "] style union7l fill:#abf,stroke-dasharray: 3 3; subgraph union8[" Union "] subgraph union8l[" "] style union8l fill:#abf,stroke-dasharray: 3 3; subgraph union9[" Union "] subgraph union9l[" "] style union9l fill:#abf,stroke-dasharray: 3 3; subgraph union10[" Union "] subgraph union10l[" "] style union10l fill:#abf,stroke-dasharray: 3 3; subgraph union11[" Union "] subgraph union11l[" "] style union11l fill:#abf,stroke-dasharray: 3 3; subgraph union12[" Union "] subgraph union12l[" "] style union12l fill:#abf,stroke-dasharray: 3 3; subgraph union13[" Union "] subgraph union13l[" "] style union13l fill:#abf,stroke-dasharray: 3 3; subgraph union14[" Union "] subgraph union14l[" "] style union14l fill:#abf,stroke-dasharray: 3 3; subgraph union15[" Union "] subgraph union15l[" "] style union15l fill:#abf,stroke-dasharray: 3 3; subgraph union16[" Union "] subgraph union16l[" "] style union16l fill:#abf,stroke-dasharray: 3 3; v2 -."wdt:P710".-> v3 end subgraph union16r[" "] style union16r fill:#abf,stroke-dasharray: 3 3; v2 --"wdt:P1344"--> v3 end union16r <== or ==> union16l end end subgraph union15r[" "] style union15r fill:#abf,stroke-dasharray: 3 3; v2 --"wdt:P527"--> v3 end union15r <== or ==> union15l end end subgraph union14r[" "] style union14r fill:#abf,stroke-dasharray: 3 3; v2 --"wdt:P361"--> v3 end union14r <== or ==> union14l end end subgraph union13r[" "] style union13r fill:#abf,stroke-dasharray: 3 3; v2 --"wdt:P276"--> v3 end union13r <== or ==> union13l end end subgraph union12r[" "] style union12r fill:#abf,stroke-dasharray: 3 3; v2 --"wdt:P937"--> v3 end union12r <== or ==> union12l end end subgraph union11r[" "] style union11r fill:#abf,stroke-dasharray: 3 3; v2 --"wdt:P466"--> v3 end union11r <== or ==> union11l end end subgraph union10r[" "] style union10r fill:#abf,stroke-dasharray: 3 3; v2 --"wdt:P551"--> v3 end union10r <== or ==> union10l end end subgraph union9r[" "] style union9r fill:#abf,stroke-dasharray: 3 3; v2 --"wdt:P734"--> v3 end union9r <== or ==> union9l end end subgraph union8r[" "] style union8r fill:#abf,stroke-dasharray: 3 3; v2 --"wdt:P463"--> v3 end union8r <== or ==> union8l end end subgraph union7r[" "] style union7r fill:#abf,stroke-dasharray: 3 3; v2 --"wdt:P802"--> v3 end union7r <== or ==> union7l end end subgraph union6r[" "] style union6r fill:#abf,stroke-dasharray: 3 3; v2 --"wdt:P1066"--> v3 end union6r <== or ==> union6l end end subgraph union5r[" "] style union5r fill:#abf,stroke-dasharray: 3 3; v2 --"wdt:P26"--> v3 end union5r <== or ==> union5l end end subgraph union4r[" "] style union4r fill:#abf,stroke-dasharray: 3 3; v2 --"wdt:P3373"--> v3 end union4r <== or ==> union4l end end subgraph union3r[" "] style union3r fill:#abf,stroke-dasharray: 3 3; v2 --"wdt:P40"--> v3 end union3r <== or ==> union3l end end subgraph union2r[" "] style union2r fill:#abf,stroke-dasharray: 3 3; v2 --"wdt:P25"--> v3 end union2r <== or ==> union2l end end subgraph union1r[" "] style union1r fill:#abf,stroke-dasharray: 3 3; v2 --"wdt:P22"--> v3 end union1r <== or ==> union1l end bind0[/VALUES ?relation/] bind0-->v4 bind00(["wdt:P22"]) bind00 --> bind0 bind01(["wdt:P25"]) bind01 --> bind0 bind02(["wdt:P40"]) bind02 --> bind0 bind03(["wdt:P3373"]) bind03 --> bind0 bind04(["wdt:P26"]) bind04 --> bind0 bind05(["wdt:P1066"]) bind05 --> bind0 bind06(["wdt:P802"]) bind06 --> bind0 bind07(["wdt:P463"]) bind07 --> bind0 bind08(["wdt:P734"]) bind08 --> bind0 bind09(["wdt:P551"]) bind09 --> bind0 bind010(["wdt:P466"]) bind010 --> bind0 bind011(["wdt:P937"]) bind011 --> bind0 bind012(["wdt:P276"]) bind012 --> bind0 bind013(["wdt:P361"]) bind013 --> bind0 bind014(["wdt:P527"]) bind014 --> bind0 bind015(["wdt:P1344"]) bind015 --> bind0 bind016(["wdt:P710"]) bind016 --> bind0 v2 -->v4--> v3 v5 --"wikibase:directClaim"--> v4 v5 --"a"--> c22 end subgraph optional1["(optional)"] style optional1 fill:#bbf,stroke-dasharray: 5 5; v2 -."wdt:P18".-> v6 end subgraph s1["http://wikiba.se/ontology#label"] style s1 stroke-width:4px; c25 --"wikibase:language"--> c27 end