#!/usr/bin/env python # coding: utf-8 # # Storing # # This notebook demonstrates [Storing](https://nexus-forge.readthedocs.io/en/latest/interaction.html#storing) features. # In[ ]: 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[ ]: forge = KnowledgeGraphForge("../../configurations/forge.yml") # ## Imports # In[ ]: from kgforge.core import Resource # ## Registration # ### resources # In[ ]: jane = Resource(type="Person", name="Jane Doe") # In[ ]: association = Resource(type="Association", agent=jane) # In[ ]: forge.register(association) # In[ ]: association._synchronized # In[ ]: association._last_action # In[ ]: association._store_metadata # ### automatic status update # In[ ]: john = Resource(type="Person", name="John Smith") # In[ ]: association.agent = john # In[ ]: association._synchronized # ### error handling # In[ ]: persons = [jane, john] # In[ ]: forge.register(jane) # In[ ]: forge.register(persons) # In[ ]: jane._synchronized # In[ ]: john._synchronized # ### files # Note: DemoStore doesn't implement file operations yet. Please use another store for this section. # In[ ]: distribution = forge.attach("../../data/persons.csv") # In[ ]: jane = Resource(type="Person", name="Jane Doe", distribution=distribution) # In[ ]: forge.register(jane) # #### custom content type # In[ ]: distribution = forge.attach("../../data/my_data.xwz", content_type="application/xwz") # In[ ]: john = Resource(type="Person", name="John Smith", distribution=distribution) # In[ ]: forge.register(john) # ## Updating # In[ ]: jane = Resource(type="Person", name="Jane Doe") # In[ ]: association = Resource(type="Association", agent=jane) # In[ ]: forge.register(association) # In[ ]: try: # DemoStore print(association._store_metadata.version) except: # BlueBrainNexus print(association._store_metadata._rev) # In[ ]: john = Resource(type="Person", name="John Smith") # In[ ]: association.agent = john # In[ ]: forge.update(association) # In[ ]: association._synchronized # In[ ]: try: # DemoStore print(association._store_metadata.version) except: # BlueBrainNexus print(association._store_metadata._rev) # ## Deprecation # In[ ]: jane = Resource(type="Person", name="Jane Doe") # In[ ]: forge.register(jane) # In[ ]: try: # DemoStore print(jane._store_metadata.deprecated) except: # BlueBrainNexus print(jane._store_metadata._deprecated) # In[ ]: forge.deprecate(jane) # In[ ]: try: # DemoStore print(jane._store_metadata.deprecated) except: # BlueBrainNexus print(jane._store_metadata._deprecated)