query-af7c4d294e268654fb8a434b05ed7bdd

rq turtle/ttl

Some sort of optimisation fail, I fear. Oddly, implementng VALUES in a named subquery seems to get over the problem.Making progress, but have 2 issues. 1) I'd like to only do the distance check if ?range1 were declared 2) I get a "bad aggregate" when trying to combine ?type1 and ?type2 preferentially

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#>
SELECT DISTINCT ?item ?itemLabel (COALESCE(SAMPLE (DISTINCT ?type1), SAMPLE (DISTINCT ?type2)) AS ?type)
WHERE {
  SERVICE wikibase:label { bd:serviceParam wikibase:language "en-GB,en,fr,de,es,pt,pl,nl,cs". }
  {wd:Q1180981 wdt:P625 ?loc1} UNION {wd:Q1180981 wdt:P276 ?loc. ?loc wdt:P625 ?loc1}
  ?item wdt:P17 wd:Q145.
  { {
  SELECT ?instances ?classes (IF(BOUND(?range1),?range1,"100") AS ?range) WHERE {
    #### THIS BIT IN INCLUDED FILE, MANY EXAMPLES ####
    VALUES ?instances {
      wd:Q2772772 # military museum
    }
    VALUES ?classes {
      wd:Q1785071  # fort
      wd:Q91122    # bunker
    }
    VALUES ?range1 {"30"}
    #### END ####
} }}
        {?item wdt:P31/wdt:P279* ?classes. BIND(?classes as ?type2)}
  UNION {?item wdt:P31 ?instances. BIND(?instances AS ?type1)}
  SERVICE wikibase:around {
    ?item wdt:P625 ?loc2 .
    bd:serviceParam wikibase:center ?loc1 .
    bd:serviceParam wikibase:radius ?range .
    bd:serviceParam wikibase:distance ?dist.
  } 
} GROUP BY ?item ?itemLabel

Query found at

graph TD classDef projected fill:lightgreen; classDef literal fill:orange; classDef iri fill:yellow; v12("?_anon_d00291b7e9a143df8ec0be8c8ebd714c40935"):::projected v13("?_anon_d00291b7e9a143df8ec0be8c8ebd714c40936"):::projected v5("?classes") v11("?dist") v4("?instances") v3("?item"):::projected v2("?loc") v1("?loc1") v10("?loc2") v7("?range") v6("?range1") v14("?type") v9("?type1") v8("?type2") a1((" ")) c4(["en-GB,en,fr,de,es,pt,pl,nl,cs"]):::literal c2(["bd:serviceParam"]):::iri c9(["wd:Q145"]):::iri c5(["wd:Q1180981"]):::iri subgraph s1["http://wikiba.se/ontology#label"] style s1 stroke-width:4px; c2 --"wikibase:language"--> c4 end subgraph union0[" Union "] subgraph union0l[" "] style union0l fill:#abf,stroke-dasharray: 3 3; c5 --"wdt:P276"--> v2 v2 --"wdt:P625"--> v1 end subgraph union0r[" "] style union0r fill:#abf,stroke-dasharray: 3 3; c5 --"wdt:P625"--> v1 end union0r <== or ==> union0l end v3 --"wdt:P17"--> c9 bind0[/VALUES ?instances/] bind0-->v4 bind00(["wd:Q2772772"]) bind00 --> bind0 bind1[/VALUES ?classes/] bind1-->v5 bind10(["wd:Q1785071"]) bind10 --> bind1 bind11(["wd:Q91122"]) bind11 --> bind1 bind2[/VALUES ?range1/] bind2-->v6 bind20(["30"]) bind20 --> bind2 bind3[/"if(bound(?range1),?range1,'100')"/] v6 --o bind3 bind3 --as--o v7 subgraph union1[" Union "] subgraph union1l[" "] style union1l fill:#abf,stroke-dasharray: 3 3; v3 --"wdt:P31"--> v4 bind4[/"?instances"/] v4 --o bind4 bind4 --as--o v9 end subgraph union1r[" "] style union1r fill:#abf,stroke-dasharray: 3 3; v3 --"wdt:P31"--> a1 a1 --"wdt:P279"--> v5 bind5[/"?classes"/] v5 --o bind5 bind5 --as--o v8 end union1r <== or ==> union1l end subgraph s2["http://wikiba.se/ontology#around"] style s2 stroke-width:4px; v3 --"wdt:P625"--> v10 c2 --"wikibase:center"--> v1 c2 --"wikibase:radius"--> v7 c2 --"wikibase:distance"--> v11 end bind8[/"sample(?type1)"/] v9 --o bind8 bind8 --as--o v12 bind9[/"sample(?type2)"/] v8 --o bind9 bind9 --as--o v13 bind10[/""/] null --o bind10 null --o bind10 bind10 --as--o v14