#!/usr/bin/env python # coding: utf-8 # # Storing # # This notebook demonstrates [Storing](https://nexus-forge.readthedocs.io/en/latest/interaction.html#storing) features. Storing allows users to persist and manage Resources in the configured store. # In[25]: 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[26]: forge = KnowledgeGraphForge("../../configurations/forge.yml") # ## Imports # In[27]: from kgforge.core import Resource # ## Registration # ### resources # In[28]: jane = Resource(type="Person", name="Jane Doe") # In[29]: association = Resource(type="Association", agent=jane) print(association) # In[30]: forge.register(association) # In[31]: association._synchronized # In[32]: association._last_action # In[33]: association._store_metadata # ### automatic status update # In[34]: john = Resource(type="Person", name="John Smith") # In[35]: association.agent = john # In[36]: association._synchronized # _synchronized becomes False whenever the resource is updated # ### error handling # In[37]: persons = [jane, john] # In[38]: forge.register(jane) # In[39]: forge.register(persons) # it is not allowed to register an already registered resource without local change # In[40]: jane._synchronized # In[41]: john._synchronized # ### files # Note: DemoStore doesn't implement file operations yet. Please use another store for this section. # In[42]: distribution = forge.attach("../../data/persons.csv") # In[43]: jane = Resource(type="Person", name="Jane Doe", distribution=distribution) # In[44]: forge.register(jane) # #### custom content type # In[45]: distribution = forge.attach("../../data/my_data.xwz", content_type="application/xwz") # In[46]: john = Resource(type="Person", name="John Smith", distribution=distribution) print(john) # In[47]: forge.register(john) # ## Updating # In[48]: jane = Resource(type="Person", name="Jane Doe") # In[49]: association = Resource(type="Association", agent=jane) # In[50]: forge.register(association) # In[51]: try: # DemoStore print(association._store_metadata.version) except: # BlueBrainNexus print(association._store_metadata._rev) # In[52]: john = Resource(type="Person", name="John Smith") # In[53]: association.agent = john # In[54]: forge.update(association) # In[55]: association.agent._synchronized # In[56]: try: # DemoStore print(association._store_metadata.version) except: # BlueBrainNexus print(association._store_metadata._rev) # ## Deprecation # In[57]: jane = Resource(type="Person", name="Jane Doe") print(jane) # In[58]: forge.register(jane) # In[59]: jane._synchronized # In[60]: try: # DemoStore print(jane._store_metadata.deprecated) except: # BlueBrainNexus print(jane._store_metadata._deprecated) # In[61]: forge.deprecate(jane) # In[62]: try: # DemoStore print(jane._store_metadata.deprecated) except: # BlueBrainNexus print(jane._store_metadata._deprecated)