Skip to content

Commit 2e13a12

Browse files
authored
Merge pull request #5 from Project-TAPIR/documentation
Documentation
2 parents c9d765d + 826499b commit 2e13a12

8 files changed

+8
-8
lines changed
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
{"nbformat":4,"nbformat_minor":0,"metadata":{"colab":{"name":"Kopie von ror-organigram.ipynb","provenance":[{"file_id":"1yJn6R6ixeEZFU47XyeZsTiqhU-W7AS2H","timestamp":1643279199327}],"authorship_tag":"ABX9TyPEl1r8wtGqaTN4CJj87Lso"},"kernelspec":{"name":"python3","display_name":"Python 3"},"language_info":{"name":"python"}},"cells":[{"cell_type":"markdown","source":["### Query ROR for an organization and the hierarchy of sub-organizations below it\n","\n","This notebook queries the [ROR API](https://ror.readme.io/) to construct a hierarchy of sub-organizations starting at a given organization. It takes a ROR URL or ID which is used to retrieve the organizations specified in the metadata field \"`relationships`\" with `\"type\"=Child` recursively to build a tree structure. The tree represents the hierarchy of sub-organizations and will be outputted.\n"],"metadata":{"id":"0-62NAVa8DL0"}},{"cell_type":"code","execution_count":null,"metadata":{"id":"VaYUrh5n2iq9"},"outputs":[],"source":["# needed dependency to make HTTP calls\n","import requests\n","# dependency to construct tree structure\n","!pip install anytree\n","from anytree import Node, RenderTree"]},{"cell_type":"markdown","source":["The input value for all following queries is a ROR ID or ROR URL."],"metadata":{"id":"YmmrIwjv3QqG"}},{"cell_type":"code","source":["# input parameter\n","example_ror=\"https://ror.org/03vek6s52\""],"metadata":{"id":"UhY0RQcU3Q1Z","executionInfo":{"status":"ok","timestamp":1643279169086,"user_tz":-60,"elapsed":19,"user":{"displayName":"Sandra M","photoUrl":"https://lh3.googleusercontent.com/a-/AOh14GjjehryRcYlqHNFf_9Q6slGN_VZPE0y5QkvOxzG=s64","userId":"04602594913862593282"}}},"execution_count":2,"outputs":[]},{"cell_type":"markdown","source":["We may use it to query the ROR API once for the organization's metadata."],"metadata":{"id":"4MApaFfD6knr"}},{"cell_type":"code","source":["# URL to ROR API\n","ROR_API_ENDPOINT = \"https://api.ror.org/organizations\"\n","\n","# query ROR API for organization's metadata\n","def query_ror_api(ror):\n"," response = requests.get(url=requests.utils.requote_uri(ROR_API_ENDPOINT + \"/\" + ror),\n"," headers={'Content-Type': 'application/json'})\n"," result=response.json()\n"," return result\n","\n","#---- example execution\n","# uncomment following lines to see the metadata for specified example_ror\n","#import pprint\n","#organization = query_ror_api(example_ror)\n","#pprint.pprint(organization)"],"metadata":{"id":"YpwZ3mrC3dHO","executionInfo":{"status":"ok","timestamp":1643279169087,"user_tz":-60,"elapsed":16,"user":{"displayName":"Sandra M","photoUrl":"https://lh3.googleusercontent.com/a-/AOh14GjjehryRcYlqHNFf_9Q6slGN_VZPE0y5QkvOxzG=s64","userId":"04602594913862593282"}}},"execution_count":3,"outputs":[]},{"cell_type":"markdown","source":["But in this notebook we use it as a starting point to recursively query the ROR API using the relationship type \"`Child`\" to construct the organizational hierarchy below it."],"metadata":{"id":"T25jtRBf3c1T"}},{"cell_type":"code","source":["# construct organizational tree recursively starting at given ROR\n","def construct_tree(ror, parent=None):\n"," organization = query_ror_api(ror)\n"," current_node = Node(organization[\"name\"], parent=parent)\n","\n"," for rel in organization['relationships']:\n"," if rel[\"type\"]==\"Child\":\n"," construct_tree(rel[\"id\"], current_node)\n","\n"," return current_node\n","\n","\n","#---- example execution\n","organigram = construct_tree(example_ror)\n","print(RenderTree(organigram))"],"metadata":{"colab":{"base_uri":"https://localhost:8080/"},"id":"4jh1liI56A4x","executionInfo":{"status":"ok","timestamp":1643279175634,"user_tz":-60,"elapsed":6559,"user":{"displayName":"Sandra M","photoUrl":"https://lh3.googleusercontent.com/a-/AOh14GjjehryRcYlqHNFf_9Q6slGN_VZPE0y5QkvOxzG=s64","userId":"04602594913862593282"}},"outputId":"ea1cbf18-6c90-4aa3-bfcb-10addcaa9e8f"},"execution_count":4,"outputs":[{"output_type":"stream","name":"stdout","text":["Node('/Harvard University')\n","├── Node('/Harvard University/Athinoula A. Martinos Center for Biomedical Imaging')\n","├── Node('/Harvard University/Berenson Allen Center for Noninvasive Brain Stimulation')\n","├── Node('/Harvard University/Center for Astrophysics Harvard & Smithsonian')\n","│ ├── Node('/Harvard University/Center for Astrophysics Harvard & Smithsonian/Harvard College Observatory')\n","│ └── Node('/Harvard University/Center for Astrophysics Harvard & Smithsonian/Smithsonian Astrophysical Observatory')\n","├── Node('/Harvard University/Center for Systems Biology')\n","├── Node('/Harvard University/Center for Vascular Biology Research')\n","├── Node('/Harvard University/Gordon Center for Medical Imaging')\n","├── Node('/Harvard University/Harvard Stem Cell Institute')\n","├── Node('/Harvard University/Harvard University Press')\n","├── Node('/Harvard University/MIT-Harvard Center for Ultracold Atoms')\n","├── Node('/Harvard University/Ragon Institute of MGH, MIT and Harvard')\n","├── Node('/Harvard University/Sleep and Human Health Institute')\n","└── Node('/Harvard University/The NSF AI Institute for Artificial Intelligence and Fundamental Interactions')\n"]}]}]}
1+
{"nbformat":4,"nbformat_minor":0,"metadata":{"colab":{"name":"ror-organigram.ipynb","provenance":[{"file_id":"1yJn6R6ixeEZFU47XyeZsTiqhU-W7AS2H","timestamp":1643279199327}],"authorship_tag":"ABX9TyPEl1r8wtGqaTN4CJj87Lso"},"kernelspec":{"name":"python3","display_name":"Python 3"},"language_info":{"name":"python"}},"cells":[{"cell_type":"markdown","source":["### Query ROR for an organization and the hierarchy of sub-organizations below it\n","\n","This notebook queries the [ROR API](https://ror.readme.io/) to construct a hierarchy of sub-organizations starting at a given organization. It takes a ROR URL or ID which is used to retrieve the organizations specified in the metadata field \"`relationships`\" with `\"type\"=Child` recursively to build a tree structure. The tree represents the hierarchy of sub-organizations and will be outputted.\n"],"metadata":{"id":"0-62NAVa8DL0"}},{"cell_type":"code","execution_count":null,"metadata":{"id":"VaYUrh5n2iq9"},"outputs":[],"source":["# needed dependency to make HTTP calls\n","import requests\n","# dependency to construct tree structure\n","!pip install anytree\n","from anytree import Node, RenderTree"]},{"cell_type":"markdown","source":["The input value for all following queries is a ROR ID or ROR URL."],"metadata":{"id":"YmmrIwjv3QqG"}},{"cell_type":"code","source":["# input parameter\n","example_ror=\"https://ror.org/03vek6s52\""],"metadata":{"id":"UhY0RQcU3Q1Z","executionInfo":{"status":"ok","timestamp":1643279169086,"user_tz":-60,"elapsed":19,"user":{"displayName":"Sandra M","photoUrl":"https://lh3.googleusercontent.com/a-/AOh14GjjehryRcYlqHNFf_9Q6slGN_VZPE0y5QkvOxzG=s64","userId":"04602594913862593282"}}},"execution_count":2,"outputs":[]},{"cell_type":"markdown","source":["We may use it to query the ROR API once for the organization's metadata."],"metadata":{"id":"4MApaFfD6knr"}},{"cell_type":"code","source":["# URL to ROR API\n","ROR_API_ENDPOINT = \"https://api.ror.org/organizations\"\n","\n","# query ROR API for organization's metadata\n","def query_ror_api(ror):\n"," response = requests.get(url=requests.utils.requote_uri(ROR_API_ENDPOINT + \"/\" + ror),\n"," headers={'Content-Type': 'application/json'})\n"," result=response.json()\n"," return result\n","\n","#---- example execution\n","# uncomment following lines to see the metadata for specified example_ror\n","#import pprint\n","#organization = query_ror_api(example_ror)\n","#pprint.pprint(organization)"],"metadata":{"id":"YpwZ3mrC3dHO","executionInfo":{"status":"ok","timestamp":1643279169087,"user_tz":-60,"elapsed":16,"user":{"displayName":"Sandra M","photoUrl":"https://lh3.googleusercontent.com/a-/AOh14GjjehryRcYlqHNFf_9Q6slGN_VZPE0y5QkvOxzG=s64","userId":"04602594913862593282"}}},"execution_count":3,"outputs":[]},{"cell_type":"markdown","source":["But in this notebook we use it as a starting point to recursively query the ROR API using the relationship type \"`Child`\" to construct the organizational hierarchy below it."],"metadata":{"id":"T25jtRBf3c1T"}},{"cell_type":"code","source":["# construct organizational tree recursively starting at given ROR\n","def construct_tree(ror, parent=None):\n"," organization = query_ror_api(ror)\n"," current_node = Node(organization[\"name\"], parent=parent)\n","\n"," for rel in organization['relationships']:\n"," if rel[\"type\"]==\"Child\":\n"," construct_tree(rel[\"id\"], current_node)\n","\n"," return current_node\n","\n","\n","#---- example execution\n","organigram = construct_tree(example_ror)\n","print(RenderTree(organigram))"],"metadata":{"colab":{"base_uri":"https://localhost:8080/"},"id":"4jh1liI56A4x","executionInfo":{"status":"ok","timestamp":1643279175634,"user_tz":-60,"elapsed":6559,"user":{"displayName":"Sandra M","photoUrl":"https://lh3.googleusercontent.com/a-/AOh14GjjehryRcYlqHNFf_9Q6slGN_VZPE0y5QkvOxzG=s64","userId":"04602594913862593282"}},"outputId":"ea1cbf18-6c90-4aa3-bfcb-10addcaa9e8f"},"execution_count":4,"outputs":[{"output_type":"stream","name":"stdout","text":["Node('/Harvard University')\n","├── Node('/Harvard University/Athinoula A. Martinos Center for Biomedical Imaging')\n","├── Node('/Harvard University/Berenson Allen Center for Noninvasive Brain Stimulation')\n","├── Node('/Harvard University/Center for Astrophysics Harvard & Smithsonian')\n","│ ├── Node('/Harvard University/Center for Astrophysics Harvard & Smithsonian/Harvard College Observatory')\n","│ └── Node('/Harvard University/Center for Astrophysics Harvard & Smithsonian/Smithsonian Astrophysical Observatory')\n","├── Node('/Harvard University/Center for Systems Biology')\n","├── Node('/Harvard University/Center for Vascular Biology Research')\n","├── Node('/Harvard University/Gordon Center for Medical Imaging')\n","├── Node('/Harvard University/Harvard Stem Cell Institute')\n","├── Node('/Harvard University/Harvard University Press')\n","├── Node('/Harvard University/MIT-Harvard Center for Ultracold Atoms')\n","├── Node('/Harvard University/Ragon Institute of MGH, MIT and Harvard')\n","├── Node('/Harvard University/Sleep and Human Health Institute')\n","└── Node('/Harvard University/The NSF AI Institute for Artificial Intelligence and Fundamental Interactions')\n"]}]}]}

0 commit comments

Comments
 (0)