-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
267 additions
and
51 deletions.
There are no files selected for viewing
185 changes: 185 additions & 0 deletions
185
examples/notebooks/use-cases/BBP KG Forge retrieval.ipynb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,185 @@ | ||
{ | ||
"cells": [ | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 1, | ||
"id": "2c4aec45-da10-4b11-8469-b0e62f8a0c31", | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"import os\n", | ||
"import json\n", | ||
"\n", | ||
"from kgforge.core import KnowledgeGraphForge\n", | ||
"from kgforge.specializations.resources import Dataset" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 2, | ||
"id": "0ac8879d-b05b-482c-94b6-e46437291854", | ||
"metadata": {}, | ||
"outputs": [ | ||
{ | ||
"name": "stdin", | ||
"output_type": "stream", | ||
"text": [ | ||
" ········\n" | ||
] | ||
} | ||
], | ||
"source": [ | ||
"import getpass\n", | ||
"TOKEN = getpass.getpass()" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 3, | ||
"id": "eb70f64b-7ca2-4c71-a725-87cfd7ce2e1d", | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"BUCKET = \"dke/kgforge\"\n", | ||
"\n", | ||
"forge = KnowledgeGraphForge(\n", | ||
" \"../use-cases/prod-forge-nexus.yml\",\n", | ||
" bucket=BUCKET,\n", | ||
" token=TOKEN\n", | ||
")" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 8, | ||
"id": "826d1183-6898-4977-b7ee-9518e4095fef", | ||
"metadata": {}, | ||
"outputs": [ | ||
{ | ||
"name": "stdout", | ||
"output_type": "stream", | ||
"text": [ | ||
"Execution 0 - Value: id - Location: same bucket - Cross bucket: True - Retrieve source: True\n", | ||
"rev 3\n", | ||
"______________________\n", | ||
"Execution 1 - Value: self - Location: same bucket - Cross bucket: True - Retrieve source: True\n", | ||
"rev 3\n", | ||
"______________________\n", | ||
"Execution 2 - Value: id - Location: other bucket - Cross bucket: True - Retrieve source: True\n", | ||
"<action> catch_http_error\n", | ||
"<error> RetrievalError: failed to resolve 'https://bbp.epfl.ch/neurosciencegraph/data/9d64dc0d-07d1-4624-b409-cdc47ccda212' (latest) using resolvers of project 'dke/kgforge'\n", | ||
"\n", | ||
"Not found\n", | ||
"______________________\n", | ||
"Execution 3 - Value: id - Location: same bucket - Cross bucket: True - Retrieve source: False\n", | ||
"rev 3\n", | ||
"______________________\n", | ||
"Execution 4 - Value: self - Location: same bucket - Cross bucket: True - Retrieve source: False\n", | ||
"rev 3\n", | ||
"______________________\n", | ||
"Execution 5 - Value: id - Location: other bucket - Cross bucket: True - Retrieve source: False\n", | ||
"<action> catch_http_error\n", | ||
"<error> RetrievalError: failed to resolve 'https://bbp.epfl.ch/neurosciencegraph/data/9d64dc0d-07d1-4624-b409-cdc47ccda212' (latest) using resolvers of project 'dke/kgforge'\n", | ||
"\n", | ||
"Not found\n", | ||
"______________________\n", | ||
"Execution 6 - Value: id - Location: same bucket - Cross bucket: False - Retrieve source: True\n", | ||
"rev 3\n", | ||
"______________________\n", | ||
"Execution 7 - Value: self - Location: same bucket - Cross bucket: False - Retrieve source: True\n", | ||
"rev 3\n", | ||
"______________________\n", | ||
"Execution 8 - Value: id - Location: other bucket - Cross bucket: False - Retrieve source: True\n", | ||
"<action> catch_http_error\n", | ||
"<error> RetrievalError: resource 'https://bbp.epfl.ch/neurosciencegraph/data/9d64dc0d-07d1-4624-b409-cdc47ccda212' not found in project 'dke/kgforge'\n", | ||
"\n", | ||
"Not found\n", | ||
"______________________\n", | ||
"Execution 9 - Value: id - Location: same bucket - Cross bucket: False - Retrieve source: False\n", | ||
"rev 3\n", | ||
"______________________\n", | ||
"Execution 10 - Value: self - Location: same bucket - Cross bucket: False - Retrieve source: False\n", | ||
"rev 3\n", | ||
"______________________\n", | ||
"Execution 11 - Value: id - Location: other bucket - Cross bucket: False - Retrieve source: False\n", | ||
"<action> catch_http_error\n", | ||
"<error> RetrievalError: 404 Client Error: Not Found for url: https://bbp.epfl.ch/nexus/v1/resources/dke/kgforge/_/https%3A%2F%2Fbbp.epfl.ch%2Fneurosciencegraph%2Fdata%2F9d64dc0d-07d1-4624-b409-cdc47ccda212\n", | ||
"\n", | ||
"Not found\n", | ||
"______________________\n" | ||
] | ||
} | ||
], | ||
"source": [ | ||
"id_ = \"https://bbp.epfl.ch/nexus/v1/resources/dke/kgforge/_/20fbc97a-fb26-43ff-8093-9136aab25dff\"\n", | ||
"self_ = \"https://bbp.epfl.ch/nexus/v1/resources/dke/kgforge/_/https:%2F%2Fbbp.epfl.ch%2Fnexus%2Fv1%2Fresources%2Fdke%2Fkgforge%2F_%2F20fbc97a-fb26-43ff-8093-9136aab25dff\"\n", | ||
"\n", | ||
"id_other_bucket = \"https://bbp.epfl.ch/neurosciencegraph/data/9d64dc0d-07d1-4624-b409-cdc47ccda212\"\n", | ||
"self_other_bucket = \"https://bbp.epfl.ch/nexus/v1/resources/bbp/atlas/_/https:%2F%2Fbbp.epfl.ch%2Fneurosciencegraph%2Fdata%2Fallen_ccfv3_spatial_reference_system\"\n", | ||
"\n", | ||
"all_ret = [\n", | ||
" (id_, \"id\", \"same bucket\"), \n", | ||
" (self_, \"self\", \"same bucket\"), \n", | ||
" (id_other_bucket, \"id\", \"other bucket\"), \n", | ||
"]\n", | ||
"\n", | ||
"\n", | ||
"i = 0\n", | ||
"\n", | ||
"for cb in [True, False]:\n", | ||
" for rs in [True, False]:\n", | ||
" for (el, type_, loc) in all_ret:\n", | ||
"\n", | ||
" print(\n", | ||
" f\"Execution {i}\", \"-\", \n", | ||
" f\"Value: {type_}\", \"-\",\n", | ||
" f\"Location: {loc}\", \"-\", \n", | ||
" f\"Cross bucket: {cb}\", \"-\", \n", | ||
" f\"Retrieve source: {rs}\"\n", | ||
" )\n", | ||
"\n", | ||
" e = forge.retrieve(el, cross_bucket=cb, retrieve_source=rs)\n", | ||
"\n", | ||
" if not e:\n", | ||
" print(\"Not found\")\n", | ||
" else:\n", | ||
" print(\"rev\", e._store_metadata._rev)\n", | ||
" print(\"______________________\")\n", | ||
" i += 1" | ||
] | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"id": "32a9eb99-82d0-41c0-be8d-b4389698bc58", | ||
"metadata": {}, | ||
"source": [ | ||
"Failures: \n", | ||
"- 2 - \n", | ||
"- 5 - \n", | ||
"- 8 - To be expected: id from other bucket, and cross_bucket = False\n", | ||
"- 11 - To be expected: id from other bucket, and cross_bucket = False" | ||
] | ||
} | ||
], | ||
"metadata": { | ||
"kernelspec": { | ||
"display_name": "forge_venv", | ||
"language": "python", | ||
"name": "venv" | ||
}, | ||
"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.8.17" | ||
} | ||
}, | ||
"nbformat": 4, | ||
"nbformat_minor": 5 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters