query-83741179e6f6ca87684ed1cd89aa7a74
]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
- https://query.wikidata.org/sparql
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