from kgforge.core import KnowledgeGraphForge
import getpass
TOKEN = getpass.getpass()
BUCKET = "dke/kgforge"
forge = KnowledgeGraphForge(
"../use-cases/prod-forge-nexus.yml",
bucket=BUCKET,
token=TOKEN
)
Show-cases options for retrieval.
id
from the bucket of the configured forge instance_self
from the bucket of the configured forge instance_self
from a bucket other than the one of the configured forge instanceretrieve_source = True
or retrieve_source = False
cross_bucket = True
or cross_bucket = False
We expect that the following calls with fail:
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
_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
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.
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.
id_ = "https://bbp.epfl.ch/nexus/v1/resources/dke/kgforge/_/20fbc97a-fb26-43ff-8093-9136aab25dff"
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"
id_other_bucket = "http://purl.obolibrary.org/obo/GO_0038048"
self_other_bucket = "https://bbp.epfl.ch/nexus/v1/resources/neurosciencegraph/datamodels/_/http:%2F%2Fpurl.obolibrary.org%2Fobo%2FGO_0038048"
all_ret = [
(id_, "id", "same bucket"),
(self_, "self", "same bucket"),
(id_other_bucket, "id", "other bucket"),
(self_other_bucket, "self", "other bucket"),
]
i = 0
for rs in [True, False]:
for cb in [True, False]:
for (el, type_, loc) in all_ret:
print(f"Execution {i}", " using: ", type_, "inside: ", loc, " - Cross bucket:", cb, " - Retrieve source:", rs)
e = forge.retrieve(el, cross_bucket=cb, retrieve_source=rs)
if not e:
print("Not found")
else:
print("rev", e._store_metadata._rev, e.context, e.id)
print("______________________")
i += 1
Execution 0 using: id inside: same bucket - Cross bucket: True - Retrieve source: True rev 3 https://bbp.neuroshapes.org https://bbp.epfl.ch/nexus/v1/resources/dke/kgforge/_/20fbc97a-fb26-43ff-8093-9136aab25dff ______________________ Execution 1 using: self inside: same bucket - Cross bucket: True - Retrieve source: True rev 3 https://bbp.neuroshapes.org https://bbp.epfl.ch/nexus/v1/resources/dke/kgforge/_/20fbc97a-fb26-43ff-8093-9136aab25dff ______________________ Execution 2 using: id inside: other bucket - Cross bucket: True - Retrieve source: True rev 3 https://bbp.neuroshapes.org http://purl.obolibrary.org/obo/GO_0038048 ______________________ Execution 3 using: self inside: other bucket - Cross bucket: True - Retrieve source: True rev 3 https://bbp.neuroshapes.org http://purl.obolibrary.org/obo/GO_0038048 ______________________ Execution 4 using: id inside: same bucket - Cross bucket: False - Retrieve source: True rev 3 https://bbp.neuroshapes.org https://bbp.epfl.ch/nexus/v1/resources/dke/kgforge/_/20fbc97a-fb26-43ff-8093-9136aab25dff ______________________ Execution 5 using: self inside: same bucket - Cross bucket: False - Retrieve source: True rev 3 https://bbp.neuroshapes.org https://bbp.epfl.ch/nexus/v1/resources/dke/kgforge/_/20fbc97a-fb26-43ff-8093-9136aab25dff ______________________ Execution 6 using: id inside: other bucket - Cross bucket: False - Retrieve source: True <action> catch_http_error <error> 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 Not found ______________________ Execution 7 using: self inside: other bucket - Cross bucket: False - Retrieve source: True <action> retrieve <error> 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 Not found ______________________ Execution 8 using: id inside: same bucket - Cross bucket: True - Retrieve source: False rev 3 https://bbp.neuroshapes.org https://bbp.epfl.ch/nexus/v1/resources/dke/kgforge/_/20fbc97a-fb26-43ff-8093-9136aab25dff ______________________ Execution 9 using: self inside: same bucket - Cross bucket: True - Retrieve source: False rev 3 https://bbp.neuroshapes.org https://bbp.epfl.ch/nexus/v1/resources/dke/kgforge/_/20fbc97a-fb26-43ff-8093-9136aab25dff ______________________ Execution 10 using: id inside: other bucket - Cross bucket: True - Retrieve source: False rev 3 https://bbp.neuroshapes.org GO:0038048 ______________________ Execution 11 using: self inside: other bucket - Cross bucket: True - Retrieve source: False rev 3 https://bbp.neuroshapes.org GO:0038048 ______________________ Execution 12 using: id inside: same bucket - Cross bucket: False - Retrieve source: False rev 3 https://bbp.neuroshapes.org https://bbp.epfl.ch/nexus/v1/resources/dke/kgforge/_/20fbc97a-fb26-43ff-8093-9136aab25dff ______________________ Execution 13 using: self inside: same bucket - Cross bucket: False - Retrieve source: False rev 3 https://bbp.neuroshapes.org https://bbp.epfl.ch/nexus/v1/resources/dke/kgforge/_/20fbc97a-fb26-43ff-8093-9136aab25dff ______________________ Execution 14 using: id inside: other bucket - Cross bucket: False - Retrieve source: False <action> catch_http_error <error> 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 Not found ______________________ Execution 15 using: self inside: other bucket - Cross bucket: False - Retrieve source: False <action> retrieve <error> 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 Not found ______________________