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://sandbox.bluebrainnexus.io/v1/resources/github-users/crisely09/_/55be8922-befa-40a1-a1fe-056c0a787e1f', '_constrainedBy': 'https://bluebrain.github.io/nexus/schemas/unconstrained.json', '_createdAt': '2024-05-31T13:25:28.690Z', '_createdBy': 'https://sandbox.bluebrainnexus.io/v1/realms/github/users/crisely09', '_deprecated': False, '_incoming': 'https://sandbox.bluebrainnexus.io/v1/resources/github-users/crisely09/_/https:%2F%2Fsandbox.bluebrainnexus.io%2Fv1%2Fresources%2Fgithub-users%2Fcrisely09%2F_%2F55be8922-befa-40a1-a1fe-056c0a787e1f/incoming', '_outgoing': 'https://sandbox.bluebrainnexus.io/v1/resources/github-users/crisely09/_/https:%2F%2Fsandbox.bluebrainnexus.io%2Fv1%2Fresources%2Fgithub-users%2Fcrisely09%2F_%2F55be8922-befa-40a1-a1fe-056c0a787e1f/outgoing', '_project': 'https://sandbox.bluebrainnexus.io/v1/projects/github-users/crisely09', '_rev': 1, '_schemaProject': 'https://sandbox.bluebrainnexus.io/v1/projects/github-users/crisely09', '_self': 'https://sandbox.bluebrainnexus.io/v1/resources/github-users/crisely09/_/https:%2F%2Fsandbox.bluebrainnexus.io%2Fv1%2Fresources%2Fgithub-users%2Fcrisely09%2F_%2F55be8922-befa-40a1-a1fe-056c0a787e1f', '_updatedAt': '2024-05-31T13:25:28.690Z', '_updatedBy': 'https://sandbox.bluebrainnexus.io/v1/realms/github/users/crisely09'}
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> False <error> RegistrationError: resource should not be synchronized
forge.register(persons) # it is not allowed to register an already registered resource without local change
<count> 2 <action> _register_many <succeeded> True
jane._synchronized
True
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', <kgforge.core.forge.KnowledgeGraphForge object at 0x7fd2181ed790>]) 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
True
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