query-004f58757a620c1f042edcd9b035fd21

rq turtle/ttl

(39) Graph of blood relatives: Jia BaoyuNo.39 (2020.07.15T0642 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#>
# find Jia Baoyu's blood relatives, i.e., those who share a common ancestor with Jia Baoyu
### Note: previous section "Graph of lineal ancestors/descendants: Daoguang Emperor" does not have any subsection for blood relatives
#defaultView:Graph
SELECT DISTINCT ?blood_relative ?blood_relativeLabel ?birthdate ?image ?parent ?parentLabel ?edgeLabel
WHERE {
  # define ?ancestor as Jia Baoyu (Q8428650)'s any father (P22) or mother (P25)'s father or mother's...
  wd:Q8428650 (wdt:P22|wdt:P25)* ?ancestor.
  # define ?blood_relative as one whose any father (P22) or mother (P25)'s father or mother's... is ?ancestor
  ?blood_relative (wdt:P22|wdt:P25)* ?ancestor
  # optional: define ?blood_relative's father (P22) or mother (P25) as ?parent
  OPTIONAL {?blood_relative (wdt:P22|wdt:P25) ?parent.
           # To eliminate blood relative's parent who is not Jia Baoyu's blood relative,
           # require that ?parent's any father (P22) or mother (P25)'s father or mother's... is ?ancestor
          ?parent (wdt:P22|wdt:P25)* ?ancestor
           # To avoid showing any other relation,
           # define ?relation as father (P22) or mother (P25)
           VALUES ?relation {wdt:P22 wdt:P25}
           # ?relation is from ?blood_relative to ?parent
           ?blood_relative ?relation ?parent.
           # get ?relation's property label and allow it to appear on graph edge
           ?edge wikibase:directClaim ?relation;
               a wikibase:Property}
  # optional: show ?blood_relative's birthdate (P569), which only appears in table, not graph
  OPTIONAL {?blood_relative wdt:P569 ?birthdate}
  # optional: show ?blood_relative's image (P18), which appears directly in graph, and as link in table
  OPTIONAL {?blood_relative wdt:P18 ?image}
  # 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("?ancestor") v6("?birthdate"):::projected v2("?blood_relative"):::projected v5("?edge") v7("?image"):::projected v3("?parent"):::projected v4("?relation") c10(["bd:serviceParam"]):::iri c6(["wikibase:Property"]):::iri c12(["#91;AUTO_LANGUAGE#93;,en"]):::literal c1(["wd:Q8428650"]):::iri subgraph union0[" Union "] subgraph union0l[" "] style union0l fill:#abf,stroke-dasharray: 3 3; c1 --"wdt:P25"--> v1 end subgraph union0r[" "] style union0r fill:#abf,stroke-dasharray: 3 3; c1 --"wdt:P22"--> v1 end union0r <== or ==> union0l end subgraph union1[" Union "] subgraph union1l[" "] style union1l fill:#abf,stroke-dasharray: 3 3; v2 --"wdt:P25"--> v1 end subgraph union1r[" "] style union1r fill:#abf,stroke-dasharray: 3 3; v2 --"wdt:P22"--> v1 end union1r <== or ==> union1l end subgraph optional0["(optional)"] style optional0 fill:#bbf,stroke-dasharray: 5 5; subgraph union2[" Union "] subgraph union2l[" "] style union2l fill:#abf,stroke-dasharray: 3 3; v2 -."wdt:P25".-> v3 end subgraph union2r[" "] style union2r fill:#abf,stroke-dasharray: 3 3; v2 --"wdt:P22"--> v3 end union2r <== or ==> union2l end subgraph union3[" Union "] subgraph union3l[" "] style union3l fill:#abf,stroke-dasharray: 3 3; v3 --"wdt:P25"--> v1 end subgraph union3r[" "] style union3r fill:#abf,stroke-dasharray: 3 3; v3 --"wdt:P22"--> v1 end union3r <== or ==> union3l end bind0[/VALUES ?relation/] bind0-->v4 bind00(["wdt:P22"]) bind00 --> bind0 bind01(["wdt:P25"]) bind01 --> bind0 v2 -->v4--> v3 v5 --"wikibase:directClaim"--> v4 v5 --"a"--> c6 end subgraph optional1["(optional)"] style optional1 fill:#bbf,stroke-dasharray: 5 5; v2 -."wdt:P569".-> v6 end subgraph optional2["(optional)"] style optional2 fill:#bbf,stroke-dasharray: 5 5; v2 -."wdt:P18".-> v7 end subgraph s1["http://wikiba.se/ontology#label"] style s1 stroke-width:4px; c10 --"wikibase:language"--> c12 end