query-e7d4f7011315816b9e2e309dd7ce0dd1

rq turtle/ttl

Find the longest river, sort by desc. Take 22 seconds, can it be improved further ?Need to find the longest river, sort by desc. This take 22 seconds, can it be improved further ? Given that the Q ID for "river" is unknown, so need to lookup the ID by label.

Use at

PREFIX wikibase: <http://wikiba.se/ontology#>
PREFIX wdt: <http://www.wikidata.org/prop/direct/>
PREFIX wd: <http://www.wikidata.org/entity/>
PREFIX skos: <http://www.w3.org/2004/02/skos/core#>
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
PREFIX psv: <http://www.wikidata.org/prop/statement/value/>
PREFIX p: <http://www.wikidata.org/prop/>
SELECT DISTINCT ?ent ?wdtProperty ?val ?valLabel 

WHERE { 

   { SELECT * WHERE { VALUES ?label1 { rdfs:label skos:altLabel } ?class ?label1 "river"@en;  } }  

  ?val wdt:P31/wdt:P279* ?class .
  ?val p:P2043 ?statement . 
  ?statement psv:P2043 ?psv. 
  ?psv wikibase:quantityAmount ?amount;
       wikibase:quantityUnit ?unit. 

  BIND( IF(?unit = wd:Q828224 , ?amount * 1000, ?amount) as ?ent)

  OPTIONAL { ?val rdfs:label ?valLabel FILTER(lang(?valLabel) = "en") } 

} ORDER BY DESC(?ent) LIMIT 10

Query found at

graph TD classDef projected fill:lightgreen; classDef literal fill:orange; classDef iri fill:yellow; v8("?amount") v4("?class") v10("?ent"):::projected v3("?label1") v7("?psv") v6("?statement") v9("?unit") v5("?val"):::projected v2("?valLabel"):::projected a1((" ")) c2([sriver^^<http://www.w3.org/1999/02/22-rdf-syntax-ns#langString>"]):::literal bind0[/VALUES ?label1/] bind0-->v3 bind00(["rdfs:label"]) bind00 --> bind0 bind01(["skos:altLabel"]) bind01 --> bind0 v4 -->v3--> c2 v5 --"p:direct/P31"--> a1 a1 --"p:direct/P279"--> v4 v5 --"p:P2043"--> v6 v6 --"p:statement/value/P2043"--> v7 v7 --"wikibase:quantityAmount"--> v8 v7 --"wikibase:quantityUnit"--> v9 bind1[/"if(?unit = 'wd:Q828224',?amount * '1000^^xsd:integer',?amount)"/] v9 --o bind1 v8 --o bind1 bind1 --as--o v10 subgraph optional0["(optional)"] style optional0 fill:#bbf,stroke-dasharray: 5 5; v5 -."rdfs:label".-> v2 end