import os
import json
from kgforge.core import KnowledgeGraphForge
from kgforge.specializations.resources import Dataset
import getpass
TOKEN = getpass.getpass()
BUCKET = "dke/kgforge"
forge = KnowledgeGraphForge("../use-cases/prod-forge-nexus.yml",
bucket=BUCKET,
token=TOKEN
)
def make_id(i):
return f"{forge._store.endpoint}/resources/{forge._store.bucket}/_/dummy_resource_{i}"
resources = [forge.retrieve(make_id(i)) for i in range(10)]
len(resources)
10
def cs(res): return [e._store_metadata._constrainedBy for e in res]
cs(resources)
['https://bluebrain.github.io/nexus/schemas/unconstrained.json', 'https://bluebrain.github.io/nexus/schemas/unconstrained.json', 'https://bluebrain.github.io/nexus/schemas/unconstrained.json', 'https://bluebrain.github.io/nexus/schemas/unconstrained.json', 'https://bluebrain.github.io/nexus/schemas/unconstrained.json', 'https://bluebrain.github.io/nexus/schemas/unconstrained.json', 'https://bluebrain.github.io/nexus/schemas/unconstrained.json', 'https://bluebrain.github.io/nexus/schemas/unconstrained.json', 'https://bluebrain.github.io/nexus/schemas/unconstrained.json', 'https://bluebrain.github.io/nexus/schemas/unconstrained.json']
e = forge._store.update_schema(resources, schema_id="https://neuroshapes.org/dash/entity")
<count> 10 <action> _update_schema_many <succeeded> True
cs(resources)
['https://neuroshapes.org/dash/entity', 'https://neuroshapes.org/dash/entity', 'https://neuroshapes.org/dash/entity', 'https://neuroshapes.org/dash/entity', 'https://neuroshapes.org/dash/entity', 'https://neuroshapes.org/dash/entity', 'https://neuroshapes.org/dash/entity', 'https://neuroshapes.org/dash/entity', 'https://neuroshapes.org/dash/entity', 'https://neuroshapes.org/dash/entity']
e = forge._store.update_schema(resources[0], schema_id='https://bluebrain.github.io/nexus/schemas/unconstrained.json')
<action> _update_schema_one <succeeded> True
cs(resources)
e = forge._store.delete_schema(resources)
<count> 10 <action> _update_schema_many <succeeded> True
cs(resources)
['https://bluebrain.github.io/nexus/schemas/unconstrained.json', 'https://bluebrain.github.io/nexus/schemas/unconstrained.json', 'https://bluebrain.github.io/nexus/schemas/unconstrained.json', 'https://bluebrain.github.io/nexus/schemas/unconstrained.json', 'https://bluebrain.github.io/nexus/schemas/unconstrained.json', 'https://bluebrain.github.io/nexus/schemas/unconstrained.json', 'https://bluebrain.github.io/nexus/schemas/unconstrained.json', 'https://bluebrain.github.io/nexus/schemas/unconstrained.json', 'https://bluebrain.github.io/nexus/schemas/unconstrained.json', 'https://bluebrain.github.io/nexus/schemas/unconstrained.json']
for r in resources:
r._synchronized = False
e = forge.update(resources, schema_id="https://neuroshapes.org/dash/entity")
<count> 10 <action> _update_many <succeeded> True
cs(resources)
['https://neuroshapes.org/dash/entity', 'https://neuroshapes.org/dash/entity', 'https://neuroshapes.org/dash/entity', 'https://neuroshapes.org/dash/entity', 'https://neuroshapes.org/dash/entity', 'https://neuroshapes.org/dash/entity', 'https://neuroshapes.org/dash/entity', 'https://neuroshapes.org/dash/entity', 'https://neuroshapes.org/dash/entity', 'https://neuroshapes.org/dash/entity']
for r in resources:
r._synchronized = False
e = forge.update(resources, schema_id='https://bluebrain.github.io/nexus/schemas/unconstrained.json')
<count> 10 <action> _update_many <succeeded> True
cs(resources)
['https://bluebrain.github.io/nexus/schemas/unconstrained.json', 'https://bluebrain.github.io/nexus/schemas/unconstrained.json', 'https://bluebrain.github.io/nexus/schemas/unconstrained.json', 'https://bluebrain.github.io/nexus/schemas/unconstrained.json', 'https://bluebrain.github.io/nexus/schemas/unconstrained.json', 'https://bluebrain.github.io/nexus/schemas/unconstrained.json', 'https://bluebrain.github.io/nexus/schemas/unconstrained.json', 'https://bluebrain.github.io/nexus/schemas/unconstrained.json', 'https://bluebrain.github.io/nexus/schemas/unconstrained.json', 'https://bluebrain.github.io/nexus/schemas/unconstrained.json']
resources[0]._synchronized = False
forge.update(resources[0], schema_id="https://neuroshapes.org/dash/entity")
<action> _update_one <succeeded> True
cs(resources)
['https://neuroshapes.org/dash/entity', 'https://bluebrain.github.io/nexus/schemas/unconstrained.json', 'https://bluebrain.github.io/nexus/schemas/unconstrained.json', 'https://bluebrain.github.io/nexus/schemas/unconstrained.json', 'https://bluebrain.github.io/nexus/schemas/unconstrained.json', 'https://bluebrain.github.io/nexus/schemas/unconstrained.json', 'https://bluebrain.github.io/nexus/schemas/unconstrained.json', 'https://bluebrain.github.io/nexus/schemas/unconstrained.json', 'https://bluebrain.github.io/nexus/schemas/unconstrained.json', 'https://bluebrain.github.io/nexus/schemas/unconstrained.json']
resources[0]._synchronized = False
forge.update(resources[0], schema_id="https://bluebrain.github.io/nexus/schemas/unconstrained.json")
<action> _update_one <succeeded> True
cs(resources)
['https://bluebrain.github.io/nexus/schemas/unconstrained.json', 'https://bluebrain.github.io/nexus/schemas/unconstrained.json', 'https://bluebrain.github.io/nexus/schemas/unconstrained.json', 'https://bluebrain.github.io/nexus/schemas/unconstrained.json', 'https://bluebrain.github.io/nexus/schemas/unconstrained.json', 'https://bluebrain.github.io/nexus/schemas/unconstrained.json', 'https://bluebrain.github.io/nexus/schemas/unconstrained.json', 'https://bluebrain.github.io/nexus/schemas/unconstrained.json', 'https://bluebrain.github.io/nexus/schemas/unconstrained.json', 'https://bluebrain.github.io/nexus/schemas/unconstrained.json']