{ "cells": [ { "cell_type": "code", "execution_count": 1, "id": "2c4aec45-da10-4b11-8469-b0e62f8a0c31", "metadata": {}, "outputs": [], "source": [ "from kgforge.core import KnowledgeGraphForge" ] }, { "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": "markdown", "id": "c0ea94f6-b66d-4761-909e-a508f61b72ee", "metadata": {}, "source": [ "Show-cases options for retrieval.\n", "- The identifiers used are\n", " - An `id` from the bucket of the configured forge instance\n", " - A `_self` from the bucket of the configured forge instance\n", " - An id from a bucket other than the one of the configured forge instance\n", " - A `_self` from a bucket other than the one of the configured forge instance\n", "- For either `retrieve_source = True` or `retrieve_source = False`\n", "- For `cross_bucket = True` or `cross_bucket = False`\n", "\n", "We expect that the following calls with fail:\n", "- An `id` from a bucket other than the one of the configured forge instance, with `cross_bucket = False`, with `retrieve_source = True` or `retrieve_source = False`\n", "- An `_self` from a bucket other than the one of the configured forge instance, with `cross_bucket = False`, with `retrieve_source = True` or `retrieve_source = False`\n", "\n", "In the case of the usage of `_self`, it is more clear that user input is the issue because the `_self` holds the bucket where the resource that is attempted to be retrieved is located.\n", "In the case of the usage of `id`, it is not possible to provide a meaningful error as to why the `id` could not be found in the forge instance's configured bucket. " ] }, { "cell_type": "code", "execution_count": 5, "id": "826d1183-6898-4977-b7ee-9518e4095fef", "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Execution 0 using: id inside: same bucket - Cross bucket: True - Retrieve source: True\n", "rev 3 https://bbp.neuroshapes.org https://bbp.epfl.ch/nexus/v1/resources/dke/kgforge/_/20fbc97a-fb26-43ff-8093-9136aab25dff\n", "______________________\n", "Execution 1 using: self inside: same bucket - Cross bucket: True - Retrieve source: True\n", "rev 3 https://bbp.neuroshapes.org https://bbp.epfl.ch/nexus/v1/resources/dke/kgforge/_/20fbc97a-fb26-43ff-8093-9136aab25dff\n", "______________________\n", "Execution 2 using: id inside: other bucket - Cross bucket: True - Retrieve source: True\n", "rev 3 https://bbp.neuroshapes.org http://purl.obolibrary.org/obo/GO_0038048\n", "______________________\n", "Execution 3 using: self inside: other bucket - Cross bucket: True - Retrieve source: True\n", "rev 3 https://bbp.neuroshapes.org http://purl.obolibrary.org/obo/GO_0038048\n", "______________________\n", "Execution 4 using: id inside: same bucket - Cross bucket: False - Retrieve source: True\n", "rev 3 https://bbp.neuroshapes.org https://bbp.epfl.ch/nexus/v1/resources/dke/kgforge/_/20fbc97a-fb26-43ff-8093-9136aab25dff\n", "______________________\n", "Execution 5 using: self inside: same bucket - Cross bucket: False - Retrieve source: True\n", "rev 3 https://bbp.neuroshapes.org https://bbp.epfl.ch/nexus/v1/resources/dke/kgforge/_/20fbc97a-fb26-43ff-8093-9136aab25dff\n", "______________________\n", "Execution 6 using: id inside: other bucket - Cross bucket: False - Retrieve source: True\n", " catch_http_error\n", " RetrievalError: 404 Client Error: Not Found for url: https://bbp.epfl.ch/nexus/v1/resources/dke/kgforge/_/http%3A%2F%2Fpurl.obolibrary.org%2Fobo%2FGO_0038048\n", "\n", "Not found\n", "______________________\n", "Execution 7 using: self inside: other bucket - Cross bucket: False - Retrieve source: True\n", " retrieve\n", " RetrievalError: Provided resource identifier https://bbp.epfl.ch/nexus/v1/resources/neurosciencegraph/datamodels/_/http:%2F%2Fpurl.obolibrary.org%2Fobo%2FGO_0038048 is not inside the current bucket, use cross_bucket=True to be able to retrieve it\n", "\n", "Not found\n", "______________________\n", "Execution 8 using: id inside: same bucket - Cross bucket: True - Retrieve source: False\n", "rev 3 https://bbp.neuroshapes.org https://bbp.epfl.ch/nexus/v1/resources/dke/kgforge/_/20fbc97a-fb26-43ff-8093-9136aab25dff\n", "______________________\n", "Execution 9 using: self inside: same bucket - Cross bucket: True - Retrieve source: False\n", "rev 3 https://bbp.neuroshapes.org https://bbp.epfl.ch/nexus/v1/resources/dke/kgforge/_/20fbc97a-fb26-43ff-8093-9136aab25dff\n", "______________________\n", "Execution 10 using: id inside: other bucket - Cross bucket: True - Retrieve source: False\n", "rev 3 https://bbp.neuroshapes.org GO:0038048\n", "______________________\n", "Execution 11 using: self inside: other bucket - Cross bucket: True - Retrieve source: False\n", "rev 3 https://bbp.neuroshapes.org GO:0038048\n", "______________________\n", "Execution 12 using: id inside: same bucket - Cross bucket: False - Retrieve source: False\n", "rev 3 https://bbp.neuroshapes.org https://bbp.epfl.ch/nexus/v1/resources/dke/kgforge/_/20fbc97a-fb26-43ff-8093-9136aab25dff\n", "______________________\n", "Execution 13 using: self inside: same bucket - Cross bucket: False - Retrieve source: False\n", "rev 3 https://bbp.neuroshapes.org https://bbp.epfl.ch/nexus/v1/resources/dke/kgforge/_/20fbc97a-fb26-43ff-8093-9136aab25dff\n", "______________________\n", "Execution 14 using: id inside: other bucket - Cross bucket: False - Retrieve source: False\n", " catch_http_error\n", " RetrievalError: 404 Client Error: Not Found for url: https://bbp.epfl.ch/nexus/v1/resources/dke/kgforge/_/http%3A%2F%2Fpurl.obolibrary.org%2Fobo%2FGO_0038048\n", "\n", "Not found\n", "______________________\n", "Execution 15 using: self inside: other bucket - Cross bucket: False - Retrieve source: False\n", " retrieve\n", " RetrievalError: Provided resource identifier https://bbp.epfl.ch/nexus/v1/resources/neurosciencegraph/datamodels/_/http:%2F%2Fpurl.obolibrary.org%2Fobo%2FGO_0038048 is not inside the current bucket, use cross_bucket=True to be able to retrieve it\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 = \"http://purl.obolibrary.org/obo/GO_0038048\"\n", "self_other_bucket = \"https://bbp.epfl.ch/nexus/v1/resources/neurosciencegraph/datamodels/_/http:%2F%2Fpurl.obolibrary.org%2Fobo%2FGO_0038048\"\n", "\n", "all_ret = [\n", " (id_, \"id\", \"same bucket\"), \n", " (self_, \"self\", \"same bucket\"), \n", " (id_other_bucket, \"id\", \"other bucket\"),\n", " (self_other_bucket, \"self\", \"other bucket\"),\n", "]\n", "\n", "i = 0\n", "\n", "for rs in [True, False]:\n", " for cb in [True, False]:\n", " for (el, type_, loc) in all_ret:\n", "\n", " print(f\"Execution {i}\", \" using: \", type_, \"inside: \", loc, \" - Cross bucket:\", cb, \" - Retrieve source:\", rs)\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, e.context, e.id)\n", " print(\"______________________\")\n", " i += 1\n" ] } ], "metadata": { "kernelspec": { "display_name": "forge_venv2", "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 }