{ "cells": [ { "cell_type": "markdown", "metadata": { "ExecuteTime": { "end_time": "2019-09-23T18:50:19.036357Z", "start_time": "2019-09-23T18:50:19.031896Z" } }, "source": [ "# Versioning\n", "\n", "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." ] }, { "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": { "ExecuteTime": { "end_time": "2019-09-23T15:42:21.191590Z", "start_time": "2019-09-23T15:42:21.184256Z" } }, "source": [ "## Tagging\n", "\n", "Tagging is used to provide a string identifier (tag) to a specific version of a resource." ] }, { "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.235417Z", "start_time": "2019-09-23T18:50:21.229695Z" } }, "outputs": [], "source": [ "jane._synchronized" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "ExecuteTime": { "end_time": "2019-09-23T18:50:21.244576Z", "start_time": "2019-09-23T18:50:21.238277Z" } }, "outputs": [], "source": [ "forge.tag(jane, \"v1\")" ] }, { "cell_type": "markdown", "metadata": { "ExecuteTime": { "end_time": "2019-09-23T15:56:05.768688Z", "start_time": "2019-09-23T15:56:05.760183Z" } }, "source": [ "### Error handling" ] }, { "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.255080Z", "start_time": "2019-09-23T18:50:21.248873Z" } }, "outputs": [], "source": [ "john._synchronized" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "ExecuteTime": { "end_time": "2019-09-23T18:50:21.262122Z", "start_time": "2019-09-23T18:50:21.257592Z" } }, "outputs": [], "source": [ "forge.tag(john, \"v1\")" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "john._last_action" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Freezing\n", "\n", "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." ] }, { "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": {}, "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": { "scrolled": true }, "outputs": [], "source": [ "forge.as_json(association)" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "try:\n", " # DemoStore\n", " print(jane._store_metadata.version)\n", "except:\n", " # BlueBrainNexus\n", " print(jane._store_metadata._rev)" ] }, { "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": [ "forge.freeze(association)" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "scrolled": true }, "outputs": [], "source": [ "forge.as_json(association)" ] } ], "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 }