sparql-examples

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

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

186

rq turtle/ttl

Topic aspect: coauthor graph

Use at

PREFIX bd: <http://www.bigdata.com/rdf#>
PREFIX p: <http://www.wikidata.org/prop/>
PREFIX wdt: <http://www.wikidata.org/prop/direct/>
PREFIX wd: <http://wikidata.org/entity/>
PREFIX wikibase: <http://wikiba.se/ontology#>
#defaultView:Graph

PREFIX target: <http://www.wikidata.org/entity/Q45340488>

SELECT ?author1 ?author1Label ?rgb ?author2 ?author2Label
WITH {
  # Find works with the topic
  SELECT ?work WHERE {
    ?work wdt:P921 / (wdt:P31* / wdt:P279* | wdt:P361+ | wdt:P1269+) target: .
  }
} AS %works
WITH {
  # Limit the number of authors
  SELECT (COUNT(?work) AS ?count1) ?author1 WHERE {
    INCLUDE %works
    ?work wdt:P50 ?author1 .
  }
  GROUP BY ?author1
  ORDER BY DESC(?count1)
  LIMIT 25
} AS %authors1
WITH {
  # Limit the number of coauthors
  SELECT DISTINCT ?author2 ?author1  (COUNT(?work) AS ?count2)  WHERE {
    INCLUDE %works
    INCLUDE %authors1
    ?work wdt:P50 ?author1 , ?author2 .
    FILTER (?author1 != ?author2) 
  }
  GROUP BY ?author2 ?author1 
  ORDER BY DESC(?count2)
  LIMIT 250
} AS %authors2
WHERE {
#  INCLUDE %authors1
  INCLUDE %authors2
  OPTIONAL { ?author1 wdt:P21 ?gender1 . }
  BIND( IF(?gender1 = wd:Q6581097, "3182BD", "E6550D") AS ?rgb)
  SERVICE wikibase:label {
    bd:serviceParam wikibase:language "[AUTO_LANGUAGE],mul,en" .
  }
}

graph TD