sparql-examples

A set of SPARQL examples that are used in different TGX resources

View the Project on GitHub BiGCAT-UM/sparql-examples

226

rq turtle/ttl

Wikiproject aspect: author awards

Use at

PREFIX hint: <http://www.bigdata.com/queryHints#>
PREFIX p: <http://www.wikidata.org/prop/>
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
PREFIX wdt: <http://www.wikidata.org/prop/direct/>
PREFIX target: <http://www.wikidata.org/entity/Q60687720>

SELECT ?count 
?award ?awardLabel (CONCAT("/award/", SUBSTR(STR(?award), 32)) AS ?awardUrl)
?recipients ?recipientsUrl
WITH {
  SELECT (COUNT(?researcher) AS ?count) ?award 
  (GROUP_CONCAT(DISTINCT ?researcher_label; separator=", ") AS ?recipients) 
  (CONCAT("../authors/", GROUP_CONCAT(DISTINCT SUBSTR(STR(?researcher), 32); separator=",")) AS ?recipientsUrl)
  WHERE {
    { 
      SELECT DISTINCT ?researcher ?award WHERE {
        hint:Query hint:optimizer "None" .
        { ?work wdt:P6104 target: .}
        union 
        { ?work wdt:P5008 target: .}
        ?work wdt:P50 ?researcher .
        ?researcher wdt:P166 ?award .
      } 
      LIMIT 100
    }
    ?researcher rdfs:label ?researcher_label . FILTER (LANG(?researcher_label) = 'en')
  }
  GROUP BY ?award 
} AS %result
WHERE {
  INCLUDE %result
    ?award rdfs:label ?awardLabel . FILTER (LANG(?awardLabel) = 'en')
}
GROUP BY ?count ?award ?awardLabel ?recipients ?recipientsUrl
ORDER BY DESC(?count)

graph TD