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 versions.
from kgforge.core import KnowledgeGraphForge
forge = KnowledgeGraphForge("../../configurations/demo-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")
<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 resources it is possible to refer to 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
print(association)
{ id: 47486895-afc0-4f6f-94ac-265a63556b30 type: Association agent: { id: f33b9536-b01a-4010-818c-587172990b65 type: Person name: Jane Doe } }
jane._store_metadata.version
1
association._store_metadata.version
1
forge.freeze(association)
<action> _freeze_one <succeeded> True
print(association)
{ id: 47486895-afc0-4f6f-94ac-265a63556b30_version=1 type: Association agent: { id: f33b9536-b01a-4010-818c-587172990b65_version=1 type: Person name: Jane Doe } }