{ "cells": [ { "cell_type": "markdown", "metadata": { "ExecuteTime": { "end_time": "2019-09-23T18:50:19.036357Z", "start_time": "2019-09-23T18:50:19.031896Z" } }, "source": [ "# Storing\n", "\n", "This notebook demonstrates [Storing](https://nexus-forge.readthedocs.io/en/latest/interaction.html#storing) features." ] }, { "cell_type": "code", "execution_count": null, "metadata": { "ExecuteTime": { "end_time": "2019-09-23T18:50:20.068658Z", "start_time": "2019-09-23T18:50:19.054054Z" } }, "outputs": [], "source": [ "from kgforge.core import KnowledgeGraphForge" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "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)." ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "forge = KnowledgeGraphForge(\"../../configurations/forge.yml\")" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Imports" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "from kgforge.core import Resource" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Registration" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### resources" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "jane = Resource(type=\"Person\", name=\"Jane Doe\")" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "association = Resource(type=\"Association\", agent=jane)" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "ExecuteTime": { "end_time": "2019-09-23T18:50:21.048776Z", "start_time": "2019-09-23T18:50:21.037127Z" } }, "outputs": [], "source": [ "forge.register(association)" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "ExecuteTime": { "end_time": "2019-09-23T18:50:21.101282Z", "start_time": "2019-09-23T18:50:21.090545Z" } }, "outputs": [], "source": [ "association._synchronized" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "ExecuteTime": { "end_time": "2019-09-23T18:50:21.086424Z", "start_time": "2019-09-23T18:50:21.078142Z" }, "scrolled": true }, "outputs": [], "source": [ "association._last_action" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "ExecuteTime": { "end_time": "2019-09-23T18:50:21.074512Z", "start_time": "2019-09-23T18:50:21.061121Z" } }, "outputs": [], "source": [ "association._store_metadata" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### automatic status update" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "john = Resource(type=\"Person\", name=\"John Smith\")" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "ExecuteTime": { "end_time": "2019-09-23T18:50:21.109091Z", "start_time": "2019-09-23T18:50:21.105159Z" } }, "outputs": [], "source": [ "association.agent = john" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "ExecuteTime": { "end_time": "2019-09-23T18:50:21.121071Z", "start_time": "2019-09-23T18:50:21.112867Z" } }, "outputs": [], "source": [ "association._synchronized" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### error handling" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "persons = [jane, john]" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "ExecuteTime": { "end_time": "2019-09-23T18:50:21.132160Z", "start_time": "2019-09-23T18:50:21.123851Z" } }, "outputs": [], "source": [ "forge.register(jane)" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "ExecuteTime": { "end_time": "2019-09-23T18:50:21.141175Z", "start_time": "2019-09-23T18:50:21.134967Z" } }, "outputs": [], "source": [ "forge.register(persons)" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "ExecuteTime": { "end_time": "2019-09-23T18:50:21.150719Z", "start_time": "2019-09-23T18:50:21.143812Z" } }, "outputs": [], "source": [ "jane._synchronized" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "ExecuteTime": { "end_time": "2019-09-23T18:50:21.159904Z", "start_time": "2019-09-23T18:50:21.153635Z" } }, "outputs": [], "source": [ "john._synchronized" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### files" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Note: DemoStore doesn't implement file operations yet. Please use another store for this section." ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "distribution = forge.attach(\"../../data/persons.csv\")" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "jane = Resource(type=\"Person\", name=\"Jane Doe\", distribution=distribution)" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "forge.register(jane)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "#### custom content type" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "distribution = forge.attach(\"../../data/my_data.xwz\", content_type=\"application/xwz\")" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "john = Resource(type=\"Person\", name=\"John Smith\", distribution=distribution)" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "forge.register(john)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Updating" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "jane = Resource(type=\"Person\", name=\"Jane Doe\")" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "association = Resource(type=\"Association\", agent=jane)" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "forge.register(association)" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "try:\n", " # DemoStore\n", " print(association._store_metadata.version)\n", "except:\n", " # BlueBrainNexus\n", " print(association._store_metadata._rev)" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "john = Resource(type=\"Person\", name=\"John Smith\")" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "association.agent = john" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "ExecuteTime": { "end_time": "2019-09-23T18:50:21.190111Z", "start_time": "2019-09-23T18:50:21.182709Z" } }, "outputs": [], "source": [ "forge.update(association)" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "ExecuteTime": { "end_time": "2019-09-23T18:50:21.199561Z", "start_time": "2019-09-23T18:50:21.192465Z" } }, "outputs": [], "source": [ "association._synchronized" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "ExecuteTime": { "end_time": "2019-09-23T18:50:21.217024Z", "start_time": "2019-09-23T18:50:21.208547Z" } }, "outputs": [], "source": [ "try:\n", " # DemoStore\n", " print(association._store_metadata.version)\n", "except:\n", " # BlueBrainNexus\n", " print(association._store_metadata._rev)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Deprecation" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "jane = Resource(type=\"Person\", name=\"Jane Doe\")" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "forge.register(jane)" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "ExecuteTime": { "end_time": "2019-09-23T18:50:21.276769Z", "start_time": "2019-09-23T18:50:21.266848Z" } }, "outputs": [], "source": [ "try:\n", " # DemoStore\n", " print(jane._store_metadata.deprecated)\n", "except:\n", " # BlueBrainNexus\n", " print(jane._store_metadata._deprecated)" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "ExecuteTime": { "end_time": "2019-09-23T18:50:21.286647Z", "start_time": "2019-09-23T18:50:21.279510Z" } }, "outputs": [], "source": [ "forge.deprecate(jane)" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "ExecuteTime": { "end_time": "2019-09-23T18:50:21.297768Z", "start_time": "2019-09-23T18:50:21.290504Z" } }, "outputs": [], "source": [ "try:\n", " # DemoStore\n", " print(jane._store_metadata.deprecated)\n", "except:\n", " # BlueBrainNexus\n", " print(jane._store_metadata._deprecated)" ] } ], "metadata": { "kernelspec": { "display_name": "Python (nexusforgelatest)", "language": "python", "name": "nexusforgelatest" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.6.10" } }, "nbformat": 4, "nbformat_minor": 4 }