query-0ee3f3bd154d1cbcb199fe4dbc827224

rq turtle/ttl

Optimizing query 14:00, 19 October 2020 (UTC)) talk (DaanvrI build this query that is pretty perfect for my project. However, it is pretty slow. What sort of optimizations could speed up the query?--

Use at

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 geo: <http://www.opengis.net/ont/geosparql#>
PREFIX bd: <http://www.bigdata.com/rdf#>
#defaultView:ImageGride
SELECT 
  ?itemNew ?itemNewLabel ?itemNewDescription ?article
  (SAMPLE(?geo) AS ?geo) # The SAMPLE code is needed to inform the GROUP BY code what to do when there are more than one.
  (SAMPLE(?img) AS ?img)
  (SAMPLE(?categorie) AS ?categorie)
  (GROUP_CONCAT(?instanceLabel; SEPARATOR = ", ") AS ?instancesof) # a nices String with the labels of the different instances of related to the item

WHERE {
  #### Selection based on location ####   
  SERVICE wikibase:box {
    ?itemNew wdt:P625 ?geo.
    bd:serviceParam wikibase:cornerWest "Point(2.30 48.87)"^^geo:wktLiteral. 
    bd:serviceParam wikibase:cornerEast "Point(2.32 48.86)"^^geo:wktLiteral.
  }

  MINUS { ?itemNew (wdt:P31/(wdt:P279*)) wd:Q376799. } # Remove everything related to roads
  ?itemNew wdt:P18 ?img. # Only keep items with pictures 

  #### Categorise items ####
  BIND(
    IF(EXISTS {?itemNew (wdt:P31/(wdt:P279*)) wd:Q811979}, "Architectural",
    IF(EXISTS {?itemNew (wdt:P31/(wdt:P279*)) wd:Q1656682}, "Event",
      "Other"
  ))
  AS ?categorie)

  OPTIONAL { ?itemNew wdt:P31 ?instance. } # Get instances

  #### Wikipedia link ####
  OPTIONAL {
    ?article schema:about ?itemNew . # Get wikipedia link
    ?article schema:isPartOf <https://en.wikipedia.org/>. # Only keep EN language
  }

  #### Labels & discription #### 
  SERVICE wikibase:label { # Get labels
    bd:serviceParam wikibase:language "en". 
    ?instance rdfs:label ?instanceLabel.      # The specification of the variables to be labeld is needed for grouping the instances of correctly
    ?itemNew rdfs:label ?itemNewLabel.
    ?itemNew schema:description ?itemNewDescription.
  }
}
GROUP BY ?itemNew ?itemNewLabel ?itemNewDescription ?article

Query found at

graph TD classDef projected fill:lightgreen; classDef literal fill:orange; classDef iri fill:yellow; v6("?article"):::projected v10("?categorie"):::projected v10("?geo"):::projected v10("?img"):::projected v5("?instance") v7("?instanceLabel"):::projected v10("?instancesof") v1("?itemNew"):::projected v9("?itemNewDescription"):::projected v8("?itemNewLabel"):::projected a1((" ")) c7([sPoint(2.32 48.86)^^<http://www.opengis.net/ont/geosparql#wktLiteral>"]):::literal c5([sPoint(2.30 48.87)^^<http://www.opengis.net/ont/geosparql#wktLiteral>"]):::literal c10(["wd:Q376799"]):::iri c17(["en"]):::literal c14([https://en.wikipedia.org/]):::iri c3(["bd:serviceParam"]):::iri subgraph s1["http://wikiba.se/ontology#box"] style s1 stroke-width:4px; v1 --"wdt:P625"--> v10 c3 --"wikibase:cornerWest"--> c5 c3 --"wikibase:cornerEast"--> c7 end subgraph minus0["MINUS"] style minus0 stroke-width:6px,fill:pink,stroke:red; v1 --"wdt:P31"--> a1 a1 --"wdt:P279"--> c10 end v1 --"wdt:P18"--> v10 v1 --"wdt:P31"--> null null --"wdt:P279"--> null v1 --"wdt:P31"--> null null --"wdt:P279"--> null bind1[/"if( ,'Architectural',if( ,'Event','Other'))"/] subgraph bind1e0["Exists Clause"] e0v1 --"wdt:P31"--> e0a1 e0a1 --"wdt:P279"--> e0c3 e0v1("?itemNew"):::projected e0a1((" ")):::projected e0c3(["wd:Q811979"]):::iri end bind1--EXISTS--> bind1e0 subgraph bind1e1["Exists Clause"] e1v1 --"wdt:P31"--> e1a1 e1a1 --"wdt:P279"--> e1c3 e1v1("?itemNew"):::projected e1a1((" ")):::projected e1c3(["wd:Q1656682"]):::iri end bind1--EXISTS--> bind1e1 v1 --o bind1 c8 --o bind1 null --o bind1 c9 --o bind1 null --o bind1 null --o bind1 null --o bind1 bind1 --as--o v10 subgraph optional0["(optional)"] style optional0 fill:#bbf,stroke-dasharray: 5 5; v1 -."wdt:P31".-> v5 end subgraph optional1["(optional)"] style optional1 fill:#bbf,stroke-dasharray: 5 5; v6 -."schema:about".-> v1 v6 --"schema:isPartOf"--> c14 end subgraph s2["http://wikiba.se/ontology#label"] style s2 stroke-width:4px; c3 --"wikibase:language"--> c17 v5 --"rdfs:label"--> v7 v1 --"rdfs:label"--> v8 v1 --"schema:description"--> v9 end bind6[/"sample(?geo)"/] v10 --o bind6 bind6 --as--o v10 bind7[/"sample(?img)"/] v10 --o bind7 bind7 --as--o v10 bind8[/"sample(?categorie)"/] v10 --o bind8 bind8 --as--o v10 bind9[/"?instanceLabel"/] v7 --o bind9 bind9 --as--o v10