query-83741179e6f6ca87684ed1cd89aa7a74

rq turtle/ttl

]reply[13:29, 26 June 2024 (UTC)) talk (Tagishsimon: The aggretation issue is sorted ut in the query above. The final GROUP BY compliments the initial SELECT, so ?itemLabel was required. Not sure where you're going with range: ?range1 is always BOUND in the first, %i, named subquery b/c it is being set by VALUES. The initial SELECT does not select ?range (or ?range1) so you're not getting the range from the lower query. And then, ?range 1 does not seem to be used in the second query at all, and all of the ?items found in the second query will have a ?range b/c they're being found by the wikibase:around function. So. Have a think, let me know. --Vicarage@]reply[13:54, 26 June 2024 (UTC)) talk (Vicarage: Thanks for the aggregate solution. I think I'm trying to be too clever, writing a generic back end that can filter on combinations of classes, distances and properties provided in a short source file, with the logic that if the filter values are mentioned, use them, otherwise skip the check entirely, to find items of many different types that are related to an item (geographically, because of subclass, because they are linked by a property of one item that is in the other's database) This requires the programatic 'IF ?thing not blank use ?thing in this check, otherwise skip the check' which doesn't seem available in the language. I think I will need to retreat to a wider range of separate back end queries. Tagishsimon@For example, this, which uses 2 techniques you showed me, times out ]reply[22:17, 26 June 2024 (UTC)) talk (VicarageYes, but I can't do the distance calculation if the item doesn't have a P625, or check against a list of properties if the list is blank. Each time I come up with a generic solution it either won't accept nulls, or runs unreasonably slowly. Its very frustrating that a few dozen results can time out. ]reply[21:56, 26 June 2024 (UTC)) talk (Tagishsimon: BIND(IF(BOUND(?this),?this,?that) as ?whatever), or BIND(IF(!BOUND(?something_else),?this,?that) as ?whatever) or BIND(IF(?this<30),?this,?that) as ?whatever) sounds like what you may be after ... so you're not deciding whether or not to do the distance calculation, but rather deciding based on some condition whether to use the result? --Vicarage@

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 bd: <http://www.bigdata.com/rdf#>
SELECT DISTINCT ?item ?type 
      (SAMPLE (DISTINCT ?sta) as ?subtypeLabel)
WHERE {
  SERVICE wikibase:label { bd:serviceParam wikibase:language "en-GB,en,fr,de,es,pt,pl,nl,cs". }
  { {SELECT ?classes1# ?classes2 #?range ?props
                       WHERE {
VALUES ?classes1 {
  wd:Q1785071  # fort
}
VALUES ?classes2 {
  wd:Q91122    # bunker
}
VALUES ?range {"15"}
} }}
  wd:Q1180981 wdt:P17 ?country.
  ?item wdt:P17 ?country.
        {?item wdt:P31/wdt:P279* ?classes1}
 UNION {?item wdt:P31/wdt:P279* ?classes2}
  {wd:Q1180981 wdt:P625 ?loc1} UNION {wd:Q1180981 wdt:P276 ?loc. ?loc wdt:P625 ?loc1}
  SERVICE wikibase:around {
    ?item wdt:P625 ?loc2.
    bd:serviceParam wikibase:center ?loc1.
    bd:serviceParam wikibase:radius "15".
    bd:serviceParam wikibase:distance ?dist.
  } 
MINUS {VALUES ?item {wd:Q1180981} } # itself
OPTIONAL {?item wdt:P1448 ?labellist. FILTER (lang(?labellist) = "mul")} # official name
{SERVICE wikibase:label {bd:serviceParam wikibase:language "en" . ?item rdfs:label ?label1} }
    }
    #GROUP by ?item ?starts ?ends ?dist ?label1 ?type
    GROUP by ?item ?type ?label1

Query found at

graph TD classDef projected fill:lightgreen; classDef literal fill:orange; classDef iri fill:yellow; v2("?classes1") v3("?classes2") v5("?country") v10("?dist") v11("?item"):::projected v11("?label1") v1("?labellist") v8("?loc") v7("?loc1") v9("?loc2") v4("?range") v12("?sta"):::projected v13("?subtypeLabel") a1((" ")) a2((" ")) c15(["15"]):::literal c18(["en"]):::literal c5(["en-GB,en,fr,de,es,pt,pl,nl,cs"]):::literal c3(["bd:serviceParam"]):::iri c6(["wd:Q1180981"]):::iri subgraph s1["http://wikiba.se/ontology#label"] style s1 stroke-width:4px; c3 --"wikibase:language"--> c5 end bind0[/VALUES ?classes1/] bind0-->v2 bind00(["wd:Q1785071"]) bind00 --> bind0 bind1[/VALUES ?classes2/] bind1-->v3 bind10(["wd:Q91122"]) bind10 --> bind1 bind2[/VALUES ?range/] bind2-->v4 bind20(["15"]) bind20 --> bind2 c6 --"wdt:P17"--> v5 v11 --"wdt:P17"--> v5 subgraph union0[" Union "] subgraph union0l[" "] style union0l fill:#abf,stroke-dasharray: 3 3; v11 --"wdt:P31"--> a2 a2 --"wdt:P279"--> v3 end subgraph union0r[" "] style union0r fill:#abf,stroke-dasharray: 3 3; v11 --"wdt:P31"--> a1 a1 --"wdt:P279"--> v2 end union0r <== or ==> union0l end subgraph union1[" Union "] subgraph union1l[" "] style union1l fill:#abf,stroke-dasharray: 3 3; c6 --"wdt:P276"--> v8 v8 --"wdt:P625"--> v7 end subgraph union1r[" "] style union1r fill:#abf,stroke-dasharray: 3 3; c6 --"wdt:P625"--> v7 end union1r <== or ==> union1l end subgraph s2["http://wikiba.se/ontology#around"] style s2 stroke-width:4px; v11 --"wdt:P625"--> v9 c3 --"wikibase:center"--> v7 c3 --"wikibase:radius"--> c15 c3 --"wikibase:distance"--> v10 end subgraph minus3["MINUS"] style minus3 stroke-width:6px,fill:pink,stroke:red; bind4[/VALUES ?item/] bind4-->v11 bind40(["wd:Q1180981"]) bind40 --> bind4 end subgraph optional0["(optional)"] style optional0 fill:#bbf,stroke-dasharray: 5 5; v11 -."wdt:P1448".-> v1 end subgraph s1["http://wikiba.se/ontology#label"] style s1 stroke-width:4px; c3 --"wikibase:language"--> c18 v11 --"rdfs:label"--> v11 end bind6[/"sample(?sta)"/] v12 --o bind6 bind6 --as--o v13