from kgforge.core import KnowledgeGraphForge
A configuration file is needed in order to create a KnowledgeGraphForge session. A configuration can be generated using the notebook 00-Initialization.ipynb.
forge = KnowledgeGraphForge("../../configurations/forge.yml")
from kgforge.core import Resource
jane = Resource(type="Person", name="Jane Doe")
association = Resource(type="Association", agent=jane)
print(association)
{ type: Association agent: { type: Person name: Jane Doe } }
forge.register(association)
<action> _register_one <succeeded> True
association._synchronized
True
association._last_action
Action(error=None, message=None, operation='_register_one', succeeded=True)
association._store_metadata
{'id': 'https://bbp.epfl.ch/nexus/v1/resources/dke/kgforge/_/24dbbd9e-92e0-4519-99d7-ec9bae56f7ea', '_constrainedBy': 'https://bluebrain.github.io/nexus/schemas/unconstrained.json', '_createdAt': '2022-04-12T15:54:23.358Z', '_createdBy': 'https://bbp.epfl.ch/nexus/v1/realms/bbp/users/sy', '_deprecated': False, '_incoming': 'https://bbp.epfl.ch/nexus/v1/resources/dke/kgforge/_/24dbbd9e-92e0-4519-99d7-ec9bae56f7ea/incoming', '_outgoing': 'https://bbp.epfl.ch/nexus/v1/resources/dke/kgforge/_/24dbbd9e-92e0-4519-99d7-ec9bae56f7ea/outgoing', '_project': 'https://bbp.epfl.ch/nexus/v1/projects/dke/kgforge', '_rev': 1, '_schemaProject': 'https://bbp.epfl.ch/nexus/v1/projects/dke/kgforge', '_self': 'https://bbp.epfl.ch/nexus/v1/resources/dke/kgforge/_/24dbbd9e-92e0-4519-99d7-ec9bae56f7ea', '_updatedAt': '2022-04-12T15:54:23.358Z', '_updatedBy': 'https://bbp.epfl.ch/nexus/v1/realms/bbp/users/sy'}
john = Resource(type="Person", name="John Smith")
association.agent = john
association._synchronized # _synchronized becomes False whenever the resource is updated
False
persons = [jane, john]
forge.register(jane)
<action> _register_one <succeeded> True
forge.register(persons) # it is not allowed to register an already registered resource without local change
<count> 1 <action> _register_many <succeeded> False <error> RegistrationError: resource should not be synchronized <count> 1 <action> _register_many <succeeded> True
jane._synchronized
False
john._synchronized
True
Note: DemoStore doesn't implement file operations yet. Please use another store for this section.
distribution = forge.attach("../../data/persons.csv")
jane = Resource(type="Person", name="Jane Doe", distribution=distribution)
forge.register(jane)
<action> _register_one <succeeded> True
distribution = forge.attach("../../data/my_data.xwz", content_type="application/xwz")
john = Resource(type="Person", name="John Smith", distribution=distribution)
print(john)
{ type: Person distribution: LazyAction(operation=Store.upload, args=['../../data/my_data.xwz', 'application/xwz']) name: John Smith }
forge.register(john)
<action> _register_one <succeeded> True
jane = Resource(type="Person", name="Jane Doe")
association = Resource(type="Association", agent=jane)
forge.register(association)
<action> _register_one <succeeded> True
try:
# DemoStore
print(association._store_metadata.version)
except:
# BlueBrainNexus
print(association._store_metadata._rev)
1
john = Resource(type="Person", name="John Smith")
association.agent = john
forge.update(association)
<action> _update_one <succeeded> True
association.agent._synchronized
False
try:
# DemoStore
print(association._store_metadata.version)
except:
# BlueBrainNexus
print(association._store_metadata._rev)
2
jane = Resource(type="Person", name="Jane Doe")
print(jane)
{ type: Person name: Jane Doe }
forge.register(jane)
<action> _register_one <succeeded> True
jane._synchronized
True
try:
# DemoStore
print(jane._store_metadata.deprecated)
except:
# BlueBrainNexus
print(jane._store_metadata._deprecated)
False
forge.deprecate(jane)
<action> _deprecate_one <succeeded> True
try:
# DemoStore
print(jane._store_metadata.deprecated)
except:
# BlueBrainNexus
print(jane._store_metadata._deprecated)
True