Skip to content

Commit 201150e

Browse files
author
mierzs
committed
minor fix
1 parent 0259863 commit 201150e

File tree

1 file changed

+1
-2
lines changed

1 file changed

+1
-2
lines changed
Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1 @@
1-
{"cells":[{"cell_type":"markdown","id":"ac7bedaf-05fb-4eb0-9bf5-e4d1d68a08c3","metadata":{"id":"ac7bedaf-05fb-4eb0-9bf5-e4d1d68a08c3"},"source":["### Query OpenAlex for all works authored by a person\n","This notebook queries the [OpenAlex API](https://docs.openalex.org/api) via its `/works` endpoint for all works authored by a person. It takes an ORCID URL as input which is used to filter for all works where '`authorships.author.orcid`' matches the given ORCID URL.\n","From the resulting list of works we output their respective DOIs."]},{"cell_type":"code","source":["# Prerequisite: needed dependency to make HTTP calls\n","import requests"],"metadata":{"id":"W8sB1ZF6aKG2","executionInfo":{"status":"ok","timestamp":1643058187428,"user_tz":-60,"elapsed":5,"user":{"displayName":"","photoUrl":"","userId":""}}},"id":"W8sB1ZF6aKG2","execution_count":1,"outputs":[]},{"cell_type":"markdown","source":["The input for the query is an ORCID URL."],"metadata":{"id":"Rt7GUbFcaNxi"},"id":"Rt7GUbFcaNxi"},{"cell_type":"code","source":["# input parameter\n","example_orcid=\"https://orcid.org/0000-0003-2499-7741\""],"metadata":{"id":"GUMzx_sPaTsH","executionInfo":{"status":"ok","timestamp":1643058187684,"user_tz":-60,"elapsed":259,"user":{"displayName":"","photoUrl":"","userId":""}}},"id":"GUMzx_sPaTsH","execution_count":2,"outputs":[]},{"cell_type":"markdown","source":["We use it to query the OpenAlex API for works that specified the ORCID URL within their metadata in the field '`authorships.author.orcid`'.\n"," Since the OpenAlex API uses [pagination](https://docs.openalex.org/api/get-lists-of-entities#pagination), we need to loop through all pages to get the complete result set."],"metadata":{"id":"nWOX9dkvaZ97"},"id":"nWOX9dkvaZ97"},{"cell_type":"code","execution_count":3,"id":"8b608640-96a8-47d1-9de7-b7d3f6fd5a47","metadata":{"trusted":true,"id":"8b608640-96a8-47d1-9de7-b7d3f6fd5a47","executionInfo":{"status":"ok","timestamp":1643058187685,"user_tz":-60,"elapsed":5,"user":{"displayName":"","photoUrl":"","userId":""}}},"outputs":[],"source":["# OpenAlex endpoint to query for works\n","OPENALEX_API_WORKS = \"https://api.openalex.org/works\"\n","\n","# query all works that are connected to orcid\n","def download_data(orcid):\n"," page = 1\n"," max_page = 1\n"," while page <= max_page:\n"," params = {'filter': 'authorships.author.orcid:'+orcid, 'page': page}\n","\n"," response = requests.get(url=OPENALEX_API_WORKS,\n"," params=params,\n"," headers= {'Content-Type': 'application/json'})\n"," result=response.json()\n","\n"," # calculate max page number in first loop\n"," if max_page == 1:\n"," max_page = determine_max_page(result)\n"," page = page + 1\n"," yield result\n","\n","# calculate max number of result pages\n","def determine_max_page(response_data):\n"," item_count = response_data['meta']['count']\n"," items_per_page = response_data['meta']['per_page']\n"," max_page_ceil = item_count // items_per_page + bool(item_count % items_per_page)\n"," return max_page_ceil\n","\n","\n","# ---- example execution\n","list_of_pages=download_data(example_orcid)"]},{"cell_type":"markdown","source":["From the resulting list of works we extract and print out title and DOI."],"metadata":{"id":"kHRO_LiJr-u_"},"id":"kHRO_LiJr-u_"},{"cell_type":"code","execution_count":4,"id":"1c36737c-4dcf-42d5-80e2-802f0a7a8326","metadata":{"trusted":true,"colab":{"base_uri":"https://localhost:8080/"},"id":"1c36737c-4dcf-42d5-80e2-802f0a7a8326","executionInfo":{"status":"ok","timestamp":1643058188197,"user_tz":-60,"elapsed":516,"user":{"displayName":"","photoUrl":"","userId":""}},"outputId":"fb849105-45c1-4abd-a6be-b6d4e3c567f4"},"outputs":[{"output_type":"stream","name":"stdout","text":["10.3897/rio.7.e66264, OPTIMETA – Strengthening the Open Access publishing system through open citations and spatiotemporal metadata\n","10.11588/ip.2020.2.73938, Bericht vom 4. VIVO-Workshop 2019\n","10.15488/9424, ConfIDent – An Open Platform for FAIR Conference Metadata\n","10.31263/voebm.v72i2.2808, Open Science und die Bibliothek – Aktionsfelder und Berufsbild\n","10.21105/joss.01182, VIVO: a system for research discovery\n","10.11588/ip.2019.1.61729, Bericht vom 3. VIVO-Workshop 2018\n","10.11588/ip.2019.1.49609, Problematische Aspekte bibliometrie-basierter Forschungsevaluierung\n","10.1016/j.procs.2019.01.074, The Research Core Dataset (KDSF) in the Linked Data context\n","10.11588/ip.2018.1.49357, Vitro - ein universell einsetzbarer Editor für Ontologien und Instanzen\n","10.3897/rio.4.e31656, Reference implementation for open scientometric indicators (ROSI)\n","10.5281/zenodo.1464108, VIVO - eine Einführung\n","10.11588/ip.2018.1.46819, Anforderungen an Forschungsinformationssysteme in Deutschland durch Forschende und Forschungsadministration – Zusammenfassung zweier Studien\n","10.5281/zenodo.1287885, Supporting a VIVO Regional Community\n","10.15488/3952, Forschungsevaluation und Visualisierung von Zitationsnetzwerken\n","10.15488/3951, Reporting mit VIVO und Kibana\n","10.15488/4087, Referenzimplementierung für offene szientometrische Indikatoren (ROSI)\n","10.11588/ip.2017.2.41926, Tagungsbericht VIVO-Workshop 2017 - “Forschungsinformationen in der Praxis”\n","10.11588/ip.2016.2.32678, Third-Party-Elemente in deutschen Bibliothekswebseiten\n","10.11588/ip.2016.1.31963, Editorial – Rückblick und Call for Call for Papers\n","10.25968/opus-837, Roving Librarians in der Zentralbibliothek der Hochschule Hannover: ein Experiment\n","10.5281/zenodo.50969, URLs von Webseiten mit Typ Bibliothek aus Lobid.org\n","10.11588/ip.2015.2.23784, Erstellung wiederverwendbarer RDF-Geodaten mit Google Refine\n","10.5281/zenodo.30992, VIVO an der Hochschule Hannover - Beispiel: Forschungsprojekte\n","10.11588/ip.2015.1.18489, Editorial - Willkommen zur ersten Ausgabe der Informationspraxis!\n","10.5281/zenodo.13101, geodata: Populated places for VIVO\n","10.2314/coscv2, CoScience : gemeinsam forschen und publizieren mit dem Netz\n","10.25968/opus-330, Die Online-Auskunft der Universitäts- und Landesbibliothek Düsseldorf : erste Evaluation eines Erfolgsmodells\n","10.25968/opus-272, Working Paper: Open Government Data\n","10.25968/opus-303, Lernen 2.0 : Bericht aus der Praxis\n","10.17877/de290r-8755, Web 2.0 in Bibliotheken - Bibliotheken im Web 2.0\n","10.18452/8872, Libworld. Biblioblogs global\n","10.1515/bd.2006.40.4.466, Informationsvermittlung: Personalisiertes Lernen in der Bibliothek: das Düsseldorfer Online-Tutorial (DOT) Informationskompetenz\n","10.1080/00048623.2006.10755322, Teaching Information Literacy with the Lerninformationssystem\n"]}],"source":["# extract all DOIs from the result\n","def extract_dois(data):\n"," for work in data['results']:\n"," try:\n"," doi=work['ids']['doi'].replace(\"https://doi.org/\", \"\")\n"," title=work['display_name']\n"," yield doi, title\n"," except KeyError:\n"," pass\n","\n","\n","# ---- example execution\n","for page in list_of_pages:\n"," for doi,title in extract_dois(page):\n"," print(f\"{doi}, {title}\")"]}],"metadata":{"kernelspec":{"display_name":"Python 3","language":"python","name":"python3"},"language_info":{"codemirror_mode":{"name":"ipython","version":3},"file_extension":".py","mimetype":"text/x-python","name":"python","nbconvert_exporter":"python","pygments_lexer":"ipython3","version":"3.7.8"},"colab":{"name":"Kopie von Kopie von Kopie von openalex_get_works_by_person.ipynb","provenance":[{"file_id":"https://github.com/TAPIR-TIB/pidgraph-notebooks/blob/person-works/person-works/openalex_get_works_by_person.ipynb","timestamp":1643058224827},{"file_id":"https://github.com/TAPIR-TIB/pidgraph-notebooks/blob/person-works/person-works/openalex_get_works_by_person.ipynb","timestamp":1643040475251},{"file_id":"1neSGbKlkQwjOYX77kpGK14BqT4KpCei0","timestamp":1643025949695}],"collapsed_sections":[]}},"nbformat":4,"nbformat_minor":5}
2-
1+
{"cells":[{"cell_type":"markdown","id":"ac7bedaf-05fb-4eb0-9bf5-e4d1d68a08c3","metadata":{"id":"ac7bedaf-05fb-4eb0-9bf5-e4d1d68a08c3"},"source":["### Query OpenAlex for all works authored by a person\n","This notebook queries the [OpenAlex API](https://docs.openalex.org/api) via its `/works` endpoint for all works authored by a person. It takes an ORCID URL as input which is used to filter for all works where '`authorships.author.orcid`' matches the given ORCID URL.\n","From the resulting list of works we output their respective DOIs."]},{"cell_type":"code","execution_count":1,"id":"W8sB1ZF6aKG2","metadata":{"executionInfo":{"elapsed":5,"status":"ok","timestamp":1643058187428,"user":{"displayName":"","photoUrl":"","userId":""},"user_tz":-60},"id":"W8sB1ZF6aKG2"},"outputs":[],"source":["# Prerequisite: needed dependency to make HTTP calls\n","import requests"]},{"cell_type":"markdown","id":"Rt7GUbFcaNxi","metadata":{"id":"Rt7GUbFcaNxi"},"source":["The input for the query is an ORCID URL."]},{"cell_type":"code","execution_count":2,"id":"GUMzx_sPaTsH","metadata":{"executionInfo":{"elapsed":259,"status":"ok","timestamp":1643058187684,"user":{"displayName":"","photoUrl":"","userId":""},"user_tz":-60},"id":"GUMzx_sPaTsH"},"outputs":[],"source":["# input parameter\n","example_orcid=\"https://orcid.org/0000-0003-2499-7741\""]},{"cell_type":"markdown","id":"nWOX9dkvaZ97","metadata":{"id":"nWOX9dkvaZ97"},"source":["We use it to query the OpenAlex API for works that specified the ORCID URL within their metadata in the field '`authorships.author.orcid`'.\n"," Since the OpenAlex API uses [pagination](https://docs.openalex.org/api/get-lists-of-entities#pagination), we need to loop through all pages to get the complete result set."]},{"cell_type":"code","execution_count":3,"id":"8b608640-96a8-47d1-9de7-b7d3f6fd5a47","metadata":{"executionInfo":{"elapsed":5,"status":"ok","timestamp":1643058187685,"user":{"displayName":"","photoUrl":"","userId":""},"user_tz":-60},"id":"8b608640-96a8-47d1-9de7-b7d3f6fd5a47","trusted":true},"outputs":[],"source":["# OpenAlex endpoint to query for works\n","OPENALEX_API_WORKS = \"https://api.openalex.org/works\"\n","\n","# query all works that are connected to orcid\n","def download_data(orcid):\n"," page = 1\n"," max_page = 1\n"," while page <= max_page:\n"," params = {'filter': 'authorships.author.orcid:'+orcid, 'page': page}\n","\n"," response = requests.get(url=OPENALEX_API_WORKS,\n"," params=params,\n"," headers= {'Content-Type': 'application/json'})\n"," result=response.json()\n","\n"," # calculate max page number in first loop\n"," if max_page == 1:\n"," max_page = determine_max_page(result)\n"," page = page + 1\n"," yield result\n","\n","# calculate max number of result pages\n","def determine_max_page(response_data):\n"," item_count = response_data['meta']['count']\n"," items_per_page = response_data['meta']['per_page']\n"," max_page_ceil = item_count // items_per_page + bool(item_count % items_per_page)\n"," return max_page_ceil\n","\n","\n","# ---- example execution\n","list_of_pages=download_data(example_orcid)"]},{"cell_type":"markdown","id":"kHRO_LiJr-u_","metadata":{"id":"kHRO_LiJr-u_"},"source":["From the resulting list of works we extract and print out title and DOI."]},{"cell_type":"code","execution_count":4,"id":"1c36737c-4dcf-42d5-80e2-802f0a7a8326","metadata":{"colab":{"base_uri":"https://localhost:8080/"},"executionInfo":{"elapsed":516,"status":"ok","timestamp":1643058188197,"user":{"displayName":"","photoUrl":"","userId":""},"user_tz":-60},"id":"1c36737c-4dcf-42d5-80e2-802f0a7a8326","outputId":"fb849105-45c1-4abd-a6be-b6d4e3c567f4","trusted":true},"outputs":[{"name":"stdout","output_type":"stream","text":["10.3897/rio.7.e66264, OPTIMETA – Strengthening the Open Access publishing system through open citations and spatiotemporal metadata\n","10.11588/ip.2020.2.73938, Bericht vom 4. VIVO-Workshop 2019\n","10.15488/9424, ConfIDent – An Open Platform for FAIR Conference Metadata\n","10.31263/voebm.v72i2.2808, Open Science und die Bibliothek – Aktionsfelder und Berufsbild\n","10.21105/joss.01182, VIVO: a system for research discovery\n","10.11588/ip.2019.1.61729, Bericht vom 3. VIVO-Workshop 2018\n","10.11588/ip.2019.1.49609, Problematische Aspekte bibliometrie-basierter Forschungsevaluierung\n","10.1016/j.procs.2019.01.074, The Research Core Dataset (KDSF) in the Linked Data context\n","10.11588/ip.2018.1.49357, Vitro - ein universell einsetzbarer Editor für Ontologien und Instanzen\n","10.3897/rio.4.e31656, Reference implementation for open scientometric indicators (ROSI)\n","10.5281/zenodo.1464108, VIVO - eine Einführung\n","10.11588/ip.2018.1.46819, Anforderungen an Forschungsinformationssysteme in Deutschland durch Forschende und Forschungsadministration – Zusammenfassung zweier Studien\n","10.5281/zenodo.1287885, Supporting a VIVO Regional Community\n","10.15488/3952, Forschungsevaluation und Visualisierung von Zitationsnetzwerken\n","10.15488/3951, Reporting mit VIVO und Kibana\n","10.15488/4087, Referenzimplementierung für offene szientometrische Indikatoren (ROSI)\n","10.11588/ip.2017.2.41926, Tagungsbericht VIVO-Workshop 2017 - “Forschungsinformationen in der Praxis”\n","10.11588/ip.2016.2.32678, Third-Party-Elemente in deutschen Bibliothekswebseiten\n","10.11588/ip.2016.1.31963, Editorial – Rückblick und Call for Call for Papers\n","10.25968/opus-837, Roving Librarians in der Zentralbibliothek der Hochschule Hannover: ein Experiment\n","10.5281/zenodo.50969, URLs von Webseiten mit Typ Bibliothek aus Lobid.org\n","10.11588/ip.2015.2.23784, Erstellung wiederverwendbarer RDF-Geodaten mit Google Refine\n","10.5281/zenodo.30992, VIVO an der Hochschule Hannover - Beispiel: Forschungsprojekte\n","10.11588/ip.2015.1.18489, Editorial - Willkommen zur ersten Ausgabe der Informationspraxis!\n","10.5281/zenodo.13101, geodata: Populated places for VIVO\n","10.2314/coscv2, CoScience : gemeinsam forschen und publizieren mit dem Netz\n","10.25968/opus-330, Die Online-Auskunft der Universitäts- und Landesbibliothek Düsseldorf : erste Evaluation eines Erfolgsmodells\n","10.25968/opus-272, Working Paper: Open Government Data\n","10.25968/opus-303, Lernen 2.0 : Bericht aus der Praxis\n","10.17877/de290r-8755, Web 2.0 in Bibliotheken - Bibliotheken im Web 2.0\n","10.18452/8872, Libworld. Biblioblogs global\n","10.1515/bd.2006.40.4.466, Informationsvermittlung: Personalisiertes Lernen in der Bibliothek: das Düsseldorfer Online-Tutorial (DOT) Informationskompetenz\n","10.1080/00048623.2006.10755322, Teaching Information Literacy with the Lerninformationssystem\n"]}],"source":["# extract all DOIs from the result\n","def extract_dois(data):\n"," for work in data['results']:\n"," try:\n"," doi=work['ids']['doi'].replace(\"https://doi.org/\", \"\")\n"," title=work['display_name']\n"," yield doi, title\n"," except (KeyError,AttributeError) as e:\n"," pass\n","\n","\n","# ---- example execution\n","for page in list_of_pages:\n"," for doi,title in extract_dois(page):\n"," print(f\"{doi}, {title}\")"]}],"metadata":{"colab":{"collapsed_sections":[],"name":"Kopie von Kopie von Kopie von openalex_get_works_by_person.ipynb","provenance":[{"file_id":"https://github.com/TAPIR-TIB/pidgraph-notebooks/blob/person-works/person-works/openalex_get_works_by_person.ipynb","timestamp":1643058224827},{"file_id":"https://github.com/TAPIR-TIB/pidgraph-notebooks/blob/person-works/person-works/openalex_get_works_by_person.ipynb","timestamp":1643040475251},{"file_id":"1neSGbKlkQwjOYX77kpGK14BqT4KpCei0","timestamp":1643025949695}]},"kernelspec":{"display_name":"Python 3","language":"python","name":"python3"},"language_info":{"codemirror_mode":{"name":"ipython","version":3},"file_extension":".py","mimetype":"text/x-python","name":"python","nbconvert_exporter":"python","pygments_lexer":"ipython3","version":"3.7.8"}},"nbformat":4,"nbformat_minor":5}

0 commit comments

Comments
 (0)