#!/usr/bin/env python # coding: utf-8 # # Versioning # # The [Storing](03%20-%20Storing.ipynb) notebook showed that the store metadata can contain a version of a specific resource. This notebook demonstrates other functionalities that are related to [versioning](https://nexus-forge.readthedocs.io/en/latest/interaction.html#versioning) data such as tagging. # In[1]: 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](00%20-%20Initialization.ipynb). # In[2]: forge = KnowledgeGraphForge("../../configurations/forge.yml") # ## Imports # In[3]: from kgforge.core import Resource # ## Tagging # # Tagging is used to provide a string identifier (tag) to a specific version of a resource. # In[4]: jane = Resource(type="Person", name="Jane Doe") # In[5]: forge.register(jane) # In[6]: jane._synchronized # In[7]: forge.tag(jane, "v1") # ### Error handling # In[8]: john = Resource(type="Person", name="John Smith") # In[9]: john._synchronized # In[10]: forge.tag(john, "v1") # only _synchronized resources (i.e registered and without further changes) can be tagged # In[11]: john._last_action # ## Freezing # # 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. # In[12]: jane = Resource(type="Person", name="Jane Doe") # In[13]: forge.register(jane) # In[14]: association = Resource(type="Association", agent=jane) # In[15]: forge.register(association) # In[16]: forge.as_json(association) # In[17]: try: # DemoStore print(jane._store_metadata.version) except: # BlueBrainNexus print(jane._store_metadata._rev) # In[18]: try: # DemoStore print(association._store_metadata.version) except: # BlueBrainNexus print(association._store_metadata._rev) # In[19]: forge.freeze(association) # In[20]: forge.as_json(association)