USyd related queries

set up the ability to query wikidata

import urllib.parse
from IPython.display import IFrame
baseurl='https://query.wikidata.org/embed.html#'

def wdq(query='',width=800,height=500):
  return IFrame(baseurl+urllib.parse.quote(query), width=width, height=height)

Find the occupations listed for all employees or past employees of the University of Sydney

wdq(width=1000,height=800,query="""
#defaultView:BubbleChart
SELECT ?occupation ?occupationLabel (COUNT(*) as ?count) WHERE {
  ?p wdt:P108 wd:Q487556 .
  ?p wdt:P106 ?occupation .
  SERVICE wikibase:label { bd:serviceParam wikibase:language "en" } .
} 
GROUP BY ?occupation ?occupationLabel
ORDER BY DESC(?count) ?occupatinoLabel
LIMIT 1000
""")

Find the occupations listed for all graduates of the University of Sydney

wdq(width=1000,height=800,query="""
#defaultView:BubbleChart
SELECT ?occupation ?occupationLabel (COUNT(*) as ?count) WHERE {
  {?person wdt:P69 wd:Q487556 } UNION {?person wdt:P69/wdt:P31 wd:Q487556 } # educated at Sydney
  ?person wdt:P106 ?occupation .
  SERVICE wikibase:label { bd:serviceParam wikibase:language "en" } .
} 
GROUP BY ?occupation ?occupationLabel
ORDER BY DESC(?count) ?occupatinoLabel
LIMIT 1000
""")

Sample graduate birthday calendar

wdq(width=1000,height=1000,query="""
#defaultView:ImageGrid
SELECT (CONCAT(STR(?day_int)," ",?monthLabel) as ?birthday) ?rperson ?personLabel ?personDesc ?pic (URI(CONCAT("https://tools.wmflabs.org/reasonator/?q=", SUBSTR(STR(?rperson),32) )) as ?link) WHERE {
{ 
  SELECT ?month_int ?month ?day_int (SAMPLE(?person) AS ?rperson) (SAMPLE(?pic) as ?pic) WHERE {
     ?month wdt:P31 wd:Q47018901; wdt:P1545 ?month_ordinal. # These lines generate a calendar from January 1 to December 31
     ?day p:P361 [ps:P361 ?month; pq:P1545 ?day_ordinal ].
     BIND(xsd:integer(?month_ordinal) AS ?month_int)
     BIND(xsd:integer(?day_ordinal) AS ?day_int)
     OPTIONAL {
      # Define the people we're interested in
      {?person wdt:P69 wd:Q487556 } UNION {?person wdt:P69/wdt:P31 wd:Q487556 } # educated at Sydney
      ?person p:P569/psv:P569 ?date_node. # birth date
      ?date_node wikibase:timePrecision "11"^^xsd:integer ; # birth date has specific day
      wikibase:timeValue ?birthdate .        
      filter(DAY(?birthdate)=?day_int) filter (MONTH(?birthdate)=?month_int )
      OPTIONAL {?person wdt:P18 ?pic .}
     }
  } GROUP BY ?month_int ?month ?day_int }
  SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en".
    ?rperson rdfs:label ?personLabel. ?rperson schema:description ?personDesc. ?month rdfs:label ?monthLabel 
  }
} ORDER BY ?month_int ?day_int
""")

Place of birth of graduates.

wdq(width=1000,height=1000,query="""
#defaultView:Map
SELECT ?person ?personLabel ?birth ?birthLabel ?birthloc WHERE {
  {?person wdt:P69 wd:Q487556 } UNION {?person wdt:P69/wdt:P31 wd:Q487556 } # educated at Sydney
   ?person wdt:P19 ?birth .
   ?birth wdt:P625 ?birthloc .

   SERVICE wikibase:label {
    bd:serviceParam wikibase:language "en" .
   }
 }  LIMIT 10000
 """)

Find all employees of the University of Sydney who have published together, and map the network. Colours are according to an occupation which is a subclass of researcher (e.g. "chemist" is navy blue). The common aqua colour is for those who are simply have "researcher" listed as their occupation.

wdq(width=1000,height=800,query="""
#defaultView:Graph
SELECT DISTINCT ?author1 ?author1Label ?rgb ?author2 ?occupation1Label WHERE {
  ?author1 wdt:P108 wd:Q487556.
  ?paper wdt:P50 ?author1 .
  ?paper wdt:P50 ?author2 .
  ?author2 wdt:P108 wd:Q487556 .
  FILTER( ?author1 != ?author2 ) .
  OPTIONAL {?author1 wdt:P106 ?occupation1 .
           ?occupation1 wdt:P279* wd:Q1650915.}
  
  SERVICE wikibase:label { bd:serviceParam wikibase:language "en" } .

  BIND( substr(md5(STR(?occupation1)),1,6) as ?rgb )
}
LIMIT 10000
""")

Map of items which are part of the University of Sydney

wdq(width=1000,height=1000,query="""
#defaultView:Map
SELECT ?item ?label ?_image ?coords WHERE {
  ?item wdt:P361 wd:Q487556.
  SERVICE wikibase:label {
    bd:serviceParam wikibase:language "en" . 
    ?item rdfs:label ?label
  }
  OPTIONAL {?item wdt:P625 ?coords.}
  OPTIONAL { ?item wdt:P18 ?_image. }
}
LIMIT 100
""")
recent publications
wdq(width=1000,height=1000,query="""
#defaultView:Table
SELECT ?publication_date ?work ?workLabel ?researchers
WITH {
  SELECT 
    (MIN(?publication_datetimes) AS ?publication_datetime) ?work 
    (GROUP_CONCAT(DISTINCT ?researcher_label; separator=', ') AS ?researchers)
  WHERE {                                                         
    ?researcher ( wdt:P108 | wdt:P463 | wdt:P1416 ) / wdt:P361* wd:Q487556 .
    ?work wdt:P50 ?researcher .
    ?researcher rdfs:label ?researcher_label . FILTER (LANG(?researcher_label) = 'en')
    OPTIONAL {
      ?work wdt:P577 ?publication_datetimes .
    }
  }
  GROUP BY ?work
  ORDER BY DESC(?publication_datetime)
  LIMIT 200  
} AS %results
WHERE {
  INCLUDE %results
  BIND(xsd:date(?publication_datetime) AS ?publication_date)
  SERVICE wikibase:label { bd:serviceParam wikibase:language "en,da,de,es,fr,jp,nl,nl,ru,zh". }
}
ORDER BY DESC(?publication_date)
""")