sparql-examples

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

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

005

rq turtle/ttl

Author aspect: coauthors

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/Q97270>

# Egocentric co-author graph for an author
SELECT ?author1 ?author1Label ?rgb ?author2 ?author2Label
WITH {
  SELECT (COUNT(?work) AS ?count) ?author1 ?author2 WHERE {
    # Find co-authors
    ?work wdt:P50 target:, ?author1, ?author2 .

    # Filtering 
    # Only journal and conference articles, books, not (yet?) software
    # VALUES ?publication_type { wd:Q13442814 wd:Q571 wd:Q26973022}  
    # ?work wdt:P31 ?publication_type .
  }
  GROUP BY ?author1 ?author2
  ORDER BY DESC(?count)
                    
  # Limit the size of the graph, to avoid overburdening the browser
  LIMIT 1000
} AS %authors
WITH {
  SELECT ?author1 ?author2 ?rgb WHERE {
    INCLUDE %authors
    
    # Exclude self-links
    FILTER (?author1 != ?author2)
    
    # Color according to gender
    OPTIONAL {
      ?author1 wdt:P21 ?gender1 . 
      BIND( IF(?gender1 = wd:Q6581097, "3182BD", "E6550D") AS ?rgb)
    }
  }
} AS %result
WHERE {
  INCLUDE %result
  # Label the results 
  SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],mul,en" . }
}

graph TD