query-d6444f22428fa250f706bdaab017747f

rq turtle/ttl

(19) Graph of Dream of the Red Chamber network: Jia Baoyu's relatives and their family namesNo.19 (2019.11.09T0017 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#>
# for comparison, add family name to nuclear family member and relative (all relatives)
#defaultView:Graph
SELECT ?x ?xLabel ?birthdate ?image ?y ?yLabel ?edgeLabel
WHERE {
  # define ?x as Jia Baoyu (Q8428650)'s any father (P22) or mother (P25) or child (P40) or sibling (P3373) or spouse (P26)
  # or relative (P1038) or family name (P734)'s father or mother or child or sibling or spouse or relative or family name's...
  ### Note: P734 (family name) is a dead end and can go nowhere. If family name is removed from ?x and just included in ?y, we can still get all the relatives and their family names.
  ### However, family name will have no image in graph if it is not included in ?x.
  ### This problem cannot be solved by replacing "?x" in "OPTIONAL {?x wdt:P18 ?image}" with "?y", which will result in more errors.
  ### This image issue seems fixed by adding a new line "OPTIONAL {?y wdt:P18 ?image2}". But I don't know if there is any potential error, and it is at least not simpler than just including family name in ?x.
  wd:Q8428650 (wdt:P22|wdt:P25|wdt:P40|wdt:P3373|wdt:P26|wdt:P1038|wdt:P734)* ?x
  # optional: define ?x's father (P22) or mother (P25) or child (P40) or sibling (P3373) or spouse (P26) or relative (P1038)
  # or family name (P734) as ?y
  OPTIONAL {?x (wdt:P22|wdt:P25|wdt:P40|wdt:P3373|wdt:P26|wdt:P1038|wdt:P734) ?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 relative (P1038)
            # or family name (P734)
            VALUES ?relation {wdt:P22 wdt:P25 wdt:P40 wdt:P3373 wdt:P26 wdt:P1038 wdt:P734}
            # ?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 birthdate (P569), which only appears in table, not graph
  OPTIONAL {?x wdt:P569 ?birthdate}
  # 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("?birthdate"):::projected v4("?edge") v6("?image"):::projected v3("?relation") v1("?x"):::projected v2("?y"):::projected c11(["wikibase:Property"]):::iri c17(["zh-hans,en"]):::literal c1(["wd:Q8428650"]):::iri c15(["bd:serviceParam"]):::iri 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; 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; c1 --"wdt:P734"--> v1 end subgraph union5r[" "] style union5r fill:#abf,stroke-dasharray: 3 3; c1 --"wdt:P1038"--> v1 end union5r <== or ==> union5l end end subgraph union4r[" "] style union4r fill:#abf,stroke-dasharray: 3 3; c1 --"wdt:P26"--> v1 end union4r <== or ==> union4l end end subgraph union3r[" "] style union3r fill:#abf,stroke-dasharray: 3 3; c1 --"wdt:P3373"--> v1 end union3r <== or ==> union3l end end subgraph union2r[" "] style union2r fill:#abf,stroke-dasharray: 3 3; c1 --"wdt:P40"--> v1 end union2r <== or ==> union2l end end subgraph union1r[" "] style union1r fill:#abf,stroke-dasharray: 3 3; c1 --"wdt:P25"--> v1 end union1r <== or ==> union1l end end subgraph union0r[" "] style union0r fill:#abf,stroke-dasharray: 3 3; c1 --"wdt:P22"--> v1 end union0r <== or ==> union0l end subgraph optional0["(optional)"] style optional0 fill:#bbf,stroke-dasharray: 5 5; 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; v1 -."wdt:P734".-> v2 end subgraph union11r[" "] style union11r fill:#abf,stroke-dasharray: 3 3; v1 --"wdt:P1038"--> v2 end union11r <== or ==> union11l end end subgraph union10r[" "] style union10r fill:#abf,stroke-dasharray: 3 3; v1 --"wdt:P26"--> v2 end union10r <== or ==> union10l end end subgraph union9r[" "] style union9r fill:#abf,stroke-dasharray: 3 3; v1 --"wdt:P3373"--> v2 end union9r <== or ==> union9l end end subgraph union8r[" "] style union8r fill:#abf,stroke-dasharray: 3 3; v1 --"wdt:P40"--> v2 end union8r <== or ==> union8l end end subgraph union7r[" "] style union7r fill:#abf,stroke-dasharray: 3 3; v1 --"wdt:P25"--> v2 end union7r <== or ==> union7l end end subgraph union6r[" "] style union6r fill:#abf,stroke-dasharray: 3 3; v1 --"wdt:P22"--> v2 end union6r <== or ==> union6l end bind0[/VALUES ?relation/] bind0-->v3 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:P1038"]) bind05 --> bind0 bind06(["wdt:P734"]) bind06 --> bind0 v1 -->v3--> v2 v4 --"wikibase:directClaim"--> v3 v4 --"a"--> c11 end subgraph optional1["(optional)"] style optional1 fill:#bbf,stroke-dasharray: 5 5; v1 -."wdt:P569".-> v5 end subgraph optional2["(optional)"] style optional2 fill:#bbf,stroke-dasharray: 5 5; v1 -."wdt:P18".-> v6 end subgraph s1["http://wikiba.se/ontology#label"] style s1 stroke-width:4px; c15 --"wikibase:language"--> c17 end