query-2eefb61fb39b6e9c611ebcd73b9c28a2
Optimizing a query for the mapframe extension. After several tweaks they now work rather well, but the main issue seems to be one of performance: the maps are often slow to load, and sometimes they won't load at all. Any help in improving their efficiency is most welcome. this one and this module to create dynamic locator maps of subnational entities, such as mapframeI've been using the ): w:Template:Russia district OSM mapThis is the 'pure' query (without some parser functions required to make them work with mapframe, which can be found at
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 schema: <http://schema.org/>
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
PREFIX ps: <http://www.wikidata.org/prop/statement/>
PREFIX pq: <http://www.wikidata.org/prop/qualifier/>
PREFIX p: <http://www.wikidata.org/prop/>
PREFIX bd: <http://www.bigdata.com/rdf#>
SELECT ?id
(if(BOUND(?link),
concat('[[', substr(str(?link),31,500), '|', ?idLabel, ']]'),
?idLabel)
as ?title)
WHERE {
{ ?id p:P31/ps:P31/wdt:P279* wd:Q2198484 . }
UNION
{ ?id p:P31/ps:P31/wdt:P279* wd:Q13626398 . }
UNION
{ ?id p:P31/ps:P31/wdt:P279* wd:Q4057820 . }
?id p:P131 ?locst .
?locst ps:P131/wdt:P131* wd:Q5400.
MINUS { ?locst pq:P582 [] }
SERVICE wikibase:label {
bd:serviceParam wikibase:language 'en' .
?id rdfs:label ?idLabel .
}
OPTIONAL {?link schema:about ?id .
?link schema:isPartOf <https://en.wikipedia.org/> . }
} GROUP BY ?id ?link ?idLabel
Query found at
graph TD
classDef projected fill:lightgreen;
classDef literal fill:orange;
classDef iri fill:yellow;
v1("?id"):::projected
v3("?idLabel"):::projected
v4("?link"):::projected
v2("?locst")
v5("?title")
a8((" "))
a1((" "))
a2((" "))
a3((" "))
a4((" "))
a5((" "))
a6((" "))
a7((" "))
c15(["en"]):::literal
c6(["wd:Q4057820"]):::iri
c4(["wd:Q2198484"]):::iri
c5(["wd:Q13626398"]):::iri
c19([https://en.wikipedia.org/]):::iri
c13(["bd:serviceParam"]):::iri
c10(["wd:Q5400"]):::iri
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;
v1 --"p:P31"--> a5
a5 --"p:statement/P31"--> a6
a6 --"p:direct/P279"--> c6
end
subgraph union1r[" "]
style union1r fill:#abf,stroke-dasharray: 3 3;
v1 --"p:P31"--> a3
a3 --"p:statement/P31"--> a4
a4 --"p:direct/P279"--> c5
end
union1r <== or ==> union1l
end
end
subgraph union0r[" "]
style union0r fill:#abf,stroke-dasharray: 3 3;
v1 --"p:P31"--> a1
a1 --"p:statement/P31"--> a2
a2 --"p:direct/P279"--> c4
end
union0r <== or ==> union0l
end
v1 --"p:P131"--> v2
v2 --"p:statement/P131"--> a7
a7 --"p:direct/P131"--> c10
subgraph minus0["MINUS"]
style minus0 stroke-width:6px,fill:pink,stroke:red;
v2 --"p:qualifier/P582"--> a8
end
subgraph s1["http://wikiba.se/ontology#label"]
style s1 stroke-width:4px;
c13 --"wikibase:language"--> c15
v1 --"rdfs:label"--> v3
end
subgraph optional0["(optional)"]
style optional0 fill:#bbf,stroke-dasharray: 5 5;
v4 -."schema:about".-> v1
v4 --"schema:isPartOf"--> c19
end
bind1[/"if(bound(?link),concat('#91;#91;',substring(str(?link),'31^^xsd:integer','500^^xsd:integer'),'|',?idLabel,'#93;#93;'),?idLabel)"/]
v4 --o bind1
v3 --o bind1
bind1 --as--o v5