The Storing notebook showed that the store metadata can contain a version of a specific resource. This notebook demonstrates other functionalities that are related to versioning data such as tagging.
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
Tagging is used to provide a string identifier (tag) to a specific version of a resource.
jane = Resource(type="Person", name="Jane Doe")
forge.register(jane)
<action> _register_one <succeeded> True
jane._synchronized
True
forge.tag(jane, "v1")
<action> _tag_one <succeeded> True
john = Resource(type="Person", name="John Smith")
john._synchronized
False
forge.tag(john, "v1") # only _synchronized resources (i.e registered and without further changes) can be tagged
<action> _tag_one <succeeded> False <error> TaggingError: resource should have an id
john._last_action
Action(error='TaggingError', message='resource should have an id', operation='_tag_one', succeeded=False)
When linking to a resource it is possible to refer to a specific version by freezing it. In this demo example, the version is attached to the resource identifier, and this is specified in the versioned_id_template
property on the Store section in the configuration file.
jane = Resource(type="Person", name="Jane Doe")
forge.register(jane)
<action> _register_one <succeeded> True
association = Resource(type="Association", agent=jane)
forge.register(association)
<action> _register_one <succeeded> True
forge.as_json(association)
{'id': 'https://bbp.epfl.ch/nexus/v1/resources/dke/kgforge/_/3a112a8b-bc32-40c9-8503-c949a3e0dfb7', 'type': 'Association', 'agent': {'id': 'https://bbp.epfl.ch/nexus/v1/resources/dke/kgforge/_/ef908022-f24a-4fdf-8c23-c0f4261dce0c', 'type': 'Person', 'name': 'Jane Doe'}}
try:
# DemoStore
print(jane._store_metadata.version)
except:
# BlueBrainNexus
print(jane._store_metadata._rev)
1
try:
# DemoStore
print(association._store_metadata.version)
except:
# BlueBrainNexus
print(association._store_metadata._rev)
1
forge.freeze(association)
<action> _freeze_one <succeeded> True
forge.as_json(association)
{'id': 'https://bbp.epfl.ch/nexus/v1/resources/dke/kgforge/_/3a112a8b-bc32-40c9-8503-c949a3e0dfb7?rev=1', 'type': 'Association', 'agent': {'id': 'https://bbp.epfl.ch/nexus/v1/resources/dke/kgforge/_/ef908022-f24a-4fdf-8c23-c0f4261dce0c?rev=1', 'type': 'Person', 'name': 'Jane Doe'}}