query-b6b21b5007053f297ca06093698da31d

rq turtle/ttl

(44) Graph of shifus and parents among xiangsheng performers: the use of UNIONNo.44 (2020.07.19T0057 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#>
# graph of shifus and parents among xiangsheng performers (also viewable as table)
# querying qualifiers
#defaultView:Graph
SELECT DISTINCT ?xiangsheng_performer ?xiangsheng_performerLabel ?birthdate ?image ?shifu_or_parent ?shifu_or_parentLabel ?edgeLabel
WHERE {
  # define ?xiangsheng_performer as one that has teacher (P1066) or student (P802) in the shifu-disciple relationship of xiangsheng performers (Q10436443)
  # 1. ?xiangsheng_performer's "teacher" (P1066) or "student" (P802) statement is ?x1
  ?xiangsheng_performer (p:P1066|p:P802) ?x1.
  # 2. ?x1's qualifier "criterion used" (P1013) is shifu-disciple relationship of xiangsheng performers (Q10436443)
  ?x1 pq:P1013 wd:Q10436443
  # optional: show ?shifu_or_parent, which has teacher (P1066) or student (P802) in the shifu-disciple relationship of xiangsheng performers (Q10436443), same as ?xiangsheng_performer
  # 1. ?shifu_or_parent's "teacher" (P1066) or "student" (P802) statement is ?x2
  OPTIONAL {?shifu_or_parent (p:P1066|p:P802) ?x2.
            # 2. ?x2's qualifier "criterion used" (P1013) is shifu-disciple relationship of xiangsheng performers (Q10436443)
            ?x2 pq:P1013 wd:Q10436443
            # ?shifu_or_parent is ?xiangsheng_performer's teacher (P1066) in the shifu-disciple relationship of xiangsheng performers (Q10436443)
            # 1. ?xiangsheng_performer's "teacher" (P1066) statement is ?x3
            { ?xiangsheng_performer p:P1066 ?x3.
              # 2. ?x3's value is ?shifu_or_parent
              ?x3 ps:P1066 ?shifu_or_parent;
              # 3. ?x3's qualifier "criterion used" (P1013) is shifu-disciple relationship of xiangsheng performers (Q10436443)
                  pq:P1013 wd:Q10436443} 
            # OR ?shifu_or_parent is ?xiangsheng_performer's father (P22) or mother (P25)
            ### Note: UNION has to be used. If divided into two OPTIONALs and not using UNION,
            ### when an optional variable (?shifu_or_parent or ?edge) has values in both OPTIONALs, i.e.,
            ### a xiangsheng performer (?xiangsheng_performer) has both teacher(s) in shifu-disciple relationship (P1066 qualified by Q10436443) and father/mother (P22/P25)
            ### as optional variable ?shifu_or_parent (even if ?edge is removed) 
            ### or as optional variable ?edge (even if ?shifu_or_parent is split into ?shifu and ?parent),
            ### only those in the first OPTIONAL can be shown (sequence matters!).
            UNION {?xiangsheng_performer (wdt:P22|wdt:P25) ?shifu_or_parent}
            # to avoid showing any other relation,
            # define ?relation as teacher (P1066) or father (P22) or mother (P25)
            ### Note: When property is used as main value in the form of "p" and "ps" (as P1066 in this query), the property label can be got as a normal main value (wdt).
            ### When property is used as qualifier (pq), the property label can not be got (see previous query "Graph of position holders by succession: presidents of the United States"), and
            ### it doesn't work to define ?relation as a group of properties from ?a to ?b and get ?relation's property label. However,
            ### UNION can be used for more than one edgeLabel to solve the issue, which does not exist in this query. 
            VALUES ?relation {wdt:P1066 wdt:P22 wdt:P25}
            # ?relation is from ?xiangsheng_performer to ?shifu_or_parent
            ?xiangsheng_performer ?relation ?shifu_or_parent.
            # get ?relation's property label and allow it to appear on graph edge
            ?edge wikibase:directClaim ?relation;
                a wikibase:Property}
  # optional: show ?xiangsheng_performer's birthdate (P569), which only appears in table, not graph
  OPTIONAL {?xiangsheng_performer wdt:P569 ?birthdate}
  # optional: show ?xiangsheng_performer's image (P18), which appears directly in graph, and as link in table
  OPTIONAL {?xiangsheng_performer 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; v8("?birthdate"):::projected v7("?edge") v9("?image"):::projected v6("?relation") v3("?shifu_or_parent"):::projected v2("?x1") v4("?x2") v5("?x3") v1("?xiangsheng_performer"):::projected c4(["wd:Q10436443"]):::iri c10(["wikibase:Property"]):::iri c14(["bd:serviceParam"]):::iri c16(["#91;AUTO_LANGUAGE#93;,en"]):::literal subgraph union0[" Union "] subgraph union0l[" "] style union0l fill:#abf,stroke-dasharray: 3 3; v1 --"p:P802"--> v2 end subgraph union0r[" "] style union0r fill:#abf,stroke-dasharray: 3 3; v1 --"p:P1066"--> v2 end union0r <== or ==> union0l end v2 --"p:qualifier/P1013"--> c4 subgraph optional0["(optional)"] style optional0 fill:#bbf,stroke-dasharray: 5 5; subgraph union1[" Union "] subgraph union1l[" "] style union1l fill:#abf,stroke-dasharray: 3 3; v3 -."p:P802".-> v4 end subgraph union1r[" "] style union1r fill:#abf,stroke-dasharray: 3 3; v3 --"p:P1066"--> v4 end union1r <== or ==> union1l end v4 --"p:qualifier/P1013"--> c4 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; v1 --"p:direct/P25"--> v3 end subgraph union3r[" "] style union3r fill:#abf,stroke-dasharray: 3 3; v1 --"p:direct/P22"--> v3 end union3r <== or ==> union3l end end subgraph union2r[" "] style union2r fill:#abf,stroke-dasharray: 3 3; v1 --"p:P1066"--> v5 v5 --"p:statement/P1066"--> v3 v5 --"p:qualifier/P1013"--> c4 end union2r <== or ==> union2l end bind0[/VALUES ?relation/] bind0-->v6 bind00(["p:direct/P1066"]) bind00 --> bind0 bind01(["p:direct/P22"]) bind01 --> bind0 bind02(["p:direct/P25"]) bind02 --> bind0 v1 -->v6--> v3 v7 --"wikibase:directClaim"--> v6 v7 --"a"--> c10 end subgraph optional1["(optional)"] style optional1 fill:#bbf,stroke-dasharray: 5 5; v1 -."p:direct/P569".-> v8 end subgraph optional2["(optional)"] style optional2 fill:#bbf,stroke-dasharray: 5 5; v1 -."p:direct/P18".-> v9 end subgraph s1["http://wikiba.se/ontology#label"] style s1 stroke-width:4px; c14 --"wikibase:language"--> c16 end