query-a2eb5231b43243ec75ccb48892dca182

rq turtle/ttl

Speeding up a query of the heritage properties of castles (P12823)‎Burgenwelt ID Do you have any suggestions how to speed this up, which given a list of 500 British castles tries to find out their heritage register properties. If I restrict the registers to UK only, it runs in 25s, but I ideally I want the register to be international, 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 rdfs: <http://www.w3.org/2000/01/rdf-schema#>
PREFIX pq: <http://www.wikidata.org/prop/qualifier/>
PREFIX bd: <http://www.bigdata.com/rdf#>
SELECT DISTINCT ?item ?itemLabel ?type 
  (CONCAT("+",STR(COALESCE(?pointintime,?starttime))) AS ?start)
  ?description ?notes ?link ?title ?keywords WHERE {
  SERVICE wikibase:label { bd:serviceParam wikibase:language "en-GB,en,fr,de,es,pt,pl,nl,cs". }
  { 
    SELECT DISTINCT ?item ?type ?pointintime ?starttime ?description ?notes ?link ?title ?keywords WHERE {
# places that need tripadvisor entries to be notable
VALUES ?notable {wd:Q23413 wd:Q16748868} # castle, city walls

?item wdt:P31/wdt:P279* ?notable.
?item wdt:P3134 ?tripadvisor.

?item wdt:P17 wd:Q145.

VALUES ?registerclass {
 wd:Q18618628 # cultural heritage
  wd:Q19829908 # places
  wd:Q22964288 # military
  wd:Q23779665 # maritime
  wd:Q74568206 # archives
}
      {
          ?registerclass ^wdt:P31 ?register.

         ?register wikibase:claim ?claim .
          ?register wikibase:statementProperty ?value.

          ?item ?claim ?stat .
          ?stat ?value ?entry .
          OPTIONAL {
          ?register wdt:P2378 ?issuer.
          ?issuer rdfs:label ?issuerlabel. FILTER (LANG(?issuerlabel) = "en")
          ?register wdt:P1630 ?URLprefix.
                  {?stat pq:P1435 ?caveat.} # heritage designation
            UNION {?stat pq:P518  ?caveat}  # applies to part
            UNION {?stat pq:P1810 ?caveat}  # subject named as
            ?caveat rdfs:label ?caveatlabel1. FILTER (LANG(?caveatlabel1) = "en")
          }
          BIND (IF(BOUND(?caveatlabel1),?caveatlabel1,"entry") AS ?caveatlabel2)

          BIND(CONCAT("[[d:Special:EntityPage/",STR(?ISSUERLABEL),"|",STR(?ISSUERLABEL),"]] [[:Template:Website]]") AS ?description)
        }
    }
  }
}

Query found at

graph TD classDef projected fill:lightgreen; classDef literal fill:orange; classDef iri fill:yellow; v13("?URLprefix") v14("?caveat") v6("?caveatlabel1") v15("?caveatlabel2") v8("?claim") v16("?description"):::projected v11("?entry") v12("?issuer") v5("?issuerlabel") v2("?item"):::projected v1("?notable") v7("?register") v4("?registerclass") v17("?start") v10("?stat") v3("?tripadvisor") v9("?value") a1((" ")) c4(["en-GB,en,fr,de,es,pt,pl,nl,cs"]):::literal c2(["bd:serviceParam"]):::iri c9(["wd:Q145"]):::iri subgraph s1["http://wikiba.se/ontology#label"] style s1 stroke-width:4px; c2 --"wikibase:language"--> c4 end bind0[/VALUES ?notable/] bind0-->v1 bind00(["wd:Q23413"]) bind00 --> bind0 bind01(["wd:Q16748868"]) bind01 --> bind0 v2 --"wdt:P31"--> a1 a1 --"wdt:P279"--> v1 v2 --"wdt:P3134"--> v3 v2 --"wdt:P17"--> c9 bind1[/VALUES ?registerclass/] bind1-->v4 bind10(["wd:Q18618628"]) bind10 --> bind1 bind11(["wd:Q19829908"]) bind11 --> bind1 bind12(["wd:Q22964288"]) bind12 --> bind1 bind13(["wd:Q23779665"]) bind13 --> bind1 bind14(["wd:Q74568206"]) bind14 --> bind1 v7 --"wdt:P31"--> v4 v7 --"wikibase:claim"--> v8 v7 --"wikibase:statementProperty"--> v9 v2 -->v8--> v10 v10 -->v9--> v11 subgraph optional0["(optional)"] style optional0 fill:#bbf,stroke-dasharray: 5 5; v7 -."wdt:P2378".-> v12 v12 --"rdfs:label"--> v5 v7 --"wdt:P1630"--> v13 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; v10 --"pq:P1810"--> v14 end subgraph union1r[" "] style union1r fill:#abf,stroke-dasharray: 3 3; v10 --"pq:P518"--> v14 end union1r <== or ==> union1l end end subgraph union0r[" "] style union0r fill:#abf,stroke-dasharray: 3 3; v10 --"pq:P1435"--> v14 end union0r <== or ==> union0l end v14 --"rdfs:label"--> v6 end bind2[/"if(bound(?caveatlabel1),?caveatlabel1,'entry')"/] v6 --o bind2 bind2 --as--o v15 bind3[/"concat('#91;#91;d:Special:EntityPage/',str(?ISSUERLABEL),'|',str(?ISSUERLABEL),'#93;#93; #91;#91;:Template:Website#93;#93;')"/] null --o bind3 bind3 --as--o v16 bind4[/"concat('+',str(?pointintime?starttime))"/] null --o bind4 null --o bind4 bind4 --as--o v17