query-46f2715306ac7dce0093058b66afa631

rq turtle/ttl

Knowledge graph). Given a list of Wikidata items provided in a VALUES array, use a SPARQL query to find all the relationships among them and then graph them. link) and optimized by Lucas Werkmeister (linkThis is a neat query that creates a connected graph of Wikidata items first posed by Martin Poulter (Knowledge graph of Death of Socrates from The Met

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#>
#defaultView:Graph
SELECT ?item1 ?image1 ?item1Label ?item2 ?image2 ?item2Label ?edgeLabel 


WHERE {
   {
  SELECT ?item1 WHERE {
    VALUES ?item1 { wd:Q913 wd:Q186953 wd:Q3110066 wd:Q1752990 wd:Q5597 wd:Q83155 wd:Q51955019 wd:Q20539433 }
  }
}
   {
  SELECT (?item1 AS ?item2) WHERE {
     {
  SELECT ?item1 WHERE {
    VALUES ?item1 { wd:Q913 wd:Q186953 wd:Q3110066 wd:Q1752990 wd:Q5597 wd:Q83155 wd:Q51955019 wd:Q20539433 }
  }
}
  }
}
  ?item1 ?wdt ?item2.
  ?edge wikibase:directClaim ?wdt;
        a wikibase:Property.
  OPTIONAL { ?item1 wdt:P18 ?image1. }
  OPTIONAL { ?item2 wdt:P18 ?image2. }
  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; v4("?edge") v5("?image1"):::projected v6("?image2"):::projected v2("?item1"):::projected v2("?item2"):::projected v3("?wdt") c6(["bd:serviceParam"]):::iri c3(["wikibase:Property"]):::iri c8(["#91;AUTO_LANGUAGE#93;,en"]):::literal bind0[/VALUES ?item1/] bind0-->v2 bind00(["wd:Q913"]) bind00 --> bind0 bind01(["wd:Q186953"]) bind01 --> bind0 bind02(["wd:Q3110066"]) bind02 --> bind0 bind03(["wd:Q1752990"]) bind03 --> bind0 bind04(["wd:Q5597"]) bind04 --> bind0 bind05(["wd:Q83155"]) bind05 --> bind0 bind06(["wd:Q51955019"]) bind06 --> bind0 bind07(["wd:Q20539433"]) bind07 --> bind0 bind1[/VALUES ?item1/] bind1-->v2 bind10(["wd:Q913"]) bind10 --> bind1 bind11(["wd:Q186953"]) bind11 --> bind1 bind12(["wd:Q3110066"]) bind12 --> bind1 bind13(["wd:Q1752990"]) bind13 --> bind1 bind14(["wd:Q5597"]) bind14 --> bind1 bind15(["wd:Q83155"]) bind15 --> bind1 bind16(["wd:Q51955019"]) bind16 --> bind1 bind17(["wd:Q20539433"]) bind17 --> bind1 bind2[/"?item1"/] v2 --o bind2 bind2 --as--o v2 v2 -->v3--> v2 v4 --"wikibase:directClaim"--> v3 v4 --"a"--> c3 subgraph optional0["(optional)"] style optional0 fill:#bbf,stroke-dasharray: 5 5; v2 -."wdt:P18".-> v5 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; c6 --"wikibase:language"--> c8 end