query-e5a2917651ca173b839e4d2a3704f18d
Query failing with Listeria, but for some times it encounters a timeout. Can someone help me optimizing it please? has worked fine for yearsHello, the below query
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 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 ?item ?INSEE ?itemLabel (CONCAT("[[Wikidata:WikiProject France/Églises/",?INSEE,"\u007C",?itemLabel,"]]") AS ?LIEN) ?depCount (IF(?_withCoord > ?depCount, 0, ?depCount - ?_withCoord) AS ?withoutCoord) (IF(?_withImg > ?depCount, 0, ?depCount - ?_withImg) AS ?withoutImg) (ROUND((IF(?_withCoord > ?depCount, ?depCount, ?_withCoord) / ?depCount) * 100 * 100) / 100 AS ?withCoord) (ROUND((IF(?_withImg > ?depCount, ?depCount, ?_withImg) / ?depCount) * 100 * 100) / 100 AS ?withImg)
WHERE {
{
SELECT ?item (COUNT(DISTINCT ?item2) AS ?depCount) (COUNT(DISTINCT ?coord) AS ?_withCoord) (COUNT(DISTINCT ?img) AS ?_withImg) WHERE {
?item2 wdt:P131+ wd:Q142.
?item2 wdt:P31/wdt:P279* wd:Q16970.
?item2 wdt:P131 ?commune.
?commune p:P131 ?stmt .
?stmt ps:P131 ?item .
MINUS { ?stmt pq:P582 [] } .
?item wdt:P2586 [] .
OPTIONAL { ?item2 wdt:P625 ?coord } .
OPTIONAL { ?item2 wdt:P18 ?img } .
} GROUP BY ?item
} .
?item wdt:P2586 ?INSEE .
SERVICE wikibase:label { bd:serviceParam wikibase:language "fr" } .
}
ORDER BY ?INSEE
Query found at
graph TD
classDef projected fill:lightgreen;
classDef literal fill:orange;
classDef iri fill:yellow;
v1("?INSEE"):::projected
v11("?LIEN")
v9("?_withCoord"):::projected
v10("?_withImg"):::projected
v3("?commune")
v6("?coord")
v8("?depCount"):::projected
v7("?img")
v5("?item"):::projected
v2("?item2")
v4("?stmt")
v14("?withCoord")
v15("?withImg")
v12("?withoutCoord")
v13("?withoutImg")
a2((" "))
a3((" "))
a1((" "))
c15(["fr"]):::literal
c13(["bd:serviceParam"]):::iri
c5(["wd:Q16970"]):::iri
c2(["wd:Q142"]):::iri
v2 --"p:direct/P131"--> c2
v2 --"p:direct/P31"--> a1
a1 --"p:direct/P279"--> c5
v2 --"p:direct/P131"--> v3
v3 --"p:P131"--> v4
v4 --"p:statement/P131"--> v5
subgraph minus0["MINUS"]
style minus0 stroke-width:6px,fill:pink,stroke:red;
v4 --"p:qualifier/P582"--> a2
end
v5 --"p:direct/P2586"--> a3
subgraph optional0["(optional)"]
style optional0 fill:#bbf,stroke-dasharray: 5 5;
v2 -."p:direct/P625".-> v6
end
subgraph optional1["(optional)"]
style optional1 fill:#bbf,stroke-dasharray: 5 5;
v2 -."p:direct/P18".-> v7
end
bind4[/"count(?item2)"/]
v2 --o bind4
bind4 --as--o v8
bind5[/"count(?coord)"/]
v6 --o bind5
bind5 --as--o v9
bind6[/"count(?img)"/]
v7 --o bind6
bind6 --as--o v10
v5 --"p:direct/P2586"--> v1
subgraph s1["http://wikiba.se/ontology#label"]
style s1 stroke-width:4px;
c13 --"wikibase:language"--> c15
end
bind7[/"concat('#91;#91;Wikidata:WikiProject France/Églises/',?INSEE,'|',?itemLabel,'#93;#93;')"/]
v1 --o bind7
null --o bind7
bind7 --as--o v11
bind8[/"if(?_withCoord > ?depCount,'0^^xsd:integer',?depCount - ?_withCoord)"/]
v9 --o bind8
v8 --o bind8
bind8 --as--o v12
bind9[/"if(?_withImg > ?depCount,'0^^xsd:integer',?depCount - ?_withImg)"/]
v10 --o bind9
v8 --o bind9
bind9 --as--o v13
bind10[/"numeric-round(if(?_withCoord > ?depCount,?depCount,?_withCoord) / ?depCount * '100^^xsd:integer' * '100^^xsd:integer') / '100^^xsd:integer'"/]
v9 --o bind10
v8 --o bind10
bind10 --as--o v14
bind11[/"numeric-round(if(?_withImg > ?depCount,?depCount,?_withImg) / ?depCount * '100^^xsd:integer' * '100^^xsd:integer') / '100^^xsd:integer'"/]
v10 --o bind11
v8 --o bind11
bind11 --as--o v15