query-0b3f82f5c06de2ea08feb1ba756ec92c

rq turtle/ttl

Using the results of a search as a series of properties to useI would like to see the urls of heritage register entries for places, but there are a lot worldwide, so I wanted to use a query to generate the property list to search. So for castles in Kent I'd look for UK registers. Something like

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 p: <http://www.wikidata.org/prop/>
PREFIX bd: <http://www.bigdata.com/rdf#>
SELECT DISTINCT ?castleLabel ?registerLabel ?URLprefix ?entry WHERE {
  SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE]". }
  {
    SELECT DISTINCT ?castle ?register ?URLprefix ?entry WHERE {
      ?register p:P31 ?statement0.
      ?statement0 (ps:P31/(wdt:P279*)) wd:Q18618628.
      ?register p:P17 ?country.
      ?country (ps:P17/(wdt:P279*)) wd:Q145.
      ?register wdt:P1630 ?URLprefix. 
      ?castle p:P31 ?statement1.
      ?statement1 (ps:P31/(wdt:P279*)) wd:Q23413.
      ?castle p:P7959 ?county.
      ?county (ps:P7959/(wdt:P279*)) wd:Q67479626.
      # pseudo code
      #?castle wdt:p?register ?entry .
    }
  }
}

Query found at

graph TD classDef projected fill:lightgreen; classDef literal fill:orange; classDef iri fill:yellow; v4("?URLprefix"):::projected v5("?castle") v3("?country") v7("?county") v1("?register") v2("?statement0") v6("?statement1") a1((" ")) a2((" ")) a3((" ")) a4((" ")) c16(["wd:Q67479626"]):::iri c13(["wd:Q23413"]):::iri c2(["bd:serviceParam"]):::iri c4(["#91;AUTO_LANGUAGE#93;"]):::literal c8(["wd:Q18618628"]):::iri c11(["wd:Q145"]):::iri subgraph s1["http://wikiba.se/ontology#label"] style s1 stroke-width:4px; c2 --"wikibase:language"--> c4 end v1 --"p:P31"--> v2 v2 --"p:statement/P31"--> a1 a1 --"p:direct/P279"--> c8 v1 --"p:P17"--> v3 v3 --"p:statement/P17"--> a2 a2 --"p:direct/P279"--> c11 v1 --"p:direct/P1630"--> v4 v5 --"p:P31"--> v6 v6 --"p:statement/P31"--> a3 a3 --"p:direct/P279"--> c13 v5 --"p:P7959"--> v7 v7 --"p:statement/P7959"--> a4 a4 --"p:direct/P279"--> c16