diff --git a/examples/notebooks/use-cases/BBP KG Schema changes.ipynb b/examples/notebooks/use-cases/BBP KG Schema changes.ipynb index 0cd0c4ae..e66bb69c 100644 --- a/examples/notebooks/use-cases/BBP KG Schema changes.ipynb +++ b/examples/notebooks/use-cases/BBP KG Schema changes.ipynb @@ -2,7 +2,7 @@ "cells": [ { "cell_type": "code", - "execution_count": 1, + "execution_count": 10, "id": "b14744df-3567-40f3-bb0c-06c6767ab695", "metadata": {}, "outputs": [], @@ -16,7 +16,7 @@ }, { "cell_type": "code", - "execution_count": 2, + "execution_count": 11, "id": "72596414-c9ac-4312-a621-5bd4fdc3477b", "metadata": {}, "outputs": [ @@ -35,7 +35,7 @@ }, { "cell_type": "code", - "execution_count": 3, + "execution_count": 12, "id": "c124caae-b9ae-4eb4-8d8e-bc437d28d3e6", "metadata": {}, "outputs": [], @@ -48,9 +48,17 @@ ")" ] }, + { + "cell_type": "markdown", + "id": "a185f986-e008-4f0a-9447-df10e4c30bb9", + "metadata": {}, + "source": [ + "# Retrieve 10 unconstrained entities" + ] + }, { "cell_type": "code", - "execution_count": 4, + "execution_count": 13, "id": "29bceff6-d7b4-4fda-9cc3-fe1923c0f865", "metadata": {}, "outputs": [], @@ -63,7 +71,7 @@ }, { "cell_type": "code", - "execution_count": 5, + "execution_count": 14, "id": "72c07da6-1f6b-4251-b552-9d5f12fa40a9", "metadata": {}, "outputs": [ @@ -73,7 +81,7 @@ "10" ] }, - "execution_count": 5, + "execution_count": 14, "metadata": {}, "output_type": "execute_result" } @@ -84,7 +92,7 @@ }, { "cell_type": "code", - "execution_count": 6, + "execution_count": 15, "id": "f3f2512d-4a1c-4c56-8cce-ea53a991d76d", "metadata": {}, "outputs": [], @@ -94,7 +102,7 @@ }, { "cell_type": "code", - "execution_count": 7, + "execution_count": 16, "id": "fc675bd3-2e7c-4de1-b3dc-041215a1a0c3", "metadata": {}, "outputs": [ @@ -113,7 +121,7 @@ " 'https://bluebrain.github.io/nexus/schemas/unconstrained.json']" ] }, - "execution_count": 7, + "execution_count": 16, "metadata": {}, "output_type": "execute_result" } @@ -122,9 +130,25 @@ "cs(resources)" ] }, + { + "cell_type": "markdown", + "id": "e79f1807-dbfa-4cca-ab08-4809c9962517", + "metadata": {}, + "source": [ + "## 1.a. Constraint using _store.update_schema" + ] + }, + { + "cell_type": "markdown", + "id": "cc361f70-c8c9-4ab8-8ed5-932c3a1bf717", + "metadata": {}, + "source": [ + "### Multiple" + ] + }, { "cell_type": "code", - "execution_count": 8, + "execution_count": 17, "id": "5ed305ef-16d2-42eb-8818-ec68674afceb", "metadata": {}, "outputs": [ @@ -144,7 +168,7 @@ }, { "cell_type": "code", - "execution_count": 9, + "execution_count": 18, "id": "bf330be7-b5be-4ea5-9249-d2926f5481b3", "metadata": {}, "outputs": [ @@ -163,7 +187,7 @@ " 'https://neuroshapes.org/dash/entity']" ] }, - "execution_count": 9, + "execution_count": 18, "metadata": {}, "output_type": "execute_result" } @@ -172,9 +196,54 @@ "cs(resources)" ] }, + { + "cell_type": "markdown", + "id": "aad27794-ddbe-4e58-8c5f-76a799b1e15c", + "metadata": {}, + "source": [ + "### One" + ] + }, { "cell_type": "code", - "execution_count": 10, + "execution_count": 19, + "id": "fcb99113-3a3e-4e8f-b98e-d127d04e4e6a", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + " _update_schema_one\n", + " True\n" + ] + } + ], + "source": [ + "e = forge._store.update_schema(resources[0], schema_id='https://bluebrain.github.io/nexus/schemas/unconstrained.json')" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "da104ef9-63cf-49d2-b296-6506b6bbf4de", + "metadata": {}, + "outputs": [], + "source": [ + "cs(resources)" + ] + }, + { + "cell_type": "markdown", + "id": "d10b21d5-212b-48cc-b4a2-7ef2f739b2ed", + "metadata": {}, + "source": [ + "## 1.b Delete schemas using _store.delete_schema (equivalent to constraining by unconstrained.json)" + ] + }, + { + "cell_type": "code", + "execution_count": 20, "id": "410896b1-2997-4cdb-9af5-fdb4a95fb7de", "metadata": {}, "outputs": [ @@ -194,7 +263,7 @@ }, { "cell_type": "code", - "execution_count": 11, + "execution_count": 21, "id": "030a7cc6-e272-43b7-9401-c288684dbfb8", "metadata": {}, "outputs": [ @@ -213,7 +282,7 @@ " 'https://bluebrain.github.io/nexus/schemas/unconstrained.json']" ] }, - "execution_count": 11, + "execution_count": 21, "metadata": {}, "output_type": "execute_result" } @@ -222,12 +291,38 @@ "cs(resources)" ] }, + { + "cell_type": "markdown", + "id": "551f3fdc-4760-4c6b-861b-6ac085f27e00", + "metadata": {}, + "source": [ + "## 2.a Constraint using the update method" + ] + }, + { + "cell_type": "markdown", + "id": "0a5b0ebd-3037-4302-a774-33c4cd6a1767", + "metadata": {}, + "source": [ + "### Multiple" + ] + }, { "cell_type": "code", - "execution_count": null, + "execution_count": 22, "id": "c0c14efd-cc49-489c-81ca-d5614b25ca34", "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + " 10\n", + " _update_many\n", + " True\n" + ] + } + ], "source": [ "for r in resources:\n", " r._synchronized = False\n", @@ -237,20 +332,58 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 23, "id": "e97e4261-2dcd-4a88-a189-a137ee7c207d", "metadata": {}, - "outputs": [], + "outputs": [ + { + "data": { + "text/plain": [ + "['https://neuroshapes.org/dash/entity',\n", + " 'https://neuroshapes.org/dash/entity',\n", + " 'https://neuroshapes.org/dash/entity',\n", + " 'https://neuroshapes.org/dash/entity',\n", + " 'https://neuroshapes.org/dash/entity',\n", + " 'https://neuroshapes.org/dash/entity',\n", + " 'https://neuroshapes.org/dash/entity',\n", + " 'https://neuroshapes.org/dash/entity',\n", + " 'https://neuroshapes.org/dash/entity',\n", + " 'https://neuroshapes.org/dash/entity']" + ] + }, + "execution_count": 23, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ "cs(resources)" ] }, + { + "cell_type": "markdown", + "id": "7e3b7dc4-e39f-4003-b974-1c877ad6a47c", + "metadata": {}, + "source": [ + "## 2.b Delete schemas using update method" + ] + }, { "cell_type": "code", - "execution_count": null, + "execution_count": 24, "id": "211eeb24-4c6f-469c-85fc-04faa4bc77fc", "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + " 10\n", + " _update_many\n", + " True\n" + ] + } + ], "source": [ "for r in resources:\n", " r._synchronized = False\n", @@ -260,10 +393,138 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 25, "id": "7ce6cb5a-e6fc-4a6f-a707-3c1781354d3d", "metadata": {}, - "outputs": [], + "outputs": [ + { + "data": { + "text/plain": [ + "['https://bluebrain.github.io/nexus/schemas/unconstrained.json',\n", + " 'https://bluebrain.github.io/nexus/schemas/unconstrained.json',\n", + " 'https://bluebrain.github.io/nexus/schemas/unconstrained.json',\n", + " 'https://bluebrain.github.io/nexus/schemas/unconstrained.json',\n", + " 'https://bluebrain.github.io/nexus/schemas/unconstrained.json',\n", + " 'https://bluebrain.github.io/nexus/schemas/unconstrained.json',\n", + " 'https://bluebrain.github.io/nexus/schemas/unconstrained.json',\n", + " 'https://bluebrain.github.io/nexus/schemas/unconstrained.json',\n", + " 'https://bluebrain.github.io/nexus/schemas/unconstrained.json',\n", + " 'https://bluebrain.github.io/nexus/schemas/unconstrained.json']" + ] + }, + "execution_count": 25, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "cs(resources)" + ] + }, + { + "cell_type": "markdown", + "id": "796e572d-4577-44ab-8862-6145cb000124", + "metadata": {}, + "source": [ + "### One" + ] + }, + { + "cell_type": "code", + "execution_count": 26, + "id": "90ffe938-dcdd-4b85-92eb-65362855cf94", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + " _update_one\n", + " True\n" + ] + } + ], + "source": [ + "resources[0]._synchronized = False\n", + "forge.update(resources[0], schema_id=\"https://neuroshapes.org/dash/entity\")" + ] + }, + { + "cell_type": "code", + "execution_count": 27, + "id": "93259b3c-9f84-4b01-bc5b-dafd7bc7c94d", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "['https://neuroshapes.org/dash/entity',\n", + " 'https://bluebrain.github.io/nexus/schemas/unconstrained.json',\n", + " 'https://bluebrain.github.io/nexus/schemas/unconstrained.json',\n", + " 'https://bluebrain.github.io/nexus/schemas/unconstrained.json',\n", + " 'https://bluebrain.github.io/nexus/schemas/unconstrained.json',\n", + " 'https://bluebrain.github.io/nexus/schemas/unconstrained.json',\n", + " 'https://bluebrain.github.io/nexus/schemas/unconstrained.json',\n", + " 'https://bluebrain.github.io/nexus/schemas/unconstrained.json',\n", + " 'https://bluebrain.github.io/nexus/schemas/unconstrained.json',\n", + " 'https://bluebrain.github.io/nexus/schemas/unconstrained.json']" + ] + }, + "execution_count": 27, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "cs(resources)" + ] + }, + { + "cell_type": "code", + "execution_count": 28, + "id": "b55e6972-714c-4468-9195-544ec3af0213", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + " _update_one\n", + " True\n" + ] + } + ], + "source": [ + "resources[0]._synchronized = False\n", + "forge.update(resources[0], schema_id=\"https://bluebrain.github.io/nexus/schemas/unconstrained.json\")" + ] + }, + { + "cell_type": "code", + "execution_count": 29, + "id": "2c0bb710-e39d-480c-be19-f48c9aaff3cc", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "['https://bluebrain.github.io/nexus/schemas/unconstrained.json',\n", + " 'https://bluebrain.github.io/nexus/schemas/unconstrained.json',\n", + " 'https://bluebrain.github.io/nexus/schemas/unconstrained.json',\n", + " 'https://bluebrain.github.io/nexus/schemas/unconstrained.json',\n", + " 'https://bluebrain.github.io/nexus/schemas/unconstrained.json',\n", + " 'https://bluebrain.github.io/nexus/schemas/unconstrained.json',\n", + " 'https://bluebrain.github.io/nexus/schemas/unconstrained.json',\n", + " 'https://bluebrain.github.io/nexus/schemas/unconstrained.json',\n", + " 'https://bluebrain.github.io/nexus/schemas/unconstrained.json',\n", + " 'https://bluebrain.github.io/nexus/schemas/unconstrained.json']" + ] + }, + "execution_count": 29, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ "cs(resources)" ]