query-c66a0d87dacb8e657c2456ba8b93081f

rq turtle/ttl

Six degrees of Bush, portable but slow version

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#>
# Six degrees of Bush, portable but slow version.
#defaultView:Graph
SELECT ?item ?itemLabel ?linkTo
WHERE {
  {
    SELECT DISTINCT ?item WHERE {
      VALUES ?source { wd:Q207 }
      { ?source ( wdt:P26| wdt:P451 | wdt:P22 | wdt:P25 | wdt:P40)/
        ( wdt:P26 | wdt:P451 | wdt:P22 | wdt:P25 | wdt:P40)?/
        ( wdt:P26 | wdt:P451 | wdt:P22 | wdt:P25 | wdt:P40)?/
        ( wdt:P26 | wdt:P451 | wdt:P22 | wdt:P25 | wdt:P40)?/
        ( wdt:P26 | wdt:P451 | wdt:P22 | wdt:P25 | wdt:P40)?/
        ( wdt:P26 | wdt:P451 | wdt:P22 | wdt:P25 | wdt:P40)? ?item. }
      UNION
      { ?item ( wdt:P26 | wdt:P451 | wdt:P22 | wdt:P25 | wdt:P40)/
        ( wdt:P26 | wdt:P451 | wdt:P22 | wdt:P25 | wdt:P40)?/
        ( wdt:P26 | wdt:P451 | wdt:P22 | wdt:P25 | wdt:P40)?/
        ( wdt:P26 | wdt:P451 | wdt:P22 | wdt:P25 | wdt:P40)?/
        ( wdt:P26 | wdt:P451 | wdt:P22 | wdt:P25 | wdt:P40)?/
        ( wdt:P26 | wdt:P451 | wdt:P22 | wdt:P25 | wdt:P40)? ?source. }
    }
  }
  # We need to turn off the optimizer so that we get distinct results from the subquery,
  # otherwise the optimizer will try to do a join with duplicated values.
  ?item (wdt:P26|wdt:P451|wdt:P22|wdt:P25|wdt:P40) ?linkTo. 
  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; v2("?item"):::projected v3("?linkTo"):::projected v1("?source") a1((" ")) a2((" ")) a3((" ")) a4((" ")) a5((" ")) a6((" ")) a7((" ")) a8((" ")) a9((" ")) a10((" ")) c7(["bd:serviceParam"]):::iri c9(["#91;AUTO_LANGUAGE#93;,en"]):::literal bind0[/VALUES ?source/] bind0-->v1 bind00(["wd:Q207"]) bind00 --> bind0 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; v2 --"wdt:P40"--> a6 end subgraph union4r[" "] style union4r fill:#abf,stroke-dasharray: 3 3; v2 --"wdt:P25"--> a6 end union4r <== or ==> union4l end end subgraph union3r[" "] style union3r fill:#abf,stroke-dasharray: 3 3; v2 --"wdt:P22"--> a6 end union3r <== or ==> union3l end end subgraph union2r[" "] style union2r fill:#abf,stroke-dasharray: 3 3; v2 --"wdt:P451"--> a6 end union2r <== or ==> union2l end end subgraph union1r[" "] style union1r fill:#abf,stroke-dasharray: 3 3; v2 --"wdt:P26"--> a6 end union1r <== or ==> union1l end 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; a6 --"wdt:P40"--> a7 end subgraph union9r[" "] style union9r fill:#abf,stroke-dasharray: 3 3; a6 --"wdt:P25"--> a7 end union9r <== or ==> union9l end end subgraph union8r[" "] style union8r fill:#abf,stroke-dasharray: 3 3; a6 --"wdt:P22"--> a7 end union8r <== or ==> union8l end end subgraph union7r[" "] style union7r fill:#abf,stroke-dasharray: 3 3; a6 --"wdt:P451"--> a7 end union7r <== or ==> union7l end end subgraph union6r[" "] style union6r fill:#abf,stroke-dasharray: 3 3; a6 --"wdt:P26"--> a7 end union6r <== or ==> union6l end end subgraph union5r[" "] style union5r fill:#abf,stroke-dasharray: 3 3; end union5r <== or ==> union5l end 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; a7 --"wdt:P40"--> a8 end subgraph union14r[" "] style union14r fill:#abf,stroke-dasharray: 3 3; a7 --"wdt:P25"--> a8 end union14r <== or ==> union14l end end subgraph union13r[" "] style union13r fill:#abf,stroke-dasharray: 3 3; a7 --"wdt:P22"--> a8 end union13r <== or ==> union13l end end subgraph union12r[" "] style union12r fill:#abf,stroke-dasharray: 3 3; a7 --"wdt:P451"--> a8 end union12r <== or ==> union12l end end subgraph union11r[" "] style union11r fill:#abf,stroke-dasharray: 3 3; a7 --"wdt:P26"--> a8 end union11r <== or ==> union11l end end subgraph union10r[" "] style union10r fill:#abf,stroke-dasharray: 3 3; end union10r <== or ==> union10l end 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; subgraph union17[" Union "] subgraph union17l[" "] style union17l fill:#abf,stroke-dasharray: 3 3; subgraph union18[" Union "] subgraph union18l[" "] style union18l fill:#abf,stroke-dasharray: 3 3; subgraph union19[" Union "] subgraph union19l[" "] style union19l fill:#abf,stroke-dasharray: 3 3; a8 --"wdt:P40"--> a9 end subgraph union19r[" "] style union19r fill:#abf,stroke-dasharray: 3 3; a8 --"wdt:P25"--> a9 end union19r <== or ==> union19l end end subgraph union18r[" "] style union18r fill:#abf,stroke-dasharray: 3 3; a8 --"wdt:P22"--> a9 end union18r <== or ==> union18l end end subgraph union17r[" "] style union17r fill:#abf,stroke-dasharray: 3 3; a8 --"wdt:P451"--> a9 end union17r <== or ==> union17l end end subgraph union16r[" "] style union16r fill:#abf,stroke-dasharray: 3 3; a8 --"wdt:P26"--> a9 end union16r <== or ==> union16l end end subgraph union15r[" "] style union15r fill:#abf,stroke-dasharray: 3 3; end union15r <== or ==> union15l end subgraph union20[" Union "] subgraph union20l[" "] style union20l fill:#abf,stroke-dasharray: 3 3; subgraph union21[" Union "] subgraph union21l[" "] style union21l fill:#abf,stroke-dasharray: 3 3; subgraph union22[" Union "] subgraph union22l[" "] style union22l fill:#abf,stroke-dasharray: 3 3; subgraph union23[" Union "] subgraph union23l[" "] style union23l fill:#abf,stroke-dasharray: 3 3; subgraph union24[" Union "] subgraph union24l[" "] style union24l fill:#abf,stroke-dasharray: 3 3; a9 --"wdt:P40"--> a10 end subgraph union24r[" "] style union24r fill:#abf,stroke-dasharray: 3 3; a9 --"wdt:P25"--> a10 end union24r <== or ==> union24l end end subgraph union23r[" "] style union23r fill:#abf,stroke-dasharray: 3 3; a9 --"wdt:P22"--> a10 end union23r <== or ==> union23l end end subgraph union22r[" "] style union22r fill:#abf,stroke-dasharray: 3 3; a9 --"wdt:P451"--> a10 end union22r <== or ==> union22l end end subgraph union21r[" "] style union21r fill:#abf,stroke-dasharray: 3 3; a9 --"wdt:P26"--> a10 end union21r <== or ==> union21l end end subgraph union20r[" "] style union20r fill:#abf,stroke-dasharray: 3 3; end union20r <== or ==> union20l end subgraph union25[" Union "] subgraph union25l[" "] style union25l fill:#abf,stroke-dasharray: 3 3; subgraph union26[" Union "] subgraph union26l[" "] style union26l fill:#abf,stroke-dasharray: 3 3; subgraph union27[" Union "] subgraph union27l[" "] style union27l fill:#abf,stroke-dasharray: 3 3; subgraph union28[" Union "] subgraph union28l[" "] style union28l fill:#abf,stroke-dasharray: 3 3; subgraph union29[" Union "] subgraph union29l[" "] style union29l fill:#abf,stroke-dasharray: 3 3; a10 --"wdt:P40"--> v1 end subgraph union29r[" "] style union29r fill:#abf,stroke-dasharray: 3 3; a10 --"wdt:P25"--> v1 end union29r <== or ==> union29l end end subgraph union28r[" "] style union28r fill:#abf,stroke-dasharray: 3 3; a10 --"wdt:P22"--> v1 end union28r <== or ==> union28l end end subgraph union27r[" "] style union27r fill:#abf,stroke-dasharray: 3 3; a10 --"wdt:P451"--> v1 end union27r <== or ==> union27l end end subgraph union26r[" "] style union26r fill:#abf,stroke-dasharray: 3 3; a10 --"wdt:P26"--> v1 end union26r <== or ==> union26l end end subgraph union25r[" "] style union25r fill:#abf,stroke-dasharray: 3 3; end union25r <== or ==> union25l end end subgraph union0r[" "] style union0r fill:#abf,stroke-dasharray: 3 3; subgraph union30[" Union "] subgraph union30l[" "] style union30l fill:#abf,stroke-dasharray: 3 3; subgraph union31[" Union "] subgraph union31l[" "] style union31l fill:#abf,stroke-dasharray: 3 3; subgraph union32[" Union "] subgraph union32l[" "] style union32l fill:#abf,stroke-dasharray: 3 3; subgraph union33[" Union "] subgraph union33l[" "] style union33l fill:#abf,stroke-dasharray: 3 3; v1 --"wdt:P40"--> a1 end subgraph union33r[" "] style union33r fill:#abf,stroke-dasharray: 3 3; v1 --"wdt:P25"--> a1 end union33r <== or ==> union33l end end subgraph union32r[" "] style union32r fill:#abf,stroke-dasharray: 3 3; v1 --"wdt:P22"--> a1 end union32r <== or ==> union32l end end subgraph union31r[" "] style union31r fill:#abf,stroke-dasharray: 3 3; v1 --"wdt:P451"--> a1 end union31r <== or ==> union31l end end subgraph union30r[" "] style union30r fill:#abf,stroke-dasharray: 3 3; v1 --"wdt:P26"--> a1 end union30r <== or ==> union30l end subgraph union34[" Union "] subgraph union34l[" "] style union34l fill:#abf,stroke-dasharray: 3 3; subgraph union35[" Union "] subgraph union35l[" "] style union35l fill:#abf,stroke-dasharray: 3 3; subgraph union36[" Union "] subgraph union36l[" "] style union36l fill:#abf,stroke-dasharray: 3 3; subgraph union37[" Union "] subgraph union37l[" "] style union37l fill:#abf,stroke-dasharray: 3 3; subgraph union38[" Union "] subgraph union38l[" "] style union38l fill:#abf,stroke-dasharray: 3 3; a1 --"wdt:P40"--> a2 end subgraph union38r[" "] style union38r fill:#abf,stroke-dasharray: 3 3; a1 --"wdt:P25"--> a2 end union38r <== or ==> union38l end end subgraph union37r[" "] style union37r fill:#abf,stroke-dasharray: 3 3; a1 --"wdt:P22"--> a2 end union37r <== or ==> union37l end end subgraph union36r[" "] style union36r fill:#abf,stroke-dasharray: 3 3; a1 --"wdt:P451"--> a2 end union36r <== or ==> union36l end end subgraph union35r[" "] style union35r fill:#abf,stroke-dasharray: 3 3; a1 --"wdt:P26"--> a2 end union35r <== or ==> union35l end end subgraph union34r[" "] style union34r fill:#abf,stroke-dasharray: 3 3; end union34r <== or ==> union34l end subgraph union39[" Union "] subgraph union39l[" "] style union39l fill:#abf,stroke-dasharray: 3 3; subgraph union40[" Union "] subgraph union40l[" "] style union40l fill:#abf,stroke-dasharray: 3 3; subgraph union41[" Union "] subgraph union41l[" "] style union41l fill:#abf,stroke-dasharray: 3 3; subgraph union42[" Union "] subgraph union42l[" "] style union42l fill:#abf,stroke-dasharray: 3 3; subgraph union43[" Union "] subgraph union43l[" "] style union43l fill:#abf,stroke-dasharray: 3 3; a2 --"wdt:P40"--> a3 end subgraph union43r[" "] style union43r fill:#abf,stroke-dasharray: 3 3; a2 --"wdt:P25"--> a3 end union43r <== or ==> union43l end end subgraph union42r[" "] style union42r fill:#abf,stroke-dasharray: 3 3; a2 --"wdt:P22"--> a3 end union42r <== or ==> union42l end end subgraph union41r[" "] style union41r fill:#abf,stroke-dasharray: 3 3; a2 --"wdt:P451"--> a3 end union41r <== or ==> union41l end end subgraph union40r[" "] style union40r fill:#abf,stroke-dasharray: 3 3; a2 --"wdt:P26"--> a3 end union40r <== or ==> union40l end end subgraph union39r[" "] style union39r fill:#abf,stroke-dasharray: 3 3; end union39r <== or ==> union39l end subgraph union44[" Union "] subgraph union44l[" "] style union44l fill:#abf,stroke-dasharray: 3 3; subgraph union45[" Union "] subgraph union45l[" "] style union45l fill:#abf,stroke-dasharray: 3 3; subgraph union46[" Union "] subgraph union46l[" "] style union46l fill:#abf,stroke-dasharray: 3 3; subgraph union47[" Union "] subgraph union47l[" "] style union47l fill:#abf,stroke-dasharray: 3 3; subgraph union48[" Union "] subgraph union48l[" "] style union48l fill:#abf,stroke-dasharray: 3 3; a3 --"wdt:P40"--> a4 end subgraph union48r[" "] style union48r fill:#abf,stroke-dasharray: 3 3; a3 --"wdt:P25"--> a4 end union48r <== or ==> union48l end end subgraph union47r[" "] style union47r fill:#abf,stroke-dasharray: 3 3; a3 --"wdt:P22"--> a4 end union47r <== or ==> union47l end end subgraph union46r[" "] style union46r fill:#abf,stroke-dasharray: 3 3; a3 --"wdt:P451"--> a4 end union46r <== or ==> union46l end end subgraph union45r[" "] style union45r fill:#abf,stroke-dasharray: 3 3; a3 --"wdt:P26"--> a4 end union45r <== or ==> union45l end end subgraph union44r[" "] style union44r fill:#abf,stroke-dasharray: 3 3; end union44r <== or ==> union44l end subgraph union49[" Union "] subgraph union49l[" "] style union49l fill:#abf,stroke-dasharray: 3 3; subgraph union50[" Union "] subgraph union50l[" "] style union50l fill:#abf,stroke-dasharray: 3 3; subgraph union51[" Union "] subgraph union51l[" "] style union51l fill:#abf,stroke-dasharray: 3 3; subgraph union52[" Union "] subgraph union52l[" "] style union52l fill:#abf,stroke-dasharray: 3 3; subgraph union53[" Union "] subgraph union53l[" "] style union53l fill:#abf,stroke-dasharray: 3 3; a4 --"wdt:P40"--> a5 end subgraph union53r[" "] style union53r fill:#abf,stroke-dasharray: 3 3; a4 --"wdt:P25"--> a5 end union53r <== or ==> union53l end end subgraph union52r[" "] style union52r fill:#abf,stroke-dasharray: 3 3; a4 --"wdt:P22"--> a5 end union52r <== or ==> union52l end end subgraph union51r[" "] style union51r fill:#abf,stroke-dasharray: 3 3; a4 --"wdt:P451"--> a5 end union51r <== or ==> union51l end end subgraph union50r[" "] style union50r fill:#abf,stroke-dasharray: 3 3; a4 --"wdt:P26"--> a5 end union50r <== or ==> union50l end end subgraph union49r[" "] style union49r fill:#abf,stroke-dasharray: 3 3; end union49r <== or ==> union49l end subgraph union54[" Union "] subgraph union54l[" "] style union54l fill:#abf,stroke-dasharray: 3 3; subgraph union55[" Union "] subgraph union55l[" "] style union55l fill:#abf,stroke-dasharray: 3 3; subgraph union56[" Union "] subgraph union56l[" "] style union56l fill:#abf,stroke-dasharray: 3 3; subgraph union57[" Union "] subgraph union57l[" "] style union57l fill:#abf,stroke-dasharray: 3 3; subgraph union58[" Union "] subgraph union58l[" "] style union58l fill:#abf,stroke-dasharray: 3 3; a5 --"wdt:P40"--> v2 end subgraph union58r[" "] style union58r fill:#abf,stroke-dasharray: 3 3; a5 --"wdt:P25"--> v2 end union58r <== or ==> union58l end end subgraph union57r[" "] style union57r fill:#abf,stroke-dasharray: 3 3; a5 --"wdt:P22"--> v2 end union57r <== or ==> union57l end end subgraph union56r[" "] style union56r fill:#abf,stroke-dasharray: 3 3; a5 --"wdt:P451"--> v2 end union56r <== or ==> union56l end end subgraph union55r[" "] style union55r fill:#abf,stroke-dasharray: 3 3; a5 --"wdt:P26"--> v2 end union55r <== or ==> union55l end end subgraph union54r[" "] style union54r fill:#abf,stroke-dasharray: 3 3; end union54r <== or ==> union54l end end union0r <== or ==> union0l end subgraph union59[" Union "] subgraph union59l[" "] style union59l fill:#abf,stroke-dasharray: 3 3; subgraph union60[" Union "] subgraph union60l[" "] style union60l fill:#abf,stroke-dasharray: 3 3; subgraph union61[" Union "] subgraph union61l[" "] style union61l fill:#abf,stroke-dasharray: 3 3; subgraph union62[" Union "] subgraph union62l[" "] style union62l fill:#abf,stroke-dasharray: 3 3; v2 --"wdt:P40"--> v3 end subgraph union62r[" "] style union62r fill:#abf,stroke-dasharray: 3 3; v2 --"wdt:P25"--> v3 end union62r <== or ==> union62l end end subgraph union61r[" "] style union61r fill:#abf,stroke-dasharray: 3 3; v2 --"wdt:P22"--> v3 end union61r <== or ==> union61l end end subgraph union60r[" "] style union60r fill:#abf,stroke-dasharray: 3 3; v2 --"wdt:P451"--> v3 end union60r <== or ==> union60l end end subgraph union59r[" "] style union59r fill:#abf,stroke-dasharray: 3 3; v2 --"wdt:P26"--> v3 end union59r <== or ==> union59l end subgraph s1["http://wikiba.se/ontology#label"] style s1 stroke-width:4px; c7 --"wikibase:language"--> c9 end