From d2b4c5f44c44eea6cac60195715fcdf0b46a7813 Mon Sep 17 00:00:00 2001 From: Arjun Gopalakrishnan Date: Thu, 24 Oct 2024 12:05:31 +0200 Subject: [PATCH] Updated README and removed duplicate files --- README.md | 14 +- examples/basic_usage.ipynb | 1588 ----------------------- examples/tutorials/1_introduction.ipynb | 216 --- examples/tutorials/2_creation.ipynb | 386 ------ examples/tutorials/3_updation.ipynb | 287 ---- examples/tutorials/4_deletion.ipynb | 404 ------ examples/tutorials/5_search.ipynb | 1323 ------------------- examples/tutorials/6_apps.ipynb | 1031 --------------- examples/tutorials/7_ktypes.ipynb | 423 ------ examples/tutorials/testfile.txt | 1 - 10 files changed, 7 insertions(+), 5666 deletions(-) delete mode 100644 examples/basic_usage.ipynb delete mode 100644 examples/tutorials/1_introduction.ipynb delete mode 100644 examples/tutorials/2_creation.ipynb delete mode 100644 examples/tutorials/3_updation.ipynb delete mode 100644 examples/tutorials/4_deletion.ipynb delete mode 100644 examples/tutorials/5_search.ipynb delete mode 100644 examples/tutorials/6_apps.ipynb delete mode 100644 examples/tutorials/7_ktypes.ipynb delete mode 100644 examples/tutorials/testfile.txt diff --git a/README.md b/README.md index 4be7a96..a96e6cc 100644 --- a/README.md +++ b/README.md @@ -48,13 +48,13 @@ Please have a look at our tutorials on _readthedocs_: * [6. Apps](https://dsms-python-sdk.readthedocs.io/en/latest/dsms_sdk/tutorials/6_apps.html) Or try our Jupyter Notebooks: -* [1. Introduction](docs\dsms_sdk\tutorials\1_introduction.ipynb) -* [2. Creation](docs\dsms_sdk\tutorials\2_creation.ipynb) -* [3. Updation](docs\dsms_sdk\tutorials\3_updation.ipynb) -* [4. Deletion](docs\dsms_sdk\tutorials\4_deletion.ipynb) -* [5. Search](docs\dsms_sdk\tutorials\5_search.ipynb) -* [6. Apps](docs\dsms_sdk\tutorials\6_apps.ipynb) -* [7. KTypes](docs\dsms_sdk\tutorials\7_ktypes.ipynb) +* [1. Introduction](docs/dsms_sdk/tutorials/1_introduction.ipynb) +* [2. Creation](docs/dsms_sdk/tutorials/2_creation.ipynb) +* [3. Updation](docs/dsms_sdk/tutorials/3_updation.ipynb) +* [4. Deletion](docs/dsms_sdk/tutorials/4_deletion.ipynb) +* [5. Search](docs/dsms_sdk/tutorials/5_search.ipynb) +* [6. Apps](docs/dsms_sdk/tutorials/6_apps.ipynb) +* [7. KTypes](docs/dsms_sdk/tutorials/7_ktypes.ipynb) ## Authors diff --git a/examples/basic_usage.ipynb b/examples/basic_usage.ipynb deleted file mode 100644 index d66b53c..0000000 --- a/examples/basic_usage.ipynb +++ /dev/null @@ -1,1588 +0,0 @@ -{ - "cells": [ - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "# Basic useage of the DSMS-Python-SDK\n", - "\n", - "Before you run this tutorial: make sure to have access to an DSMS-instance of your interest, that you have installed this package and that you have copied the needed variables such as the `DSMS_HOST_URL` and `DSMS_TOKEN` into an `.env`-file." - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "First of all, make let us import the needed classes and functions for this tutortial." - ] - }, - { - "cell_type": "code", - "execution_count": 1, - "metadata": {}, - "outputs": [], - "source": [ - "from dsms import DSMS, KItem" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "Now source the environmental variables from an `.env` file and start the DSMS-session." - ] - }, - { - "cell_type": "code", - "execution_count": 2, - "metadata": {}, - "outputs": [], - "source": [ - "dsms = DSMS(env=\"../.env\")" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "### 1: Introduction" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "We can see which kind of DSMS-object we own as a user:" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "We can investigate what a KItem needs in order to be created. KItems are entirely based on [`Pydantic`](https://docs.pydantic.dev/latest/)-Models (v2), hence the properties (in `Pydantic` called `Fields`) are automatically validated once we set them. \n", - "\n", - "The schema of the KItem itself is a JSON schema which is machine-readable and can be directly incorporated into [Swagger](https://swagger.io/tools/swagger-ui/)-supported APIs like e.g. [`FastAPI`](https://fastapi.tiangolo.com/)." - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "We can investigate the KTypes defined in the remote instance:" - ] - }, - { - "cell_type": "code", - "execution_count": 3, - "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "KTypes.Organization\n", - "KTypes.App\n", - "KTypes.Dataset\n", - "KTypes.DatasetCatalog\n", - "KTypes.Expert\n", - "KTypes.Test\n", - "KTypes.Specimen\n", - "KTypes.Batch\n", - "KTypes.Resource\n", - "KTypes.TestingMachine\n" - ] - } - ], - "source": [ - "for ktype in dsms.ktypes:\n", - " print(ktype)" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "### 2: Create KItems" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "We can make new KItems by simple class-initiation:" - ] - }, - { - "cell_type": "code", - "execution_count": 4, - "metadata": {}, - "outputs": [ - { - "data": { - "text/plain": [ - "KItem(\n", - "\n", - "\tname = foo123, \n", - "\n", - "\tid = 617cd64f-1a4d-48d5-aed6-ff9d9e3ddb20, \n", - "\n", - "\tktype_id = KTypes.Dataset, \n", - "\n", - "\tin_backend = False, \n", - "\n", - "\tslug = foo123-617cd64f, \n", - "\n", - "\tannotations = [], \n", - "\n", - "\tattachments = [], \n", - "\n", - "\tlinked_kitems = [], \n", - "\n", - "\taffiliations = [], \n", - "\n", - "\tauthors = [], \n", - "\n", - "\tavatar_exists = False, \n", - "\n", - "\tcontacts = [], \n", - "\n", - "\tcreated_at = None, \n", - "\n", - "\tupdated_at = None, \n", - "\n", - "\texternal_links = [], \n", - "\n", - "\tkitem_apps = [], \n", - "\n", - "\tsummary = None, \n", - "\n", - "\tuser_groups = [], \n", - "\n", - "\tcustom_properties = {\n", - "\t\tfoo: bar\n", - "\t}, \n", - "\n", - "\tdataframe = None, \n", - "\n", - "\trdf_exists = False\n", - ")" - ] - }, - "execution_count": 4, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "item = KItem(\n", - " name=\"foo123\",\n", - " ktype_id=dsms.ktypes.Dataset,\n", - " custom_properties={\"foo\": \"bar\"},\n", - ")\n", - "\n", - "item" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "Remember: changes are only syncronized with the DSMS when you call the `commit`-method:" - ] - }, - { - "cell_type": "code", - "execution_count": 5, - "metadata": {}, - "outputs": [ - { - "data": { - "text/plain": [ - "'https://bue.materials-data.space/knowledge/dataset/foo123-617cd64f'" - ] - }, - "execution_count": 5, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "dsms.commit()\n", - "item.url" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "As we can see, the object we created before running the `commit`-method has automatically been updated, e.g. with the creation- and update-timestamp:" - ] - }, - { - "cell_type": "code", - "execution_count": 6, - "metadata": {}, - "outputs": [ - { - "data": { - "text/plain": [ - "KItem(\n", - "\n", - "\tname = foo123, \n", - "\n", - "\tid = 617cd64f-1a4d-48d5-aed6-ff9d9e3ddb20, \n", - "\n", - "\tktype_id = dataset, \n", - "\n", - "\tin_backend = True, \n", - "\n", - "\tslug = foo123-617cd64f, \n", - "\n", - "\tannotations = [], \n", - "\n", - "\tattachments = [], \n", - "\n", - "\tlinked_kitems = [], \n", - "\n", - "\taffiliations = [], \n", - "\n", - "\tauthors = [\n", - "\t\t{\n", - "\t\t\tuser_id: 7f0e5a37-353b-4bbc-b1f1-b6ad575f562d\n", - "\t\t}\n", - "\t], \n", - "\n", - "\tavatar_exists = False, \n", - "\n", - "\tcontacts = [], \n", - "\n", - "\tcreated_at = 2024-08-20 08:01:50.536406, \n", - "\n", - "\tupdated_at = 2024-08-20 08:01:50.536406, \n", - "\n", - "\texternal_links = [], \n", - "\n", - "\tkitem_apps = [], \n", - "\n", - "\tsummary = None, \n", - "\n", - "\tuser_groups = [], \n", - "\n", - "\tcustom_properties = {\n", - "\t\tfoo: bar\n", - "\t}, \n", - "\n", - "\tdataframe = None, \n", - "\n", - "\trdf_exists = False\n", - ")" - ] - }, - "execution_count": 6, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "item" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "### 3. Update KItems" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "Now, we would like to update the properties of our KItem we created previously.\n", - "\n", - "Depending on the schema of each property (see `KItem.model_schema_json()` in the **Introduction** of this tutorial), we can simply use the standard `list`-method as we know them from basic Python (e.g. for the `annotations`, `attachments`, `external_link`, etc). \n", - "\n", - "\n", - "Other properties which are not `list`-like can be simply set by attribute-assignment (e.g. `name`, `slug`, `ktype_id`, etc)." - ] - }, - { - "cell_type": "code", - "execution_count": 7, - "metadata": {}, - "outputs": [], - "source": [ - "item.name = \"foobar\"\n", - "item.custom_properties.foobar = \"foobar\"\n", - "item.attachments.append(\"../README.md\")\n", - "item.annotations.append(\"www.example.org/foo\")\n", - "item.external_links.append(\n", - " {\"url\": \"http://example.org\", \"label\": \"example link\"}\n", - ")\n", - "item.contacts.append({\"name\": \"foo\", \"email\": \"foo@bar.mail\"})\n", - "item.affiliations.append(\"foobar team\")\n", - "item.user_groups.append({\"name\": \"foogroup\", \"group_id\": \"123\"})" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "Changes are sent to the DSMS through the `commit`-method again." - ] - }, - { - "cell_type": "code", - "execution_count": 8, - "metadata": {}, - "outputs": [], - "source": [ - "dsms.commit()" - ] - }, - { - "cell_type": "code", - "execution_count": 9, - "metadata": {}, - "outputs": [ - { - "data": { - "text/plain": [ - "KItem(\n", - "\n", - "\tname = foobar, \n", - "\n", - "\tid = 617cd64f-1a4d-48d5-aed6-ff9d9e3ddb20, \n", - "\n", - "\tktype_id = dataset, \n", - "\n", - "\tin_backend = True, \n", - "\n", - "\tslug = foo123-617cd64f, \n", - "\n", - "\tannotations = [\n", - "\t\t{\n", - "\t\t\tiri: www.example.org/foo,\n", - "\t\t\tname: foo,\n", - "\t\t\tnamespace: www.example.org,\n", - "\t\t\tdescription: None\n", - "\t\t}\n", - "\t], \n", - "\n", - "\tattachments = [\n", - "\t\t{\n", - "\t\t\tname: README.md\n", - "\t\t}\n", - "\t], \n", - "\n", - "\tlinked_kitems = [], \n", - "\n", - "\taffiliations = [\n", - "\t\t{\n", - "\t\t\tname: foobar team\n", - "\t\t}\n", - "\t], \n", - "\n", - "\tauthors = [\n", - "\t\t{\n", - "\t\t\tuser_id: 7f0e5a37-353b-4bbc-b1f1-b6ad575f562d\n", - "\t\t}\n", - "\t], \n", - "\n", - "\tavatar_exists = False, \n", - "\n", - "\tcontacts = [\n", - "\t\t{\n", - "\t\t\tname: foo,\n", - "\t\t\temail: foo@bar.mail,\n", - "\t\t\tuser_id: None\n", - "\t\t}\n", - "\t], \n", - "\n", - "\tcreated_at = 2024-08-20 08:01:50.536406, \n", - "\n", - "\tupdated_at = 2024-08-20 08:01:54.745601, \n", - "\n", - "\texternal_links = [\n", - "\t\t{\n", - "\t\t\tlabel: example link,\n", - "\t\t\turl: http://example.org/\n", - "\t\t}\n", - "\t], \n", - "\n", - "\tkitem_apps = [], \n", - "\n", - "\tsummary = None, \n", - "\n", - "\tuser_groups = [\n", - "\t\t{\n", - "\t\t\tname: foogroup,\n", - "\t\t\tgroup_id: 123\n", - "\t\t}\n", - "\t], \n", - "\n", - "\tcustom_properties = {\n", - "\t\tfoo: bar\n", - "\t}, \n", - "\n", - "\tdataframe = None, \n", - "\n", - "\trdf_exists = False\n", - ")" - ] - }, - "execution_count": 9, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "item" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "We can see now that e.g. the local system path of the attachment is changed to a simply file name, which means that the upload was successful. If not so, an error would have beem thrown during the `commit`." - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "Furthermore we can also download the file we uploaded again:" - ] - }, - { - "cell_type": "code", - "execution_count": 10, - "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "\t\t\t Downloaded file: {\n", - "\t\t\tname: README.md\n", - "\t\t}\n", - "|------------------------------------Beginning of file------------------------------------|\n", - "# DSMS-SDK\n", - "Python SDK core-package for interacting with the Dataspace Management System (DSMS)\n", - "\n", - "\n", - "## Authors\n", - "\n", - "[Matthias Büschelberger](mailto:matthias.bueschelberger@iwm.fraunhofer.de) (Fraunhofer Institute for Mechanics of Materials IWM)\n", - "\n", - "[Yoav Nahshon](mailto:yoav.nahshon@iwm.fraunhofer.de) (Fraunhofer Institute for Mechanics of Materials IWM)\n", - "\n", - "[Pablo De Andres](mailto:pablo.de.andres@iwm.fraunhofer.de) (Fraunhofer Institute for Mechanics of Materials IWM)\n", - "\n", - "## License\n", - "\n", - "This project is licensed under the BSD 3-Clause. See the LICENSE file for more information.\n", - "\n", - "## Usage\n", - "\n", - "The SDK provides a general Python interface to a remote DSMS deployment, allowing users to access, store and link data in a DSMS instance easily and safely. The package provides the following main capabilities:\n", - "\n", - "- Managing Knowledge-Items (KItems), which are data instances of an explicitly defined semantic class type (KType)\n", - " - Creating, updating and deleting meta data and properties, e.g. date, operator, material response data for a conducted tensile test\n", - " - Administrating authorship, contact information and supplementary information upon making changes or adding KItems\n", - " - Semantic annotation of KItems\n", - "- Conduct simple free-text searches within the DSMS instance including filters (e.g. limiting the search for certain materials) as well as a more experts-aware SPARQL interface\n", - "- Linking KItems to other KItems\n", - "- Linking Apps to KItems, triggererd, for example, during a file upload\n", - "- Performing simple file upload and download using attachments to KItems\n", - "- Export of a knowledge (sub) graph as common serializations (.ttl, .json)\n", - "\n", - "For the basic usage, please have a look on the Jupyter Notebook under `examples/basic_usage.ipynb`. This tutorial provides a basic overview of using the dsms package to interact with Knowledge Items.\n", - "\n", - "## Disclaimer\n", - "\n", - "Copyright (c) 2014-2024, Fraunhofer-Gesellschaft zur Förderung der angewandten Forschung e.V. acting on behalf of its Fraunhofer IWM.\n", - "\n", - "Contact: [Matthias Büschelberger](mailto:matthias.bueschelberger@iwm.fraunhofer.de)\n", - "\n", - "|---------------------------------------End of file---------------------------------------|\n" - ] - } - ], - "source": [ - "for file in item.attachments:\n", - " download = file.download()\n", - "\n", - " print(\"\\t\\t\\t Downloaded file:\", file)\n", - " print(\"|------------------------------------Beginning of file------------------------------------|\")\n", - " print(download)\n", - " print(\"|---------------------------------------End of file---------------------------------------|\")" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "### 4: Delete KItems and their properties" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "We can also remove properties from the KItem without deleting the KItem itself.\n", - "\n", - "For the `list`-like properties, we can use the standard `list`-methods from basic Python again (e.g. `pop`, `remove`, etc. or the `del`-operator).\n", - "\n", - "For the other, non-`list`-like properties, we can simply use the attribute-assignment again.\n", - "\n", - "When we only want single parts of the properties in the KItem, we can do it like this:" - ] - }, - { - "cell_type": "code", - "execution_count": 11, - "metadata": {}, - "outputs": [ - { - "data": { - "text/plain": [ - "{\n", - "\t\t\tiri: www.example.org/foo,\n", - "\t\t\tname: foo,\n", - "\t\t\tnamespace: www.example.org,\n", - "\t\t\tdescription: None\n", - "\t\t}" - ] - }, - "execution_count": 11, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "item.attachments.pop(0)\n", - "item.annotations.pop(0)" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "However, we can also reset the entire property by setting it to e.g. an empty list again:" - ] - }, - { - "cell_type": "code", - "execution_count": 12, - "metadata": {}, - "outputs": [], - "source": [ - "item.user_groups = []" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "See the changes:" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "Send the changes to the DSMS with the `commit`-method:" - ] - }, - { - "cell_type": "code", - "execution_count": 13, - "metadata": {}, - "outputs": [], - "source": [ - "dsms.commit()" - ] - }, - { - "cell_type": "code", - "execution_count": 14, - "metadata": {}, - "outputs": [ - { - "data": { - "text/plain": [ - "KItem(\n", - "\n", - "\tname = foobar, \n", - "\n", - "\tid = 617cd64f-1a4d-48d5-aed6-ff9d9e3ddb20, \n", - "\n", - "\tktype_id = dataset, \n", - "\n", - "\tin_backend = True, \n", - "\n", - "\tslug = foo123-617cd64f, \n", - "\n", - "\tannotations = [], \n", - "\n", - "\tattachments = [], \n", - "\n", - "\tlinked_kitems = [], \n", - "\n", - "\taffiliations = [\n", - "\t\t{\n", - "\t\t\tname: foobar team\n", - "\t\t}\n", - "\t], \n", - "\n", - "\tauthors = [\n", - "\t\t{\n", - "\t\t\tuser_id: 7f0e5a37-353b-4bbc-b1f1-b6ad575f562d\n", - "\t\t}\n", - "\t], \n", - "\n", - "\tavatar_exists = False, \n", - "\n", - "\tcontacts = [\n", - "\t\t{\n", - "\t\t\tname: foo,\n", - "\t\t\temail: foo@bar.mail,\n", - "\t\t\tuser_id: None\n", - "\t\t}\n", - "\t], \n", - "\n", - "\tcreated_at = 2024-08-20 08:01:50.536406, \n", - "\n", - "\tupdated_at = 2024-08-20 08:01:54.745601, \n", - "\n", - "\texternal_links = [\n", - "\t\t{\n", - "\t\t\tlabel: example link,\n", - "\t\t\turl: http://example.org/\n", - "\t\t}\n", - "\t], \n", - "\n", - "\tkitem_apps = [], \n", - "\n", - "\tsummary = None, \n", - "\n", - "\tuser_groups = [], \n", - "\n", - "\tcustom_properties = {\n", - "\t\tfoo: bar\n", - "\t}, \n", - "\n", - "\tdataframe = None, \n", - "\n", - "\trdf_exists = False\n", - ")" - ] - }, - "execution_count": 14, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "item" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "However, we can also delete the whole KItem from the DSMS by applying the `del`-operator to the `dsms`-object with the individual `KItem`-object:" - ] - }, - { - "cell_type": "code", - "execution_count": 15, - "metadata": {}, - "outputs": [], - "source": [ - "del dsms[item]" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "Commit the changes:" - ] - }, - { - "cell_type": "code", - "execution_count": 16, - "metadata": {}, - "outputs": [], - "source": [ - "dsms.commit()" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "### 5: Search for KItems" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "In the last unit of this tutorial, we would like to search for specfic KItems we created in the DSMS.\n", - "\n", - "For this purpose, we will firstly create some KItems and apply the `search`-method on the `DSMS`-object later on in order to find them again in the DSMS.\n", - "\n", - "We also wnat to demonstrate here, that we can link KItems to each other in order to find e.g. a related item of type `DatasetCatalog`. For this strategy, we are using the `linked_kitems`-attribute and the `id` of the item which we would like to link.\n", - "\n", - "The procedure looks like this:" - ] - }, - { - "cell_type": "code", - "execution_count": 17, - "metadata": {}, - "outputs": [], - "source": [ - "item = KItem(\n", - " name=\"foo 1\",\n", - " ktype_id=dsms.ktypes.DatasetCatalog\n", - ")\n", - "\n", - "item2 = KItem(\n", - " name=\"foo 2\",\n", - " ktype_id=dsms.ktypes.Organization,\n", - " linked_kitems=[item],\n", - " annotations=[\"www.example.org/foo\"]\n", - ")\n", - "item3 = KItem(\n", - " name=\"foo 3\", \n", - " ktype_id=dsms.ktypes.Organization\n", - ")\n", - "item4 = KItem(\n", - " name=\"foo 4\",\n", - " ktype_id=dsms.ktypes.Organization,\n", - " annotations=[\"www.example.org/bar\"],\n", - ")\n", - "\n", - "dsms.commit()" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "Now, we are apply to search for e.g. kitems of type `DatasetCatalog`:" - ] - }, - { - "cell_type": "code", - "execution_count": 18, - "metadata": {}, - "outputs": [ - { - "data": { - "text/plain": [ - "[SearchResult(hit=KItem(\n", - " \n", - " \tname = foo 1, \n", - " \n", - " \tid = 966beb55-6eb5-422e-b8c1-84d65b8cf50d, \n", - " \n", - " \tktype_id = dataset-catalog, \n", - " \n", - " \tin_backend = True, \n", - " \n", - " \tslug = foo1-966beb55, \n", - " \n", - " \tannotations = [], \n", - " \n", - " \tattachments = [], \n", - " \n", - " \tlinked_kitems = [\n", - " \t\t\n", - " \t\t\tid: 3ca3c293-8845-4f0e-afcb-6c680c07239f\n", - " \t\t\tname: foo 2\n", - " \t\t\tslug: foo2-3ca3c293\n", - " \t\t\tktype_id: organization\n", - " \t\t\tsummary: None\n", - " \t\t\tavatar_exists: False\n", - " \t\t\tannotations: [{\n", - " \t\t\tiri: www.example.org/foo,\n", - " \t\t\tname: foo,\n", - " \t\t\tnamespace: www.example.org,\n", - " \t\t\tdescription: None\n", - " \t\t}]\n", - " \t\t\tlinked_kitems: [{\n", - " \t\t\tid: 966beb55-6eb5-422e-b8c1-84d65b8cf50d\n", - " \t\t}]\n", - " \t\t\texternal_links: []\n", - " \t\t\tcontacts: []\n", - " \t\t\tauthors: [{\n", - " \t\t\tuser_id: 7f0e5a37-353b-4bbc-b1f1-b6ad575f562d\n", - " \t\t}]\n", - " \t\t\tlinked_affiliations: []\n", - " \t\t\tattachments: []\n", - " \t\t\tuser_groups: []\n", - " \t\t\tcustom_properties: None\n", - " \t\t\tcreated_at: 2024-08-20T08:02:09.024038\n", - " \t\t\tupdated_at: 2024-08-20T08:02:09.024038\n", - " \t\t\n", - " \t], \n", - " \n", - " \taffiliations = [], \n", - " \n", - " \tauthors = [\n", - " \t\t{\n", - " \t\t\tuser_id: 7f0e5a37-353b-4bbc-b1f1-b6ad575f562d\n", - " \t\t}\n", - " \t], \n", - " \n", - " \tavatar_exists = False, \n", - " \n", - " \tcontacts = [], \n", - " \n", - " \tcreated_at = 2024-08-20 08:02:08.491699, \n", - " \n", - " \tupdated_at = 2024-08-20 08:02:08.491699, \n", - " \n", - " \texternal_links = [], \n", - " \n", - " \tkitem_apps = [], \n", - " \n", - " \tsummary = None, \n", - " \n", - " \tuser_groups = [], \n", - " \n", - " \tcustom_properties = None, \n", - " \n", - " \tdataframe = None, \n", - " \n", - " \trdf_exists = False\n", - " ), fuzzy=False)]" - ] - }, - "execution_count": 18, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "dsms.search(ktypes=[dsms.ktypes.DatasetCatalog])" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "... and for all of type `Organization` and `DatasetCatalog`:" - ] - }, - { - "cell_type": "code", - "execution_count": 19, - "metadata": {}, - "outputs": [ - { - "data": { - "text/plain": [ - "[SearchResult(hit=KItem(\n", - " \n", - " \tname = foo 1, \n", - " \n", - " \tid = 966beb55-6eb5-422e-b8c1-84d65b8cf50d, \n", - " \n", - " \tktype_id = dataset-catalog, \n", - " \n", - " \tin_backend = True, \n", - " \n", - " \tslug = foo1-966beb55, \n", - " \n", - " \tannotations = [], \n", - " \n", - " \tattachments = [], \n", - " \n", - " \tlinked_kitems = [\n", - " \t\t\n", - " \t\t\tid: 3ca3c293-8845-4f0e-afcb-6c680c07239f\n", - " \t\t\tname: foo 2\n", - " \t\t\tslug: foo2-3ca3c293\n", - " \t\t\tktype_id: organization\n", - " \t\t\tsummary: None\n", - " \t\t\tavatar_exists: False\n", - " \t\t\tannotations: [{\n", - " \t\t\tiri: www.example.org/foo,\n", - " \t\t\tname: foo,\n", - " \t\t\tnamespace: www.example.org,\n", - " \t\t\tdescription: None\n", - " \t\t}]\n", - " \t\t\tlinked_kitems: [{\n", - " \t\t\tid: 966beb55-6eb5-422e-b8c1-84d65b8cf50d\n", - " \t\t}]\n", - " \t\t\texternal_links: []\n", - " \t\t\tcontacts: []\n", - " \t\t\tauthors: [{\n", - " \t\t\tuser_id: 7f0e5a37-353b-4bbc-b1f1-b6ad575f562d\n", - " \t\t}]\n", - " \t\t\tlinked_affiliations: []\n", - " \t\t\tattachments: []\n", - " \t\t\tuser_groups: []\n", - " \t\t\tcustom_properties: None\n", - " \t\t\tcreated_at: 2024-08-20T08:02:09.024038\n", - " \t\t\tupdated_at: 2024-08-20T08:02:09.024038\n", - " \t\t\n", - " \t], \n", - " \n", - " \taffiliations = [], \n", - " \n", - " \tauthors = [\n", - " \t\t{\n", - " \t\t\tuser_id: 7f0e5a37-353b-4bbc-b1f1-b6ad575f562d\n", - " \t\t}\n", - " \t], \n", - " \n", - " \tavatar_exists = False, \n", - " \n", - " \tcontacts = [], \n", - " \n", - " \tcreated_at = 2024-08-20 08:02:08.491699, \n", - " \n", - " \tupdated_at = 2024-08-20 08:02:08.491699, \n", - " \n", - " \texternal_links = [], \n", - " \n", - " \tkitem_apps = [], \n", - " \n", - " \tsummary = None, \n", - " \n", - " \tuser_groups = [], \n", - " \n", - " \tcustom_properties = None, \n", - " \n", - " \tdataframe = None, \n", - " \n", - " \trdf_exists = False\n", - " ), fuzzy=False),\n", - " SearchResult(hit=KItem(\n", - " \n", - " \tname = foo 2, \n", - " \n", - " \tid = 3ca3c293-8845-4f0e-afcb-6c680c07239f, \n", - " \n", - " \tktype_id = organization, \n", - " \n", - " \tin_backend = True, \n", - " \n", - " \tslug = foo2-3ca3c293, \n", - " \n", - " \tannotations = [\n", - " \t\t{\n", - " \t\t\tiri: www.example.org/foo,\n", - " \t\t\tname: foo,\n", - " \t\t\tnamespace: www.example.org,\n", - " \t\t\tdescription: None\n", - " \t\t}\n", - " \t], \n", - " \n", - " \tattachments = [], \n", - " \n", - " \tlinked_kitems = [\n", - " \t\t\n", - " \t\t\tid: 966beb55-6eb5-422e-b8c1-84d65b8cf50d\n", - " \t\t\tname: foo 1\n", - " \t\t\tslug: foo1-966beb55\n", - " \t\t\tktype_id: dataset-catalog\n", - " \t\t\tsummary: None\n", - " \t\t\tavatar_exists: False\n", - " \t\t\tannotations: []\n", - " \t\t\tlinked_kitems: [{\n", - " \t\t\tid: 3ca3c293-8845-4f0e-afcb-6c680c07239f\n", - " \t\t}]\n", - " \t\t\texternal_links: []\n", - " \t\t\tcontacts: []\n", - " \t\t\tauthors: [{\n", - " \t\t\tuser_id: 7f0e5a37-353b-4bbc-b1f1-b6ad575f562d\n", - " \t\t}]\n", - " \t\t\tlinked_affiliations: []\n", - " \t\t\tattachments: []\n", - " \t\t\tuser_groups: []\n", - " \t\t\tcustom_properties: None\n", - " \t\t\tcreated_at: 2024-08-20T08:02:08.491699\n", - " \t\t\tupdated_at: 2024-08-20T08:02:08.491699\n", - " \t\t\n", - " \t], \n", - " \n", - " \taffiliations = [], \n", - " \n", - " \tauthors = [\n", - " \t\t{\n", - " \t\t\tuser_id: 7f0e5a37-353b-4bbc-b1f1-b6ad575f562d\n", - " \t\t}\n", - " \t], \n", - " \n", - " \tavatar_exists = False, \n", - " \n", - " \tcontacts = [], \n", - " \n", - " \tcreated_at = 2024-08-20 08:02:09.024038, \n", - " \n", - " \tupdated_at = 2024-08-20 08:02:09.024038, \n", - " \n", - " \texternal_links = [], \n", - " \n", - " \tkitem_apps = [], \n", - " \n", - " \tsummary = None, \n", - " \n", - " \tuser_groups = [], \n", - " \n", - " \tcustom_properties = None, \n", - " \n", - " \tdataframe = None, \n", - " \n", - " \trdf_exists = False\n", - " ), fuzzy=False),\n", - " SearchResult(hit=KItem(\n", - " \n", - " \tname = foo 3, \n", - " \n", - " \tid = 31a58a53-8f50-4f18-93ee-90ff5a806e14, \n", - " \n", - " \tktype_id = organization, \n", - " \n", - " \tin_backend = True, \n", - " \n", - " \tslug = foo3-31a58a53, \n", - " \n", - " \tannotations = [], \n", - " \n", - " \tattachments = [], \n", - " \n", - " \tlinked_kitems = [], \n", - " \n", - " \taffiliations = [], \n", - " \n", - " \tauthors = [\n", - " \t\t{\n", - " \t\t\tuser_id: 7f0e5a37-353b-4bbc-b1f1-b6ad575f562d\n", - " \t\t}\n", - " \t], \n", - " \n", - " \tavatar_exists = False, \n", - " \n", - " \tcontacts = [], \n", - " \n", - " \tcreated_at = 2024-08-20 08:02:09.532080, \n", - " \n", - " \tupdated_at = 2024-08-20 08:02:09.532080, \n", - " \n", - " \texternal_links = [], \n", - " \n", - " \tkitem_apps = [], \n", - " \n", - " \tsummary = None, \n", - " \n", - " \tuser_groups = [], \n", - " \n", - " \tcustom_properties = None, \n", - " \n", - " \tdataframe = None, \n", - " \n", - " \trdf_exists = False\n", - " ), fuzzy=False),\n", - " SearchResult(hit=KItem(\n", - " \n", - " \tname = foo 4, \n", - " \n", - " \tid = 552ab1b9-64df-4343-9e4e-e5c292c3999f, \n", - " \n", - " \tktype_id = organization, \n", - " \n", - " \tin_backend = True, \n", - " \n", - " \tslug = foo4-552ab1b9, \n", - " \n", - " \tannotations = [\n", - " \t\t{\n", - " \t\t\tiri: www.example.org/bar,\n", - " \t\t\tname: bar,\n", - " \t\t\tnamespace: www.example.org,\n", - " \t\t\tdescription: None\n", - " \t\t}\n", - " \t], \n", - " \n", - " \tattachments = [], \n", - " \n", - " \tlinked_kitems = [], \n", - " \n", - " \taffiliations = [], \n", - " \n", - " \tauthors = [\n", - " \t\t{\n", - " \t\t\tuser_id: 7f0e5a37-353b-4bbc-b1f1-b6ad575f562d\n", - " \t\t}\n", - " \t], \n", - " \n", - " \tavatar_exists = False, \n", - " \n", - " \tcontacts = [], \n", - " \n", - " \tcreated_at = 2024-08-20 08:02:10.062595, \n", - " \n", - " \tupdated_at = 2024-08-20 08:02:10.062595, \n", - " \n", - " \texternal_links = [], \n", - " \n", - " \tkitem_apps = [], \n", - " \n", - " \tsummary = None, \n", - " \n", - " \tuser_groups = [], \n", - " \n", - " \tcustom_properties = None, \n", - " \n", - " \tdataframe = None, \n", - " \n", - " \trdf_exists = False\n", - " ), fuzzy=False),\n", - " SearchResult(hit=KItem(\n", - " \n", - " \tname = Research Institute ABC, \n", - " \n", - " \tid = 21aa50c3-5ec2-4ac3-aba8-69071a4287e2, \n", - " \n", - " \tktype_id = organization, \n", - " \n", - " \tin_backend = True, \n", - " \n", - " \tslug = researchinstituteabc-21aa50c3, \n", - " \n", - " \tannotations = [], \n", - " \n", - " \tattachments = [], \n", - " \n", - " \tlinked_kitems = [], \n", - " \n", - " \taffiliations = [], \n", - " \n", - " \tauthors = [\n", - " \t\t{\n", - " \t\t\tuser_id: 7f0e5a37-353b-4bbc-b1f1-b6ad575f562d\n", - " \t\t}\n", - " \t], \n", - " \n", - " \tavatar_exists = False, \n", - " \n", - " \tcontacts = [], \n", - " \n", - " \tcreated_at = 2024-08-19 18:26:00.740761, \n", - " \n", - " \tupdated_at = 2024-08-19 18:26:00.740761, \n", - " \n", - " \texternal_links = [], \n", - " \n", - " \tkitem_apps = [], \n", - " \n", - " \tsummary = None, \n", - " \n", - " \tuser_groups = [], \n", - " \n", - " \tcustom_properties = None, \n", - " \n", - " \tdataframe = None, \n", - " \n", - " \trdf_exists = False\n", - " ), fuzzy=False)]" - ] - }, - "execution_count": 19, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "dsms.search(ktypes=[dsms.ktypes.Organization, dsms.ktypes.DatasetCatalog])" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "... or for all of type `DatasetCatalog` with `foo` in the name:" - ] - }, - { - "cell_type": "code", - "execution_count": 20, - "metadata": {}, - "outputs": [ - { - "data": { - "text/plain": [ - "[SearchResult(hit=KItem(\n", - " \n", - " \tname = foo 1, \n", - " \n", - " \tid = 966beb55-6eb5-422e-b8c1-84d65b8cf50d, \n", - " \n", - " \tktype_id = dataset-catalog, \n", - " \n", - " \tin_backend = True, \n", - " \n", - " \tslug = foo1-966beb55, \n", - " \n", - " \tannotations = [], \n", - " \n", - " \tattachments = [], \n", - " \n", - " \tlinked_kitems = [\n", - " \t\t\n", - " \t\t\tid: 3ca3c293-8845-4f0e-afcb-6c680c07239f\n", - " \t\t\tname: foo 2\n", - " \t\t\tslug: foo2-3ca3c293\n", - " \t\t\tktype_id: organization\n", - " \t\t\tsummary: None\n", - " \t\t\tavatar_exists: False\n", - " \t\t\tannotations: [{\n", - " \t\t\tiri: www.example.org/foo,\n", - " \t\t\tname: foo,\n", - " \t\t\tnamespace: www.example.org,\n", - " \t\t\tdescription: None\n", - " \t\t}]\n", - " \t\t\tlinked_kitems: [{\n", - " \t\t\tid: 966beb55-6eb5-422e-b8c1-84d65b8cf50d\n", - " \t\t}]\n", - " \t\t\texternal_links: []\n", - " \t\t\tcontacts: []\n", - " \t\t\tauthors: [{\n", - " \t\t\tuser_id: 7f0e5a37-353b-4bbc-b1f1-b6ad575f562d\n", - " \t\t}]\n", - " \t\t\tlinked_affiliations: []\n", - " \t\t\tattachments: []\n", - " \t\t\tuser_groups: []\n", - " \t\t\tcustom_properties: None\n", - " \t\t\tcreated_at: 2024-08-20T08:02:09.024038\n", - " \t\t\tupdated_at: 2024-08-20T08:02:09.024038\n", - " \t\t\n", - " \t], \n", - " \n", - " \taffiliations = [], \n", - " \n", - " \tauthors = [\n", - " \t\t{\n", - " \t\t\tuser_id: 7f0e5a37-353b-4bbc-b1f1-b6ad575f562d\n", - " \t\t}\n", - " \t], \n", - " \n", - " \tavatar_exists = False, \n", - " \n", - " \tcontacts = [], \n", - " \n", - " \tcreated_at = 2024-08-20 08:02:08.491699, \n", - " \n", - " \tupdated_at = 2024-08-20 08:02:08.491699, \n", - " \n", - " \texternal_links = [], \n", - " \n", - " \tkitem_apps = [], \n", - " \n", - " \tsummary = None, \n", - " \n", - " \tuser_groups = [], \n", - " \n", - " \tcustom_properties = None, \n", - " \n", - " \tdataframe = None, \n", - " \n", - " \trdf_exists = False\n", - " ), fuzzy=False)]" - ] - }, - "execution_count": 20, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "dsms.search(query=\"foo\", ktypes=[dsms.ktypes.DatasetCatalog])" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "... and for all of type `Organization` with the annotation `www.example.org/foo`:" - ] - }, - { - "cell_type": "code", - "execution_count": 21, - "metadata": {}, - "outputs": [ - { - "data": { - "text/plain": [ - "[SearchResult(hit=KItem(\n", - " \n", - " \tname = foo 2, \n", - " \n", - " \tid = 3ca3c293-8845-4f0e-afcb-6c680c07239f, \n", - " \n", - " \tktype_id = organization, \n", - " \n", - " \tin_backend = True, \n", - " \n", - " \tslug = foo2-3ca3c293, \n", - " \n", - " \tannotations = [\n", - " \t\t{\n", - " \t\t\tiri: www.example.org/foo,\n", - " \t\t\tname: foo,\n", - " \t\t\tnamespace: www.example.org,\n", - " \t\t\tdescription: None\n", - " \t\t}\n", - " \t], \n", - " \n", - " \tattachments = [], \n", - " \n", - " \tlinked_kitems = [\n", - " \t\t\n", - " \t\t\tid: 966beb55-6eb5-422e-b8c1-84d65b8cf50d\n", - " \t\t\tname: foo 1\n", - " \t\t\tslug: foo1-966beb55\n", - " \t\t\tktype_id: dataset-catalog\n", - " \t\t\tsummary: None\n", - " \t\t\tavatar_exists: False\n", - " \t\t\tannotations: []\n", - " \t\t\tlinked_kitems: [{\n", - " \t\t\tid: 3ca3c293-8845-4f0e-afcb-6c680c07239f\n", - " \t\t}]\n", - " \t\t\texternal_links: []\n", - " \t\t\tcontacts: []\n", - " \t\t\tauthors: [{\n", - " \t\t\tuser_id: 7f0e5a37-353b-4bbc-b1f1-b6ad575f562d\n", - " \t\t}]\n", - " \t\t\tlinked_affiliations: []\n", - " \t\t\tattachments: []\n", - " \t\t\tuser_groups: []\n", - " \t\t\tcustom_properties: None\n", - " \t\t\tcreated_at: 2024-08-20T08:02:08.491699\n", - " \t\t\tupdated_at: 2024-08-20T08:02:08.491699\n", - " \t\t\n", - " \t], \n", - " \n", - " \taffiliations = [], \n", - " \n", - " \tauthors = [\n", - " \t\t{\n", - " \t\t\tuser_id: 7f0e5a37-353b-4bbc-b1f1-b6ad575f562d\n", - " \t\t}\n", - " \t], \n", - " \n", - " \tavatar_exists = False, \n", - " \n", - " \tcontacts = [], \n", - " \n", - " \tcreated_at = 2024-08-20 08:02:09.024038, \n", - " \n", - " \tupdated_at = 2024-08-20 08:02:09.024038, \n", - " \n", - " \texternal_links = [], \n", - " \n", - " \tkitem_apps = [], \n", - " \n", - " \tsummary = None, \n", - " \n", - " \tuser_groups = [], \n", - " \n", - " \tcustom_properties = None, \n", - " \n", - " \tdataframe = None, \n", - " \n", - " \trdf_exists = False\n", - " ), fuzzy=False)]" - ] - }, - "execution_count": 21, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "dsms.search(\n", - " ktypes=[dsms.ktypes.Organization], annotations=[\"www.example.org/foo\"]\n", - " )" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "Clean up the DSMS from the tutortial:" - ] - }, - { - "cell_type": "code", - "execution_count": 22, - "metadata": {}, - "outputs": [], - "source": [ - "del dsms[item]\n", - "del dsms[item2]\n", - "del dsms[item3]\n", - "del dsms[item4]\n", - "\n", - "dsms.commit()\n" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "### 6. Apps" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "We can investigate which apps are available through JupyterLab:" - ] - }, - { - "cell_type": "code", - "execution_count": 23, - "metadata": {}, - "outputs": [ - { - "data": { - "text/plain": [ - "[AppConfig(name=ckan-fetch, specification={'metadata': {'generateName': 'ckan-resource-request-'}}),\n", - " AppConfig(name=csv_tensile_test, specification={'metadata': {'generateName': 'data2rdf-'}}),\n", - " AppConfig(name=csv_tensile_test_f2, specification={'metadata': {'generateName': 'data2rdf-'}}),\n", - " AppConfig(name=excel_notched_tensile_test, specification={'metadata': {'generateName': 'data2rdf-'}}),\n", - " AppConfig(name=excel_shear_test, specification={'metadata': {'generateName': 'data2rdf-'}}),\n", - " AppConfig(name=excel_tensile_test, specification={'metadata': {'generateName': 'data2rdf-'}}),\n", - " AppConfig(name=ternary-plot, specification={'metadata': {'generateName': 'ckan-tenary-app-'}})]" - ] - }, - "execution_count": 23, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "dsms.app_configs" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "7. HDF5 " - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "We are also able to upload dataframes or time series data and investigate them:" - ] - }, - { - "cell_type": "code", - "execution_count": 24, - "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "Column-wise:\n", - "column: a ,\n", - " data: [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95, 96, 97, 98, 99]\n", - "column: b ,\n", - " data: [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95, 96, 97, 98, 99, 100]\n", - "\n", - "As data frame:\n", - " a b\n", - "0 0 1\n", - "1 1 2\n", - "2 2 3\n", - "3 3 4\n", - "4 4 5\n", - ".. .. ...\n", - "95 95 96\n", - "96 96 97\n", - "97 97 98\n", - "98 98 99\n", - "99 99 100\n", - "\n", - "[100 rows x 2 columns]\n" - ] - } - ], - "source": [ - "data = {\"a\": list(range(100)), \"b\": list(range(1,101))}\n", - "\n", - "\n", - "item = KItem(name=\"testdata1234\", ktype_id=dsms.ktypes.DatasetCatalog, dataframe=data)\n", - "dsms.commit()\n", - "\n", - "print(\"Column-wise:\")\n", - "for column in item.dataframe:\n", - " print(\"column:\", column.name, \",\\n\", \"data:\", column.get())\n", - "\n", - "df = item.dataframe.to_df()\n", - "print(\"\\nAs data frame:\")\n", - "print(df)\n", - "\n", - "new_df = df.drop(['a'], axis=1)\n", - "item.dataframe = new_df\n", - "\n", - "dsms.commit()" - ] - }, - { - "cell_type": "code", - "execution_count": 25, - "metadata": {}, - "outputs": [], - "source": [ - "del dsms[item]" - ] - }, - { - "cell_type": "code", - "execution_count": 26, - "metadata": {}, - "outputs": [], - "source": [ - "dsms.commit()" - ] - } - ], - "metadata": { - "kernelspec": { - "display_name": "sdk", - "language": "python", - "name": "python3" - }, - "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.12.2" - } - }, - "nbformat": 4, - "nbformat_minor": 2 -} diff --git a/examples/tutorials/1_introduction.ipynb b/examples/tutorials/1_introduction.ipynb deleted file mode 100644 index 1665bb0..0000000 --- a/examples/tutorials/1_introduction.ipynb +++ /dev/null @@ -1,216 +0,0 @@ -{ - "cells": [ - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "# 1. Connecting with the SDK to DSMS\n", - "\n", - "In this tutorial we see the overview on how to setup and basic use DSMS-SDK\n" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "### 1.1. Setting up" - ] - }, - { - "cell_type": "code", - "execution_count": 5, - "metadata": {}, - "outputs": [], - "source": [ - "from dsms import DSMS" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "Now source the environmental variables from an `.env` file and start the DSMS-session." - ] - }, - { - "cell_type": "code", - "execution_count": 6, - "metadata": {}, - "outputs": [], - "source": [ - "dsms = DSMS(env=\"../../.env\")" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "### 1.2. Introduction to KItems" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "We can see which kind of DSMS-object we own as a user (in the beginning, we own none):" - ] - }, - { - "cell_type": "code", - "execution_count": 7, - "metadata": {}, - "outputs": [ - { - "data": { - "text/plain": [ - "[]" - ] - }, - "execution_count": 7, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "dsms.kitems" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "We can investigate what a KItem needs in order to be created. KItems are entirely based on Pydantic-Models (v2), hence the properties (in Pydantic called Fields) are automatically validated once we set them.\n", - "\n", - "The schema of the KItem itself is a JSON schema which is machine-readable and can be directly incorporated into Swagger-supported APIs like e.g. FastAPI.\n", - "\n", - "We can investigate the KTypes defined in the remote instance:" - ] - }, - { - "cell_type": "code", - "execution_count": 8, - "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "Organization(\n", - "\tid=organization,\n", - "\tname=None,\n", - "\twebform=None,\n", - "\tjson_schema=None,\n", - "\trdf_mapping=None,\n", - "\tcreated_at=2024-05-06T13:01:42.756035,\n", - "\tupdated_at=2024-05-06T13:01:42.756035\n", - ")\n", - "App(\n", - "\tid=app,\n", - "\tname=None,\n", - "\twebform=None,\n", - "\tjson_schema=None,\n", - "\trdf_mapping=None,\n", - "\tcreated_at=2024-05-06T13:01:42.756035,\n", - "\tupdated_at=2024-05-06T13:01:42.756035\n", - ")\n", - "Dataset(\n", - "\tid=dataset,\n", - "\tname=dataset,\n", - "\twebform=None,\n", - "\tjson_schema=None,\n", - "\trdf_mapping=None,\n", - "\tcreated_at=2024-05-06T13:01:42.756035,\n", - "\tupdated_at=2024-05-06T13:01:42.756035\n", - ")\n", - "DatasetCatalog(\n", - "\tid=dataset-catalog,\n", - "\tname=dataset catalog,\n", - "\twebform=None,\n", - "\tjson_schema=None,\n", - "\trdf_mapping=None,\n", - "\tcreated_at=2024-05-06T13:01:42.756035,\n", - "\tupdated_at=2024-05-06T13:01:42.756035\n", - ")\n", - "Expert(\n", - "\tid=expert,\n", - "\tname=expert,\n", - "\twebform={\n", - "\t\tname=dict(annotation=Union[str, NoneType] required=False default=None),\n", - "\t\tskills=dict(annotation=Union[str, NoneType] required=False default=None)\n", - "\t},\n", - "\tjson_schema=None,\n", - "\trdf_mapping=None,\n", - "\tcreated_at=2024-05-06T13:01:42.756035,\n", - "\tupdated_at=2024-05-06T17:09:46.125058\n", - ")\n", - "Test(\n", - "\tid=test,\n", - "\tname=test,\n", - "\twebform=None,\n", - "\tjson_schema=None,\n", - "\trdf_mapping=None,\n", - "\tcreated_at=2024-05-14T07:45:38.051796,\n", - "\tupdated_at=2024-05-14T07:45:38.051796\n", - ")\n", - "Specimen(\n", - "\tid=specimen,\n", - "\tname=Specimen,\n", - "\twebform={\n", - "\t\tsampletype=dict(annotation=Union[str, NoneType] required=False default=None),\n", - "\t\tsampleinformation=dict(annotation=Union[str, NoneType] required=False default=None),\n", - "\t\tsampleproductionprocess=dict(annotation=Union[str, NoneType] required=False default=None)\n", - "\t},\n", - "\tjson_schema=None,\n", - "\trdf_mapping=None,\n", - "\tcreated_at=2024-05-22T07:19:24.079365,\n", - "\tupdated_at=2024-05-22T07:20:08.774884\n", - ")\n", - "Resource(\n", - "\tid=resource,\n", - "\tname=Resource,\n", - "\twebform=None,\n", - "\tjson_schema=None,\n", - "\trdf_mapping=None,\n", - "\tcreated_at=2024-06-10T10:17:31.071959,\n", - "\tupdated_at=2024-06-10T10:17:40.156104\n", - ")\n", - "TestingMachine(\n", - "\tid=testing-machine,\n", - "\tname=Testing Machine,\n", - "\twebform=None,\n", - "\tjson_schema=None,\n", - "\trdf_mapping=None,\n", - "\tcreated_at=2024-08-19T17:13:57.534570,\n", - "\tupdated_at=2024-08-19T18:11:40.465640\n", - ")\n" - ] - } - ], - "source": [ - "for ktype in dsms.ktypes:\n", - " print(ktype)" - ] - } - ], - "metadata": { - "kernelspec": { - "display_name": "sdk", - "language": "python", - "name": "python3" - }, - "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.12.2" - } - }, - "nbformat": 4, - "nbformat_minor": 2 -} diff --git a/examples/tutorials/2_creation.ipynb b/examples/tutorials/2_creation.ipynb deleted file mode 100644 index 5cb7539..0000000 --- a/examples/tutorials/2_creation.ipynb +++ /dev/null @@ -1,386 +0,0 @@ -{ - "cells": [ - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "# 2. Create KItems with the SDK\n", - "\n", - "In this tutorial we see how to create new Kitems." - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "### 2.1. Setting up\n", - "\n", - "Now let us import the needed classes and functions for this tutorial." - ] - }, - { - "cell_type": "code", - "execution_count": 12, - "metadata": {}, - "outputs": [], - "source": [ - "from dsms import DSMS, KItem" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "Now source the environmental variables from an `.env` file and start the DSMS-session." - ] - }, - { - "cell_type": "code", - "execution_count": 13, - "metadata": {}, - "outputs": [], - "source": [ - "dsms = DSMS(env=\"../../.env\")" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "\n", - "### 2.2: Create KItems" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "We can make new KItems by simple class-initiation: (Make sure existing KItems are not given as input). \n", - "#" - ] - }, - { - "cell_type": "code", - "execution_count": 14, - "metadata": {}, - "outputs": [ - { - "data": { - "text/plain": [ - "KItem(\n", - "\n", - "\tname = Machine-1, \n", - "\n", - "\tid = c4128bec-3ecd-4c92-a307-7015bc9f2e86, \n", - "\n", - "\tktype_id = KTypes.TestingMachine, \n", - "\n", - "\tin_backend = False, \n", - "\n", - "\tslug = machine-1-c4128bec, \n", - "\n", - "\tannotations = [], \n", - "\n", - "\tattachments = [], \n", - "\n", - "\tlinked_kitems = [], \n", - "\n", - "\taffiliations = [], \n", - "\n", - "\tauthors = [], \n", - "\n", - "\tavatar_exists = False, \n", - "\n", - "\tcontacts = [], \n", - "\n", - "\tcreated_at = None, \n", - "\n", - "\tupdated_at = None, \n", - "\n", - "\texternal_links = [], \n", - "\n", - "\tkitem_apps = [], \n", - "\n", - "\tsummary = None, \n", - "\n", - "\tuser_groups = [], \n", - "\n", - "\tcustom_properties = {\n", - "\t\tProducer: TestingLab GmBH, \n", - "\t\tLocation: A404, \n", - "\t\tModel Number: Bending Test Machine No 777\n", - "\t}, \n", - "\n", - "\tdataframe = None, \n", - "\n", - "\trdf_exists = False\n", - ")" - ] - }, - "execution_count": 14, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "item = KItem(\n", - " name=\"Machine-1\",\n", - " ktype_id=dsms.ktypes.TestingMachine,\n", - " custom_properties={\"Producer\": \"TestingLab GmBH\",\n", - " \"Location\": \"A404\",\n", - " \"Model Number\" : \"Bending Test Machine No 777\"\n", - " },\n", - ")\n", - "\n", - "item" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "Remember: changes are only syncronized with the DSMS when you call the `commit`-method:" - ] - }, - { - "cell_type": "code", - "execution_count": 15, - "metadata": {}, - "outputs": [ - { - "data": { - "text/plain": [ - "'https://bue.materials-data.space/knowledge/testing-machine/machine-1-c4128bec'" - ] - }, - "execution_count": 15, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "dsms.commit()\n", - "item.url" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "As we can see, the object we created before running the `commit`-method has automatically been updated, e.g. with the creation- and update-timestamp. We can check this with the below command:" - ] - }, - { - "cell_type": "code", - "execution_count": 16, - "metadata": {}, - "outputs": [ - { - "data": { - "text/plain": [ - "KItem(\n", - "\n", - "\tname = Machine-1, \n", - "\n", - "\tid = c4128bec-3ecd-4c92-a307-7015bc9f2e86, \n", - "\n", - "\tktype_id = testing-machine, \n", - "\n", - "\tin_backend = True, \n", - "\n", - "\tslug = machine-1-c4128bec, \n", - "\n", - "\tannotations = [], \n", - "\n", - "\tattachments = [], \n", - "\n", - "\tlinked_kitems = [], \n", - "\n", - "\taffiliations = [], \n", - "\n", - "\tauthors = [\n", - "\t\t{\n", - "\t\t\tuser_id: 7f0e5a37-353b-4bbc-b1f1-b6ad575f562d\n", - "\t\t}\n", - "\t], \n", - "\n", - "\tavatar_exists = False, \n", - "\n", - "\tcontacts = [], \n", - "\n", - "\tcreated_at = 2024-10-01 14:21:54.195585, \n", - "\n", - "\tupdated_at = 2024-10-01 14:21:54.195585, \n", - "\n", - "\texternal_links = [], \n", - "\n", - "\tkitem_apps = [], \n", - "\n", - "\tsummary = None, \n", - "\n", - "\tuser_groups = [], \n", - "\n", - "\tcustom_properties = {\n", - "\t\tProducer: TestingLab GmBH, \n", - "\t\tLocation: A404, \n", - "\t\tModel Number: Bending Test Machine No 777\n", - "\t}, \n", - "\n", - "\tdataframe = None, \n", - "\n", - "\trdf_exists = False\n", - ")" - ] - }, - "execution_count": 16, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "item" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "To just get the name of the item, we can do it as follows:" - ] - }, - { - "cell_type": "code", - "execution_count": 17, - "metadata": {}, - "outputs": [ - { - "data": { - "text/plain": [ - "'Machine-1'" - ] - }, - "execution_count": 17, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "item.name" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "As well as the id of the kitem we can do it as follows:" - ] - }, - { - "cell_type": "code", - "execution_count": 18, - "metadata": {}, - "outputs": [ - { - "data": { - "text/plain": [ - "UUID('c4128bec-3ecd-4c92-a307-7015bc9f2e86')" - ] - }, - "execution_count": 18, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "item.id" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "To check the KType of the item newly created we can use the following:" - ] - }, - { - "cell_type": "code", - "execution_count": 19, - "metadata": {}, - "outputs": [ - { - "data": { - "text/plain": [ - "KType(id='testing-machine', name='Testing Machine', webform=, json_schema=None, rdf_mapping=None, created_at='2024-08-19T17:13:57.534570', updated_at='2024-08-19T18:11:40.465640')" - ] - }, - "execution_count": 19, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "item.ktype" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "... and also check the KType:" - ] - }, - { - "cell_type": "code", - "execution_count": 20, - "metadata": {}, - "outputs": [ - { - "data": { - "text/plain": [ - "True" - ] - }, - "execution_count": 20, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "item.is_a(dsms.ktypes.TestingMachine)" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "\n", - "Now you can check if the particular kitem is in the list of KItems. This can be done either by using the command:\n", - " `\n", - " dsms.kitems\n", - " `\n", - " or by logging into the frontend dsms instance." - ] - } - ], - "metadata": { - "kernelspec": { - "display_name": "sdk", - "language": "python", - "name": "python3" - }, - "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.12.2" - } - }, - "nbformat": 4, - "nbformat_minor": 2 -} diff --git a/examples/tutorials/3_updation.ipynb b/examples/tutorials/3_updation.ipynb deleted file mode 100644 index 3bf4d84..0000000 --- a/examples/tutorials/3_updation.ipynb +++ /dev/null @@ -1,287 +0,0 @@ -{ - "cells": [ - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "# 3. Updating KItems with the SDK\n", - "\n", - "In this tutorial we see how to update existing Kitems." - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "### 3.1. Setting up\n" - ] - }, - { - "cell_type": "code", - "execution_count": 13, - "metadata": {}, - "outputs": [], - "source": [ - "from dsms import DSMS" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "Now source the environmental variables from an `.env` file and start the DSMS-session." - ] - }, - { - "cell_type": "code", - "execution_count": 14, - "metadata": {}, - "outputs": [], - "source": [ - "dsms = DSMS(env=\"../../.env\")" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "Now lets get the kitem we created in the [2nd tutorial : Creation of Kitems](2_creation.ipynb)\n" - ] - }, - { - "cell_type": "code", - "execution_count": 15, - "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "Machine-1\n" - ] - } - ], - "source": [ - "item = dsms.kitems[-1]\n", - "print(item.name)" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "### 3.2. Updating Kitems" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "Now, we would like to update the properties of our KItem we created previously.\n", - "\n", - "Depending on the schema of each property (see [DSMS KItem Schema](../dsms_kitem_schema.md)), we can simply use the standard `list`-method as we know them from basic Python (e.g. for the `annotations`, `attachments`, `external_link`, etc). \n", - "\n", - "Other properties which are not `list`-like can be simply set by attribute-assignment (e.g. `name`, `slug`, `ktype_id`, etc)." - ] - }, - { - "cell_type": "code", - "execution_count": 16, - "metadata": {}, - "outputs": [], - "source": [ - "item.name = \"Machine-1\"\n", - "item.custom_properties.Producer = \"Machinery GmBH\"\n", - "item.attachments.append(\"testfile.txt\")\n", - "item.annotations.append(\"www.machinery.org/\")\n", - "item.external_links.append(\n", - " {\"url\": \"http://machine.org\", \"label\": \"machine-link\"}\n", - ")\n", - "item.contacts.append({\"name\": \"machinesupport\", \"email\": \"machinesupport@group.mail\"})\n", - "item.affiliations.append(\"machine-team\")\n", - "item.user_groups.append({\"name\": \"machinegroup\", \"group_id\": \"123\"})" - ] - }, - { - "cell_type": "code", - "execution_count": 17, - "metadata": {}, - "outputs": [], - "source": [ - "dsms.commit()" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "We can see now that the local system path of the attachment is changed to a simply file name, which means that the upload was successful. If not so, an error would have been thrown during the `commit`." - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "We can see the updates when we print the item:" - ] - }, - { - "cell_type": "code", - "execution_count": 19, - "metadata": {}, - "outputs": [ - { - "data": { - "text/plain": [ - "KItem(\n", - "\n", - "\tname = Machine-1, \n", - "\n", - "\tid = dd091666-a7c9-4b3b-8832-910bdec5c63c, \n", - "\n", - "\tktype_id = testing-machine, \n", - "\n", - "\tin_backend = True, \n", - "\n", - "\tslug = machine-1-dd091666, \n", - "\n", - "\tannotations = [\n", - "\t\t{\n", - "\t\t\tiri: www.machinery.org/,\n", - "\t\t\tname: ,\n", - "\t\t\tnamespace: www.machinery.org,\n", - "\t\t\tdescription: None\n", - "\t\t}\n", - "\t], \n", - "\n", - "\tattachments = [\n", - "\t\t{\n", - "\t\t\tname: testfile.txt\n", - "\t\t}\n", - "\t], \n", - "\n", - "\tlinked_kitems = [], \n", - "\n", - "\taffiliations = [\n", - "\t\t{\n", - "\t\t\tname: machine-team\n", - "\t\t}\n", - "\t], \n", - "\n", - "\tauthors = [\n", - "\t\t{\n", - "\t\t\tuser_id: 7f0e5a37-353b-4bbc-b1f1-b6ad575f562d\n", - "\t\t}\n", - "\t], \n", - "\n", - "\tavatar_exists = False, \n", - "\n", - "\tcontacts = [\n", - "\t\t{\n", - "\t\t\tname: machinesupport,\n", - "\t\t\temail: machinesupport@group.mail,\n", - "\t\t\tuser_id: None\n", - "\t\t}\n", - "\t], \n", - "\n", - "\tcreated_at = 2024-08-19 18:12:11.338394, \n", - "\n", - "\tupdated_at = 2024-08-19 18:12:11.338394, \n", - "\n", - "\texternal_links = [\n", - "\t\t{\n", - "\t\t\tlabel: machine-link,\n", - "\t\t\turl: http://machine.org/\n", - "\t\t}\n", - "\t], \n", - "\n", - "\tkitem_apps = [], \n", - "\n", - "\tsummary = None, \n", - "\n", - "\tuser_groups = [\n", - "\t\t{\n", - "\t\t\tname: machinegroup,\n", - "\t\t\tgroup_id: 123\n", - "\t\t}\n", - "\t], \n", - "\n", - "\tcustom_properties = {\n", - "\t\tProducer: Machinery GmBH, \n", - "\t\tLocation: A404, \n", - "\t\tModel Number: Bending Test Machine No 777\n", - "\t}, \n", - "\n", - "\tdataframe = None, \n", - "\n", - "\trdf_exists = False\n", - ")" - ] - }, - "execution_count": 19, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "item" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "Furthermore we can also download the file we uploaded again:" - ] - }, - { - "cell_type": "code", - "execution_count": 18, - "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "\t\t\t Downloaded file: {\n", - "\t\t\tname: testfile.txt\n", - "\t\t}\n", - "|------------------------------------Beginning of file------------------------------------|\n", - "This is a calibration protocol!\n", - "|---------------------------------------End of file---------------------------------------|\n" - ] - } - ], - "source": [ - "for file in item.attachments:\n", - " download = file.download()\n", - "\n", - " print(\"\\t\\t\\t Downloaded file:\", file)\n", - " print(\"|------------------------------------Beginning of file------------------------------------|\")\n", - " print(download)\n", - " print(\"|---------------------------------------End of file---------------------------------------|\")" - ] - } - ], - "metadata": { - "kernelspec": { - "display_name": "sdk", - "language": "python", - "name": "python3" - }, - "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.10.12" - } - }, - "nbformat": 4, - "nbformat_minor": 2 -} diff --git a/examples/tutorials/4_deletion.ipynb b/examples/tutorials/4_deletion.ipynb deleted file mode 100644 index 210df6b..0000000 --- a/examples/tutorials/4_deletion.ipynb +++ /dev/null @@ -1,404 +0,0 @@ -{ - "cells": [ - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "# 4. Deleting KItems with the SDK\n", - "\n", - "In this tutorial we see how to delete new Kitems and their properties." - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "### 4.1. Setting up\n" - ] - }, - { - "cell_type": "code", - "execution_count": 1, - "metadata": {}, - "outputs": [], - "source": [ - "from dsms import DSMS" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "Now source the environmental variables from an `.env` file and start the DSMS-session." - ] - }, - { - "cell_type": "code", - "execution_count": 2, - "metadata": {}, - "outputs": [], - "source": [ - "dsms = DSMS(env=\"../../.env\")" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "Then lets see the Kitem we are interested in to remove." - ] - }, - { - "cell_type": "code", - "execution_count": 3, - "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "KItem(\n", - "\n", - "\tname = Machine-1, \n", - "\n", - "\tid = dd091666-a7c9-4b3b-8832-910bdec5c63c, \n", - "\n", - "\tktype_id = testing-machine, \n", - "\n", - "\tin_backend = True, \n", - "\n", - "\tslug = machine-1-dd091666, \n", - "\n", - "\tannotations = [\n", - "\t\t{\n", - "\t\t\tiri: www.machinery.org/,\n", - "\t\t\tname: ,\n", - "\t\t\tnamespace: www.machinery.org,\n", - "\t\t\tdescription: None\n", - "\t\t}\n", - "\t], \n", - "\n", - "\tattachments = [\n", - "\t\t{\n", - "\t\t\tname: testfile.txt\n", - "\t\t}\n", - "\t], \n", - "\n", - "\tlinked_kitems = [], \n", - "\n", - "\taffiliations = [\n", - "\t\t{\n", - "\t\t\tname: machine-team\n", - "\t\t}\n", - "\t], \n", - "\n", - "\tauthors = [\n", - "\t\t{\n", - "\t\t\tuser_id: 7f0e5a37-353b-4bbc-b1f1-b6ad575f562d\n", - "\t\t}\n", - "\t], \n", - "\n", - "\tavatar_exists = False, \n", - "\n", - "\tcontacts = [\n", - "\t\t{\n", - "\t\t\tname: machinesupport,\n", - "\t\t\temail: machinesupport@group.mail,\n", - "\t\t\tuser_id: None\n", - "\t\t}\n", - "\t], \n", - "\n", - "\tcreated_at = 2024-08-19 18:12:11.338394, \n", - "\n", - "\tupdated_at = 2024-08-19 18:12:11.338394, \n", - "\n", - "\texternal_links = [\n", - "\t\t{\n", - "\t\t\tlabel: machine-link,\n", - "\t\t\turl: http://machine.org/\n", - "\t\t}\n", - "\t], \n", - "\n", - "\tkitem_apps = [], \n", - "\n", - "\tsummary = None, \n", - "\n", - "\tuser_groups = [\n", - "\t\t{\n", - "\t\t\tname: machinegroup,\n", - "\t\t\tgroup_id: 123\n", - "\t\t}\n", - "\t], \n", - "\n", - "\tcustom_properties = {\n", - "\t\tProducer: Machinery GmBH, \n", - "\t\tLocation: A404, \n", - "\t\tModel Number: Bending Test Machine No 777\n", - "\t}, \n", - "\n", - "\tdataframe = None, \n", - "\n", - "\trdf_exists = False\n", - ")\n" - ] - } - ], - "source": [ - "item = dsms.kitems[-1]\n", - "print(item)" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "### 4.2. Deletion of KItems and their properties" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "We can also remove properties from the KItem without deleting the KItem itself.\n", - "\n", - "For the `list`-like properties, we can use the standard `list`-methods from basic Python again (e.g. `pop`, `remove`, etc. or the `del`-operator).\n", - "\n", - "For the other, non-`list`-like properties, we can simply use the attribute-assignment again.\n", - "\n", - "When we only want single parts of the properties in the KItem, we can do it like this:" - ] - }, - { - "cell_type": "code", - "execution_count": 4, - "metadata": {}, - "outputs": [ - { - "data": { - "text/plain": [ - "{\n", - "\t\t\tname: machinegroup,\n", - "\t\t\tgroup_id: 123\n", - "\t\t}" - ] - }, - "execution_count": 4, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "item.attachments.pop(0)\n", - "item.annotations.pop(0)\n", - "item.external_links.pop(0)\n", - "item.contacts.pop(0)\n", - "item.user_groups.pop(0)" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "However, we can also reset the entire property by setting it to e.g. an empty list again:" - ] - }, - { - "cell_type": "code", - "execution_count": 5, - "metadata": {}, - "outputs": [], - "source": [ - "item.affiliations = []" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "We can delete the custom properties by setting the property to an empty dict:" - ] - }, - { - "cell_type": "code", - "execution_count": 6, - "metadata": {}, - "outputs": [], - "source": [ - "item.custom_properties = {}" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "Send the changes to the DSMS with the `commit`-method:" - ] - }, - { - "cell_type": "code", - "execution_count": 8, - "metadata": {}, - "outputs": [], - "source": [ - "dsms.commit()" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "See the changes:" - ] - }, - { - "cell_type": "code", - "execution_count": 11, - "metadata": {}, - "outputs": [ - { - "data": { - "text/plain": [ - "KItem(\n", - "\n", - "\tname = Machine-1, \n", - "\n", - "\tid = dd091666-a7c9-4b3b-8832-910bdec5c63c, \n", - "\n", - "\tktype_id = testing-machine, \n", - "\n", - "\tin_backend = True, \n", - "\n", - "\tslug = machine-1-dd091666, \n", - "\n", - "\tannotations = [], \n", - "\n", - "\tattachments = [], \n", - "\n", - "\tlinked_kitems = [], \n", - "\n", - "\taffiliations = [\n", - "\t\t{\n", - "\t\t\tname: machine-team\n", - "\t\t}\n", - "\t], \n", - "\n", - "\tauthors = [\n", - "\t\t{\n", - "\t\t\tuser_id: 7f0e5a37-353b-4bbc-b1f1-b6ad575f562d\n", - "\t\t}\n", - "\t], \n", - "\n", - "\tavatar_exists = False, \n", - "\n", - "\tcontacts = [\n", - "\t\t{\n", - "\t\t\tname: machinesupport,\n", - "\t\t\temail: machinesupport@group.mail,\n", - "\t\t\tuser_id: None\n", - "\t\t}\n", - "\t], \n", - "\n", - "\tcreated_at = 2024-08-19 18:12:11.338394, \n", - "\n", - "\tupdated_at = 2024-08-19 18:12:11.338394, \n", - "\n", - "\texternal_links = [\n", - "\t\t{\n", - "\t\t\tlabel: machine-link,\n", - "\t\t\turl: http://machine.org/\n", - "\t\t}\n", - "\t], \n", - "\n", - "\tkitem_apps = [], \n", - "\n", - "\tsummary = None, \n", - "\n", - "\tuser_groups = [], \n", - "\n", - "\tcustom_properties = {\n", - "\t\tid: dd091666-a7c9-4b3b-8832-910bdec5c63c, \n", - "\t\tcontent: {}\n", - "\t}, \n", - "\n", - "\tdataframe = None, \n", - "\n", - "\trdf_exists = False\n", - ")" - ] - }, - "execution_count": 11, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "item" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "However, we can also delete the whole KItem from the DSMS by applying the `del`-operator to the `dsms`-object with the individual `KItem`-object:" - ] - }, - { - "cell_type": "code", - "execution_count": 9, - "metadata": {}, - "outputs": [], - "source": [ - "del dsms[item]" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "\n", - "Commit the changes:" - ] - }, - { - "cell_type": "code", - "execution_count": 10, - "metadata": {}, - "outputs": [], - "source": [ - "dsms.commit()" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "Now to check if the particular kitem was removed, we can do this by using the command:\n", - " `\n", - " dsms.kitems\n", - " `\n", - " or by logging into the frontend dsms instance." - ] - } - ], - "metadata": { - "kernelspec": { - "display_name": "sdk", - "language": "python", - "name": "python3" - }, - "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.10.12" - } - }, - "nbformat": 4, - "nbformat_minor": 2 -} diff --git a/examples/tutorials/5_search.ipynb b/examples/tutorials/5_search.ipynb deleted file mode 100644 index 42610d3..0000000 --- a/examples/tutorials/5_search.ipynb +++ /dev/null @@ -1,1323 +0,0 @@ -{ - "cells": [ - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "# 5. Searching KItems with the SDK\n", - "\n", - "In this tutorial we see how to search existing Kitems" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "### 5.1. Setting up\n" - ] - }, - { - "cell_type": "code", - "execution_count": 1, - "metadata": {}, - "outputs": [], - "source": [ - "from dsms import DSMS, KItem" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "Now source the environmental variables from an `.env` file and start the DSMS-session." - ] - }, - { - "cell_type": "code", - "execution_count": 2, - "metadata": {}, - "outputs": [], - "source": [ - "dsms = DSMS(env=\"../../.env\")" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "### 5.2. Searching for KItems" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "In this section, we would like to search for specfic KItems we created in the DSMS.\n", - "\n", - "For this purpose, we will firstly create some KItems and apply the `search`-method on the `DSMS`-object later on in order to find them again in the DSMS.\n", - "\n", - "We also want to demonstrate here, that we can link KItems to each other in order to find e.g. a related item of type `DatasetCatalog`. For this strategy, we are using the `linked_kitems`- attribute and the `id` of the item which we would like to link.\n", - "\n", - "The procedure looks like this:" - ] - }, - { - "cell_type": "code", - "execution_count": 3, - "metadata": {}, - "outputs": [], - "source": [ - "item1 = KItem(\n", - " name=\"Machine-1\",\n", - " ktype_id=dsms.ktypes.TestingMachine,\n", - " annotations=[\"https://w3id.org/steel/ProcessOntology/TestingMachine\"],\n", - " custom_properties={\"Producer\": \"TestingLab GmBH\",\n", - " \"Room Number\": \"A404\",\n", - " \"Description\": \"Bending Test Machine\"\n", - " }\n", - ")\n", - "\n", - "item2 = KItem(\n", - " name=\"Machine-2\",\n", - " ktype_id=dsms.ktypes.TestingMachine,\n", - " annotations=[\"https://w3id.org/steel/ProcessOntology/TestingMachine\"],\n", - " custom_properties={\"Producer\": \"StressStrain GmBH\",\n", - " \"Room Number\": \"B500\",\n", - " \"Description\": \"Compression Test Machine\"\n", - " }\n", - ")\n", - "\n", - "item3 = KItem(\n", - " name=\"Specimen-1\", \n", - " ktype_id=dsms.ktypes.Specimen,\n", - " linked_kitems=[item1],\n", - " annotations=[\"https://w3id.org/steel/ProcessOntology/TestPiece\"],\n", - " custom_properties={\"Geometry\": \"Cylindrical 150mm x 20mm x 40mm\",\n", - " \"Material\": \"Concrete\",\n", - " \"Project ID\": \"ConstructionProject2024\"\n", - " }\n", - "\n", - ")\n", - "item4 = KItem(\n", - " name=\"Specimen-2\",\n", - " ktype_id=dsms.ktypes.Specimen,\n", - " linked_kitems=[item2],\n", - " annotations=[\"https://w3id.org/steel/ProcessOntology/TestPiece\"],\n", - " custom_properties={\"Geometry\": \"Rectangular 200mm x 30mm x 20mm\",\n", - " \"Material\": \"Metal\",\n", - " \"Project ID\": \"MetalBlenders2024\"\n", - " }\n", - ")\n", - "\n", - "item5 = KItem(\n", - " name=\"Research Institute ABC\",\n", - " ktype_id=dsms.ktypes.Organization,\n", - " linked_kitems=[item1,item2],\n", - " annotations=[\"www.researchBACiri.org/foo\"],\n", - ")\n", - "\n", - "dsms.commit()" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "\n", - "

Note : Here in this tutorial, we use dsms.search with `limit=1` to maintain readability but the user can adjust the variable `limit` as per requirement.

\n", - "\n", - "\n", - "Now, we are apply to search for e.g. kitems of type `TestingMachine`:" - ] - }, - { - "cell_type": "code", - "execution_count": 4, - "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "KItem(\n", - "\n", - "\tname = Machine-1, \n", - "\n", - "\tid = 1d2c5439-1971-4a92-907b-e30ce00da344, \n", - "\n", - "\tktype_id = testing-machine, \n", - "\n", - "\tin_backend = True, \n", - "\n", - "\tslug = machine-1-1d2c5439, \n", - "\n", - "\tannotations = [\n", - "\t\t{\n", - "\t\t\tiri: https://w3id.org/steel/ProcessOntology/TestingMachine,\n", - "\t\t\tname: TestingMachine,\n", - "\t\t\tnamespace: https://w3id.org/steel/ProcessOntology,\n", - "\t\t\tdescription: None\n", - "\t\t}\n", - "\t], \n", - "\n", - "\tattachments = [], \n", - "\n", - "\tlinked_kitems = [\n", - "\t\t\n", - "\t\t\tid: b77d1d0c-1c30-483c-bb3c-bddbcf3707b7\n", - "\t\t\tname: Research Institute ABC\n", - "\t\t\tslug: researchinstituteabc-b77d1d0c\n", - "\t\t\tktype_id: organization\n", - "\t\t\tsummary: None\n", - "\t\t\tavatar_exists: False\n", - "\t\t\tannotations: [{\n", - "\t\t\tiri: www.researchBACiri.org/foo,\n", - "\t\t\tname: foo,\n", - "\t\t\tnamespace: www.researchBACiri.org,\n", - "\t\t\tdescription: None\n", - "\t\t}]\n", - "\t\t\tlinked_kitems: [{\n", - "\t\t\tid: 1d2c5439-1971-4a92-907b-e30ce00da344\n", - "\t\t}, {\n", - "\t\t\tid: 63c045bd-e0d5-429c-ad92-39e7e778c9a9\n", - "\t\t}]\n", - "\t\t\texternal_links: []\n", - "\t\t\tcontacts: []\n", - "\t\t\tauthors: [{\n", - "\t\t\tuser_id: 7f0e5a37-353b-4bbc-b1f1-b6ad575f562d\n", - "\t\t}]\n", - "\t\t\tlinked_affiliations: []\n", - "\t\t\tattachments: []\n", - "\t\t\tuser_groups: []\n", - "\t\t\tcustom_properties: None\n", - "\t\t\tcreated_at: 2024-09-26T14:42:49.728733\n", - "\t\t\tupdated_at: 2024-09-26T14:42:49.728733\n", - "\t\t, \n", - "\t\t\n", - "\t\t\tid: d68f1a4c-0da4-454b-aaa5-3c927e690c0d\n", - "\t\t\tname: Specimen-1\n", - "\t\t\tslug: specimen-1-d68f1a4c\n", - "\t\t\tktype_id: specimen\n", - "\t\t\tsummary: None\n", - "\t\t\tavatar_exists: False\n", - "\t\t\tannotations: [{\n", - "\t\t\tiri: https://w3id.org/steel/ProcessOntology/TestPiece,\n", - "\t\t\tname: TestPiece,\n", - "\t\t\tnamespace: https://w3id.org/steel/ProcessOntology,\n", - "\t\t\tdescription: None\n", - "\t\t}]\n", - "\t\t\tlinked_kitems: [{\n", - "\t\t\tid: 1d2c5439-1971-4a92-907b-e30ce00da344\n", - "\t\t}]\n", - "\t\t\texternal_links: []\n", - "\t\t\tcontacts: []\n", - "\t\t\tauthors: [{\n", - "\t\t\tuser_id: 7f0e5a37-353b-4bbc-b1f1-b6ad575f562d\n", - "\t\t}]\n", - "\t\t\tlinked_affiliations: []\n", - "\t\t\tattachments: []\n", - "\t\t\tuser_groups: []\n", - "\t\t\tcustom_properties: {'sampletype': None, 'sampleinformation': None, 'sampleproductionprocess': None, 'Geometry': 'Cylindrical 150mm x 20mm x 40mm', 'Material': 'Concrete', 'Project ID': 'ConstructionProject2024'}\n", - "\t\t\tcreated_at: 2024-09-26T14:42:48.908560\n", - "\t\t\tupdated_at: 2024-09-26T14:42:48.908560\n", - "\t\t\n", - "\t], \n", - "\n", - "\taffiliations = [], \n", - "\n", - "\tauthors = [\n", - "\t\t{\n", - "\t\t\tuser_id: 7f0e5a37-353b-4bbc-b1f1-b6ad575f562d\n", - "\t\t}\n", - "\t], \n", - "\n", - "\tavatar_exists = False, \n", - "\n", - "\tcontacts = [], \n", - "\n", - "\tcreated_at = 2024-09-26 14:42:48.010709, \n", - "\n", - "\tupdated_at = 2024-09-26 14:42:48.010709, \n", - "\n", - "\texternal_links = [], \n", - "\n", - "\tkitem_apps = [], \n", - "\n", - "\tsummary = None, \n", - "\n", - "\tuser_groups = [], \n", - "\n", - "\tcustom_properties = {\n", - "\t\tProducer: TestingLab GmBH, \n", - "\t\tRoom Number: A404, \n", - "\t\tDescription: Bending Test Machine\n", - "\t}, \n", - "\n", - "\tdataframe = None, \n", - "\n", - "\trdf_exists = False\n", - ")\n", - "\n", - "\n" - ] - } - ], - "source": [ - "for result in dsms.search(ktypes=[dsms.ktypes.TestingMachine], limit=1):\n", - " print(result.hit)\n", - " print(\"\\n\")" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "... and for all of type `Organization` and `DatasetCatalog`:" - ] - }, - { - "cell_type": "code", - "execution_count": 5, - "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "KItem(\n", - "\n", - "\tname = Research Institute ABC, \n", - "\n", - "\tid = f61b851e-9a5c-456e-b486-488d3d32bd8e, \n", - "\n", - "\tktype_id = organization, \n", - "\n", - "\tin_backend = True, \n", - "\n", - "\tslug = researchinstituteabc-f61b851e, \n", - "\n", - "\tannotations = [\n", - "\t\t{\n", - "\t\t\tiri: www.researchBACiri.org/foo,\n", - "\t\t\tname: foo,\n", - "\t\t\tnamespace: www.researchBACiri.org,\n", - "\t\t\tdescription: None\n", - "\t\t}\n", - "\t], \n", - "\n", - "\tattachments = [], \n", - "\n", - "\tlinked_kitems = [\n", - "\t\t\n", - "\t\t\tid: 5f93eca8-e076-4d7c-b5fa-57cb226d7aa1\n", - "\t\t\tname: Machine-2\n", - "\t\t\tslug: machine-2-5f93eca8\n", - "\t\t\tktype_id: testing-machine\n", - "\t\t\tsummary: None\n", - "\t\t\tavatar_exists: False\n", - "\t\t\tannotations: [{\n", - "\t\t\tiri: https://w3id.org/steel/ProcessOntology/TestingMachine,\n", - "\t\t\tname: TestingMachine,\n", - "\t\t\tnamespace: https://w3id.org/steel/ProcessOntology,\n", - "\t\t\tdescription: None\n", - "\t\t}]\n", - "\t\t\tlinked_kitems: [{\n", - "\t\t\tid: f61b851e-9a5c-456e-b486-488d3d32bd8e\n", - "\t\t}, {\n", - "\t\t\tid: ff58c3ac-9f7d-4aa2-8fc1-9524f324f598\n", - "\t\t}]\n", - "\t\t\texternal_links: []\n", - "\t\t\tcontacts: []\n", - "\t\t\tauthors: [{\n", - "\t\t\tuser_id: 7f0e5a37-353b-4bbc-b1f1-b6ad575f562d\n", - "\t\t}]\n", - "\t\t\tlinked_affiliations: []\n", - "\t\t\tattachments: []\n", - "\t\t\tuser_groups: []\n", - "\t\t\tcustom_properties: {'Producer': 'StressStrain GmBH', 'Room Number': 'B500', 'Description': 'Compression Test Machine'}\n", - "\t\t\tcreated_at: 2024-09-26T14:38:14.079698\n", - "\t\t\tupdated_at: 2024-09-26T14:38:14.079698\n", - "\t\t, \n", - "\t\t\n", - "\t\t\tid: e32870cb-1686-4d76-a51e-7692568c1dc0\n", - "\t\t\tname: Machine-1\n", - "\t\t\tslug: machine-1-e32870cb\n", - "\t\t\tktype_id: testing-machine\n", - "\t\t\tsummary: None\n", - "\t\t\tavatar_exists: False\n", - "\t\t\tannotations: [{\n", - "\t\t\tiri: https://w3id.org/steel/ProcessOntology/TestingMachine,\n", - "\t\t\tname: TestingMachine,\n", - "\t\t\tnamespace: https://w3id.org/steel/ProcessOntology,\n", - "\t\t\tdescription: None\n", - "\t\t}]\n", - "\t\t\tlinked_kitems: [{\n", - "\t\t\tid: 43a67f5a-fd31-4a39-9697-bfc39aa852b2\n", - "\t\t}, {\n", - "\t\t\tid: f61b851e-9a5c-456e-b486-488d3d32bd8e\n", - "\t\t}]\n", - "\t\t\texternal_links: []\n", - "\t\t\tcontacts: []\n", - "\t\t\tauthors: [{\n", - "\t\t\tuser_id: 7f0e5a37-353b-4bbc-b1f1-b6ad575f562d\n", - "\t\t}]\n", - "\t\t\tlinked_affiliations: []\n", - "\t\t\tattachments: []\n", - "\t\t\tuser_groups: []\n", - "\t\t\tcustom_properties: {'Producer': 'TestingLab GmBH', 'Room Number': 'A404', 'Description': 'Bending Test Machine'}\n", - "\t\t\tcreated_at: 2024-09-26T14:38:13.645998\n", - "\t\t\tupdated_at: 2024-09-26T14:38:13.645998\n", - "\t\t\n", - "\t], \n", - "\n", - "\taffiliations = [], \n", - "\n", - "\tauthors = [\n", - "\t\t{\n", - "\t\t\tuser_id: 7f0e5a37-353b-4bbc-b1f1-b6ad575f562d\n", - "\t\t}\n", - "\t], \n", - "\n", - "\tavatar_exists = False, \n", - "\n", - "\tcontacts = [], \n", - "\n", - "\tcreated_at = 2024-09-26 14:38:15.465213, \n", - "\n", - "\tupdated_at = 2024-09-26 14:38:15.465213, \n", - "\n", - "\texternal_links = [], \n", - "\n", - "\tkitem_apps = [], \n", - "\n", - "\tsummary = None, \n", - "\n", - "\tuser_groups = [], \n", - "\n", - "\tcustom_properties = None, \n", - "\n", - "\tdataframe = None, \n", - "\n", - "\trdf_exists = False\n", - ")\n", - "fuzziness: False\n", - "\n", - "\n" - ] - } - ], - "source": [ - "for result in dsms.search(ktypes=[dsms.ktypes.Organization, dsms.ktypes.DatasetCatalog], limit=1):\n", - " print(result.hit)\n", - " print(\"fuzziness: \", result.fuzzy)\n", - " print(\"\\n\")\n", - " " - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "... or for all of type `Dataset` with `Specimen-1` in the name:" - ] - }, - { - "cell_type": "code", - "execution_count": 6, - "metadata": {}, - "outputs": [], - "source": [ - "for result in dsms.search(query=\"Specimen-1\", ktypes=[dsms.ktypes.Dataset], limit=1):\n", - " print(result.hit)\n", - " print(\"\\n\")" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "... and for all of type `Organization` with the annotation `www.researchBACiri.org/foo`:" - ] - }, - { - "cell_type": "code", - "execution_count": 7, - "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "KItem(\n", - "\n", - "\tname = Research Institute ABC, \n", - "\n", - "\tid = 7b58fc00-bdb3-4584-a86b-b8f447189429, \n", - "\n", - "\tktype_id = organization, \n", - "\n", - "\tin_backend = True, \n", - "\n", - "\tslug = researchinstituteabc-7b58fc00, \n", - "\n", - "\tannotations = [\n", - "\t\t{\n", - "\t\t\tiri: www.researchBACiri.org/foo,\n", - "\t\t\tname: foo,\n", - "\t\t\tnamespace: www.researchBACiri.org,\n", - "\t\t\tdescription: None\n", - "\t\t}\n", - "\t], \n", - "\n", - "\tattachments = [], \n", - "\n", - "\tlinked_kitems = [\n", - "\t\t\n", - "\t\t\tid: 6dd446f1-cc37-462b-83d5-cc55d46d57b1\n", - "\t\t\tname: Machine-1\n", - "\t\t\tslug: machine-1-6dd446f1\n", - "\t\t\tktype_id: testing-machine\n", - "\t\t\tsummary: None\n", - "\t\t\tavatar_exists: False\n", - "\t\t\tannotations: [{\n", - "\t\t\tiri: https://w3id.org/steel/ProcessOntology/TestingMachine,\n", - "\t\t\tname: TestingMachine,\n", - "\t\t\tnamespace: https://w3id.org/steel/ProcessOntology,\n", - "\t\t\tdescription: None\n", - "\t\t}]\n", - "\t\t\tlinked_kitems: [{\n", - "\t\t\tid: 7b58fc00-bdb3-4584-a86b-b8f447189429\n", - "\t\t}, {\n", - "\t\t\tid: e6ef3088-bb47-471b-bd31-ffb1b06cd184\n", - "\t\t}]\n", - "\t\t\texternal_links: []\n", - "\t\t\tcontacts: []\n", - "\t\t\tauthors: [{\n", - "\t\t\tuser_id: 7f0e5a37-353b-4bbc-b1f1-b6ad575f562d\n", - "\t\t}]\n", - "\t\t\tlinked_affiliations: []\n", - "\t\t\tattachments: []\n", - "\t\t\tuser_groups: []\n", - "\t\t\tcustom_properties: {'Producer': 'TestingLab GmBH', 'Room Number': 'A404', 'Description': 'Bending Test Machine'}\n", - "\t\t\tcreated_at: 2024-09-26T14:44:24.055330\n", - "\t\t\tupdated_at: 2024-09-26T14:44:24.055330\n", - "\t\t, \n", - "\t\t\n", - "\t\t\tid: fd1a2a9a-7353-476c-a8b5-19fe6e6d75e1\n", - "\t\t\tname: Machine-2\n", - "\t\t\tslug: machine-2-fd1a2a9a\n", - "\t\t\tktype_id: testing-machine\n", - "\t\t\tsummary: None\n", - "\t\t\tavatar_exists: False\n", - "\t\t\tannotations: [{\n", - "\t\t\tiri: https://w3id.org/steel/ProcessOntology/TestingMachine,\n", - "\t\t\tname: TestingMachine,\n", - "\t\t\tnamespace: https://w3id.org/steel/ProcessOntology,\n", - "\t\t\tdescription: None\n", - "\t\t}]\n", - "\t\t\tlinked_kitems: [{\n", - "\t\t\tid: 7b58fc00-bdb3-4584-a86b-b8f447189429\n", - "\t\t}, {\n", - "\t\t\tid: b15bc4c8-0180-43ce-8d73-c38e7d9f4aae\n", - "\t\t}]\n", - "\t\t\texternal_links: []\n", - "\t\t\tcontacts: []\n", - "\t\t\tauthors: [{\n", - "\t\t\tuser_id: 7f0e5a37-353b-4bbc-b1f1-b6ad575f562d\n", - "\t\t}]\n", - "\t\t\tlinked_affiliations: []\n", - "\t\t\tattachments: []\n", - "\t\t\tuser_groups: []\n", - "\t\t\tcustom_properties: {'Producer': 'StressStrain GmBH', 'Room Number': 'B500', 'Description': 'Compression Test Machine'}\n", - "\t\t\tcreated_at: 2024-09-26T14:44:24.494230\n", - "\t\t\tupdated_at: 2024-09-26T14:44:24.494230\n", - "\t\t\n", - "\t], \n", - "\n", - "\taffiliations = [], \n", - "\n", - "\tauthors = [\n", - "\t\t{\n", - "\t\t\tuser_id: 7f0e5a37-353b-4bbc-b1f1-b6ad575f562d\n", - "\t\t}\n", - "\t], \n", - "\n", - "\tavatar_exists = False, \n", - "\n", - "\tcontacts = [], \n", - "\n", - "\tcreated_at = 2024-09-26 14:44:25.705701, \n", - "\n", - "\tupdated_at = 2024-09-26 14:44:25.705701, \n", - "\n", - "\texternal_links = [], \n", - "\n", - "\tkitem_apps = [], \n", - "\n", - "\tsummary = None, \n", - "\n", - "\tuser_groups = [], \n", - "\n", - "\tcustom_properties = None, \n", - "\n", - "\tdataframe = None, \n", - "\n", - "\trdf_exists = False\n", - ")\n", - "\n", - "\n" - ] - } - ], - "source": [ - "for result in dsms.search(\n", - " ktypes=[dsms.ktypes.Organization], annotations=[\"www.researchBACiri.org/foo\"], limit=1\n", - " ):\n", - " print(result.hit)\n", - " print(\"\\n\")" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "## 5.3. Fetching linked KItems from a KItem" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "In the beginning under **5.1** we created some kitems and linked each other. Now we want to fetch the linked kitems and display them to the user. For this we use the `linked_kitems` attribute." - ] - }, - { - "cell_type": "code", - "execution_count": 8, - "metadata": {}, - "outputs": [ - { - "data": { - "text/plain": [ - "[\n", - "\t\t\n", - "\t\t\tid: 6dd446f1-cc37-462b-83d5-cc55d46d57b1\n", - "\t\t\tname: Machine-1\n", - "\t\t\tslug: machine-1-6dd446f1\n", - "\t\t\tktype_id: testing-machine\n", - "\t\t\tsummary: None\n", - "\t\t\tavatar_exists: False\n", - "\t\t\tannotations: [{\n", - "\t\t\tiri: https://w3id.org/steel/ProcessOntology/TestingMachine,\n", - "\t\t\tname: TestingMachine,\n", - "\t\t\tnamespace: https://w3id.org/steel/ProcessOntology,\n", - "\t\t\tdescription: None\n", - "\t\t}]\n", - "\t\t\tlinked_kitems: [{\n", - "\t\t\tid: 7b58fc00-bdb3-4584-a86b-b8f447189429\n", - "\t\t}, {\n", - "\t\t\tid: e6ef3088-bb47-471b-bd31-ffb1b06cd184\n", - "\t\t}]\n", - "\t\t\texternal_links: []\n", - "\t\t\tcontacts: []\n", - "\t\t\tauthors: [{\n", - "\t\t\tuser_id: 7f0e5a37-353b-4bbc-b1f1-b6ad575f562d\n", - "\t\t}]\n", - "\t\t\tlinked_affiliations: []\n", - "\t\t\tattachments: []\n", - "\t\t\tuser_groups: []\n", - "\t\t\tcustom_properties: {'Producer': 'TestingLab GmBH', 'Room Number': 'A404', 'Description': 'Bending Test Machine'}\n", - "\t\t\tcreated_at: 2024-09-26T14:44:24.055330\n", - "\t\t\tupdated_at: 2024-09-26T14:44:24.055330\n", - "\t\t, \n", - "\t\t\n", - "\t\t\tid: fd1a2a9a-7353-476c-a8b5-19fe6e6d75e1\n", - "\t\t\tname: Machine-2\n", - "\t\t\tslug: machine-2-fd1a2a9a\n", - "\t\t\tktype_id: testing-machine\n", - "\t\t\tsummary: None\n", - "\t\t\tavatar_exists: False\n", - "\t\t\tannotations: [{\n", - "\t\t\tiri: https://w3id.org/steel/ProcessOntology/TestingMachine,\n", - "\t\t\tname: TestingMachine,\n", - "\t\t\tnamespace: https://w3id.org/steel/ProcessOntology,\n", - "\t\t\tdescription: None\n", - "\t\t}]\n", - "\t\t\tlinked_kitems: [{\n", - "\t\t\tid: 7b58fc00-bdb3-4584-a86b-b8f447189429\n", - "\t\t}, {\n", - "\t\t\tid: b15bc4c8-0180-43ce-8d73-c38e7d9f4aae\n", - "\t\t}]\n", - "\t\t\texternal_links: []\n", - "\t\t\tcontacts: []\n", - "\t\t\tauthors: [{\n", - "\t\t\tuser_id: 7f0e5a37-353b-4bbc-b1f1-b6ad575f562d\n", - "\t\t}]\n", - "\t\t\tlinked_affiliations: []\n", - "\t\t\tattachments: []\n", - "\t\t\tuser_groups: []\n", - "\t\t\tcustom_properties: {'Producer': 'StressStrain GmBH', 'Room Number': 'B500', 'Description': 'Compression Test Machine'}\n", - "\t\t\tcreated_at: 2024-09-26T14:44:24.494230\n", - "\t\t\tupdated_at: 2024-09-26T14:44:24.494230\n", - "\t\t\n", - "\t]" - ] - }, - "execution_count": 8, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "item5.linked_kitems" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "However, this linked KItem is not a \"real\" KItem. Due to performance reasons, we only display a slim representation of the linked KItem. Imagine if the linked KItem also has a linked KItem... this might lead to an infinite recursion. We can fetch the \"real\" KItem by using the `fetch` method of the linked KItem:\n" - ] - }, - { - "cell_type": "code", - "execution_count": 9, - "metadata": {}, - "outputs": [ - { - "data": { - "text/plain": [ - "KItem(\n", - "\n", - "\tname = Machine-1, \n", - "\n", - "\tid = 6dd446f1-cc37-462b-83d5-cc55d46d57b1, \n", - "\n", - "\tktype_id = testing-machine, \n", - "\n", - "\tin_backend = True, \n", - "\n", - "\tslug = machine-1-6dd446f1, \n", - "\n", - "\tannotations = [\n", - "\t\t{\n", - "\t\t\tiri: https://w3id.org/steel/ProcessOntology/TestingMachine,\n", - "\t\t\tname: TestingMachine,\n", - "\t\t\tnamespace: https://w3id.org/steel/ProcessOntology,\n", - "\t\t\tdescription: None\n", - "\t\t}\n", - "\t], \n", - "\n", - "\tattachments = [], \n", - "\n", - "\tlinked_kitems = [\n", - "\t\t\n", - "\t\t\tid: 7b58fc00-bdb3-4584-a86b-b8f447189429\n", - "\t\t\tname: Research Institute ABC\n", - "\t\t\tslug: researchinstituteabc-7b58fc00\n", - "\t\t\tktype_id: organization\n", - "\t\t\tsummary: None\n", - "\t\t\tavatar_exists: False\n", - "\t\t\tannotations: [{\n", - "\t\t\tiri: www.researchBACiri.org/foo,\n", - "\t\t\tname: foo,\n", - "\t\t\tnamespace: www.researchBACiri.org,\n", - "\t\t\tdescription: None\n", - "\t\t}]\n", - "\t\t\tlinked_kitems: [{\n", - "\t\t\tid: 6dd446f1-cc37-462b-83d5-cc55d46d57b1\n", - "\t\t}, {\n", - "\t\t\tid: fd1a2a9a-7353-476c-a8b5-19fe6e6d75e1\n", - "\t\t}]\n", - "\t\t\texternal_links: []\n", - "\t\t\tcontacts: []\n", - "\t\t\tauthors: [{\n", - "\t\t\tuser_id: 7f0e5a37-353b-4bbc-b1f1-b6ad575f562d\n", - "\t\t}]\n", - "\t\t\tlinked_affiliations: []\n", - "\t\t\tattachments: []\n", - "\t\t\tuser_groups: []\n", - "\t\t\tcustom_properties: None\n", - "\t\t\tcreated_at: 2024-09-26T14:44:25.705701\n", - "\t\t\tupdated_at: 2024-09-26T14:44:25.705701\n", - "\t\t, \n", - "\t\t\n", - "\t\t\tid: e6ef3088-bb47-471b-bd31-ffb1b06cd184\n", - "\t\t\tname: Specimen-1\n", - "\t\t\tslug: specimen-1-e6ef3088\n", - "\t\t\tktype_id: specimen\n", - "\t\t\tsummary: None\n", - "\t\t\tavatar_exists: False\n", - "\t\t\tannotations: [{\n", - "\t\t\tiri: https://w3id.org/steel/ProcessOntology/TestPiece,\n", - "\t\t\tname: TestPiece,\n", - "\t\t\tnamespace: https://w3id.org/steel/ProcessOntology,\n", - "\t\t\tdescription: None\n", - "\t\t}]\n", - "\t\t\tlinked_kitems: [{\n", - "\t\t\tid: 6dd446f1-cc37-462b-83d5-cc55d46d57b1\n", - "\t\t}]\n", - "\t\t\texternal_links: []\n", - "\t\t\tcontacts: []\n", - "\t\t\tauthors: [{\n", - "\t\t\tuser_id: 7f0e5a37-353b-4bbc-b1f1-b6ad575f562d\n", - "\t\t}]\n", - "\t\t\tlinked_affiliations: []\n", - "\t\t\tattachments: []\n", - "\t\t\tuser_groups: []\n", - "\t\t\tcustom_properties: {'sampletype': None, 'sampleinformation': None, 'sampleproductionprocess': None, 'Geometry': 'Cylindrical 150mm x 20mm x 40mm', 'Material': 'Concrete', 'Project ID': 'ConstructionProject2024'}\n", - "\t\t\tcreated_at: 2024-09-26T14:44:24.894772\n", - "\t\t\tupdated_at: 2024-09-26T14:44:24.894772\n", - "\t\t\n", - "\t], \n", - "\n", - "\taffiliations = [], \n", - "\n", - "\tauthors = [\n", - "\t\t{\n", - "\t\t\tuser_id: 7f0e5a37-353b-4bbc-b1f1-b6ad575f562d\n", - "\t\t}\n", - "\t], \n", - "\n", - "\tavatar_exists = False, \n", - "\n", - "\tcontacts = [], \n", - "\n", - "\tcreated_at = 2024-09-26 14:44:24.055330, \n", - "\n", - "\tupdated_at = 2024-09-26 14:44:24.055330, \n", - "\n", - "\texternal_links = [], \n", - "\n", - "\tkitem_apps = [], \n", - "\n", - "\tsummary = None, \n", - "\n", - "\tuser_groups = [], \n", - "\n", - "\tcustom_properties = {\n", - "\t\tProducer: TestingLab GmBH, \n", - "\t\tRoom Number: A404, \n", - "\t\tDescription: Bending Test Machine\n", - "\t}, \n", - "\n", - "\tdataframe = None, \n", - "\n", - "\trdf_exists = False\n", - ")" - ] - }, - "execution_count": 9, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "item5.linked_kitems[0].fetch()" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "We can also get the linked KItems grouped by annotation:" - ] - }, - { - "cell_type": "code", - "execution_count": 10, - "metadata": {}, - "outputs": [ - { - "data": { - "text/plain": [ - "{'https://w3id.org/steel/ProcessOntology/TestingMachine': [\n", - " \t\t\tid: 6dd446f1-cc37-462b-83d5-cc55d46d57b1\n", - " \t\t\tname: Machine-1\n", - " \t\t\tslug: machine-1-6dd446f1\n", - " \t\t\tktype_id: testing-machine\n", - " \t\t\tsummary: None\n", - " \t\t\tavatar_exists: False\n", - " \t\t\tannotations: [{\n", - " \t\t\tiri: https://w3id.org/steel/ProcessOntology/TestingMachine,\n", - " \t\t\tname: TestingMachine,\n", - " \t\t\tnamespace: https://w3id.org/steel/ProcessOntology,\n", - " \t\t\tdescription: None\n", - " \t\t}]\n", - " \t\t\tlinked_kitems: [{\n", - " \t\t\tid: 7b58fc00-bdb3-4584-a86b-b8f447189429\n", - " \t\t}, {\n", - " \t\t\tid: e6ef3088-bb47-471b-bd31-ffb1b06cd184\n", - " \t\t}]\n", - " \t\t\texternal_links: []\n", - " \t\t\tcontacts: []\n", - " \t\t\tauthors: [{\n", - " \t\t\tuser_id: 7f0e5a37-353b-4bbc-b1f1-b6ad575f562d\n", - " \t\t}]\n", - " \t\t\tlinked_affiliations: []\n", - " \t\t\tattachments: []\n", - " \t\t\tuser_groups: []\n", - " \t\t\tcustom_properties: {'Producer': 'TestingLab GmBH', 'Room Number': 'A404', 'Description': 'Bending Test Machine'}\n", - " \t\t\tcreated_at: 2024-09-26T14:44:24.055330\n", - " \t\t\tupdated_at: 2024-09-26T14:44:24.055330\n", - " \t\t,\n", - " \n", - " \t\t\tid: fd1a2a9a-7353-476c-a8b5-19fe6e6d75e1\n", - " \t\t\tname: Machine-2\n", - " \t\t\tslug: machine-2-fd1a2a9a\n", - " \t\t\tktype_id: testing-machine\n", - " \t\t\tsummary: None\n", - " \t\t\tavatar_exists: False\n", - " \t\t\tannotations: [{\n", - " \t\t\tiri: https://w3id.org/steel/ProcessOntology/TestingMachine,\n", - " \t\t\tname: TestingMachine,\n", - " \t\t\tnamespace: https://w3id.org/steel/ProcessOntology,\n", - " \t\t\tdescription: None\n", - " \t\t}]\n", - " \t\t\tlinked_kitems: [{\n", - " \t\t\tid: 7b58fc00-bdb3-4584-a86b-b8f447189429\n", - " \t\t}, {\n", - " \t\t\tid: b15bc4c8-0180-43ce-8d73-c38e7d9f4aae\n", - " \t\t}]\n", - " \t\t\texternal_links: []\n", - " \t\t\tcontacts: []\n", - " \t\t\tauthors: [{\n", - " \t\t\tuser_id: 7f0e5a37-353b-4bbc-b1f1-b6ad575f562d\n", - " \t\t}]\n", - " \t\t\tlinked_affiliations: []\n", - " \t\t\tattachments: []\n", - " \t\t\tuser_groups: []\n", - " \t\t\tcustom_properties: {'Producer': 'StressStrain GmBH', 'Room Number': 'B500', 'Description': 'Compression Test Machine'}\n", - " \t\t\tcreated_at: 2024-09-26T14:44:24.494230\n", - " \t\t\tupdated_at: 2024-09-26T14:44:24.494230\n", - " \t\t]}" - ] - }, - "execution_count": 10, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "item5.linked_kitems.by_annotation" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "Again, we are able to fetch the \"real\" KItem by using the `fetch` method of the linked KItem:" - ] - }, - { - "cell_type": "code", - "execution_count": 11, - "metadata": {}, - "outputs": [ - { - "data": { - "text/plain": [ - "KItem(\n", - "\n", - "\tname = Machine-1, \n", - "\n", - "\tid = 6dd446f1-cc37-462b-83d5-cc55d46d57b1, \n", - "\n", - "\tktype_id = testing-machine, \n", - "\n", - "\tin_backend = True, \n", - "\n", - "\tslug = machine-1-6dd446f1, \n", - "\n", - "\tannotations = [\n", - "\t\t{\n", - "\t\t\tiri: https://w3id.org/steel/ProcessOntology/TestingMachine,\n", - "\t\t\tname: TestingMachine,\n", - "\t\t\tnamespace: https://w3id.org/steel/ProcessOntology,\n", - "\t\t\tdescription: None\n", - "\t\t}\n", - "\t], \n", - "\n", - "\tattachments = [], \n", - "\n", - "\tlinked_kitems = [\n", - "\t\t\n", - "\t\t\tid: 7b58fc00-bdb3-4584-a86b-b8f447189429\n", - "\t\t\tname: Research Institute ABC\n", - "\t\t\tslug: researchinstituteabc-7b58fc00\n", - "\t\t\tktype_id: organization\n", - "\t\t\tsummary: None\n", - "\t\t\tavatar_exists: False\n", - "\t\t\tannotations: [{\n", - "\t\t\tiri: www.researchBACiri.org/foo,\n", - "\t\t\tname: foo,\n", - "\t\t\tnamespace: www.researchBACiri.org,\n", - "\t\t\tdescription: None\n", - "\t\t}]\n", - "\t\t\tlinked_kitems: [{\n", - "\t\t\tid: 6dd446f1-cc37-462b-83d5-cc55d46d57b1\n", - "\t\t}, {\n", - "\t\t\tid: fd1a2a9a-7353-476c-a8b5-19fe6e6d75e1\n", - "\t\t}]\n", - "\t\t\texternal_links: []\n", - "\t\t\tcontacts: []\n", - "\t\t\tauthors: [{\n", - "\t\t\tuser_id: 7f0e5a37-353b-4bbc-b1f1-b6ad575f562d\n", - "\t\t}]\n", - "\t\t\tlinked_affiliations: []\n", - "\t\t\tattachments: []\n", - "\t\t\tuser_groups: []\n", - "\t\t\tcustom_properties: None\n", - "\t\t\tcreated_at: 2024-09-26T14:44:25.705701\n", - "\t\t\tupdated_at: 2024-09-26T14:44:25.705701\n", - "\t\t, \n", - "\t\t\n", - "\t\t\tid: e6ef3088-bb47-471b-bd31-ffb1b06cd184\n", - "\t\t\tname: Specimen-1\n", - "\t\t\tslug: specimen-1-e6ef3088\n", - "\t\t\tktype_id: specimen\n", - "\t\t\tsummary: None\n", - "\t\t\tavatar_exists: False\n", - "\t\t\tannotations: [{\n", - "\t\t\tiri: https://w3id.org/steel/ProcessOntology/TestPiece,\n", - "\t\t\tname: TestPiece,\n", - "\t\t\tnamespace: https://w3id.org/steel/ProcessOntology,\n", - "\t\t\tdescription: None\n", - "\t\t}]\n", - "\t\t\tlinked_kitems: [{\n", - "\t\t\tid: 6dd446f1-cc37-462b-83d5-cc55d46d57b1\n", - "\t\t}]\n", - "\t\t\texternal_links: []\n", - "\t\t\tcontacts: []\n", - "\t\t\tauthors: [{\n", - "\t\t\tuser_id: 7f0e5a37-353b-4bbc-b1f1-b6ad575f562d\n", - "\t\t}]\n", - "\t\t\tlinked_affiliations: []\n", - "\t\t\tattachments: []\n", - "\t\t\tuser_groups: []\n", - "\t\t\tcustom_properties: {'sampletype': None, 'sampleinformation': None, 'sampleproductionprocess': None, 'Geometry': 'Cylindrical 150mm x 20mm x 40mm', 'Material': 'Concrete', 'Project ID': 'ConstructionProject2024'}\n", - "\t\t\tcreated_at: 2024-09-26T14:44:24.894772\n", - "\t\t\tupdated_at: 2024-09-26T14:44:24.894772\n", - "\t\t\n", - "\t], \n", - "\n", - "\taffiliations = [], \n", - "\n", - "\tauthors = [\n", - "\t\t{\n", - "\t\t\tuser_id: 7f0e5a37-353b-4bbc-b1f1-b6ad575f562d\n", - "\t\t}\n", - "\t], \n", - "\n", - "\tavatar_exists = False, \n", - "\n", - "\tcontacts = [], \n", - "\n", - "\tcreated_at = 2024-09-26 14:44:24.055330, \n", - "\n", - "\tupdated_at = 2024-09-26 14:44:24.055330, \n", - "\n", - "\texternal_links = [], \n", - "\n", - "\tkitem_apps = [], \n", - "\n", - "\tsummary = None, \n", - "\n", - "\tuser_groups = [], \n", - "\n", - "\tcustom_properties = {\n", - "\t\tProducer: TestingLab GmBH, \n", - "\t\tRoom Number: A404, \n", - "\t\tDescription: Bending Test Machine\n", - "\t}, \n", - "\n", - "\tdataframe = None, \n", - "\n", - "\trdf_exists = False\n", - ")" - ] - }, - "execution_count": 11, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "item5.linked_kitems.by_annotation[\"https://w3id.org/steel/ProcessOntology/TestingMachine\"][0].fetch()" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "Additionally, we can retrieve the linked KItems grouped by ktype:" - ] - }, - { - "cell_type": "code", - "execution_count": 12, - "metadata": {}, - "outputs": [ - { - "data": { - "text/plain": [ - "{, json_schema=None, rdf_mapping=None, created_at='2024-08-19T17:13:57.534570', updated_at='2024-08-19T18:11:40.465640')>: [\n", - " \t\t\tid: 6dd446f1-cc37-462b-83d5-cc55d46d57b1\n", - " \t\t\tname: Machine-1\n", - " \t\t\tslug: machine-1-6dd446f1\n", - " \t\t\tktype_id: testing-machine\n", - " \t\t\tsummary: None\n", - " \t\t\tavatar_exists: False\n", - " \t\t\tannotations: [{\n", - " \t\t\tiri: https://w3id.org/steel/ProcessOntology/TestingMachine,\n", - " \t\t\tname: TestingMachine,\n", - " \t\t\tnamespace: https://w3id.org/steel/ProcessOntology,\n", - " \t\t\tdescription: None\n", - " \t\t}]\n", - " \t\t\tlinked_kitems: [{\n", - " \t\t\tid: 7b58fc00-bdb3-4584-a86b-b8f447189429\n", - " \t\t}, {\n", - " \t\t\tid: e6ef3088-bb47-471b-bd31-ffb1b06cd184\n", - " \t\t}]\n", - " \t\t\texternal_links: []\n", - " \t\t\tcontacts: []\n", - " \t\t\tauthors: [{\n", - " \t\t\tuser_id: 7f0e5a37-353b-4bbc-b1f1-b6ad575f562d\n", - " \t\t}]\n", - " \t\t\tlinked_affiliations: []\n", - " \t\t\tattachments: []\n", - " \t\t\tuser_groups: []\n", - " \t\t\tcustom_properties: {'Producer': 'TestingLab GmBH', 'Room Number': 'A404', 'Description': 'Bending Test Machine'}\n", - " \t\t\tcreated_at: 2024-09-26T14:44:24.055330\n", - " \t\t\tupdated_at: 2024-09-26T14:44:24.055330\n", - " \t\t,\n", - " \n", - " \t\t\tid: fd1a2a9a-7353-476c-a8b5-19fe6e6d75e1\n", - " \t\t\tname: Machine-2\n", - " \t\t\tslug: machine-2-fd1a2a9a\n", - " \t\t\tktype_id: testing-machine\n", - " \t\t\tsummary: None\n", - " \t\t\tavatar_exists: False\n", - " \t\t\tannotations: [{\n", - " \t\t\tiri: https://w3id.org/steel/ProcessOntology/TestingMachine,\n", - " \t\t\tname: TestingMachine,\n", - " \t\t\tnamespace: https://w3id.org/steel/ProcessOntology,\n", - " \t\t\tdescription: None\n", - " \t\t}]\n", - " \t\t\tlinked_kitems: [{\n", - " \t\t\tid: 7b58fc00-bdb3-4584-a86b-b8f447189429\n", - " \t\t}, {\n", - " \t\t\tid: b15bc4c8-0180-43ce-8d73-c38e7d9f4aae\n", - " \t\t}]\n", - " \t\t\texternal_links: []\n", - " \t\t\tcontacts: []\n", - " \t\t\tauthors: [{\n", - " \t\t\tuser_id: 7f0e5a37-353b-4bbc-b1f1-b6ad575f562d\n", - " \t\t}]\n", - " \t\t\tlinked_affiliations: []\n", - " \t\t\tattachments: []\n", - " \t\t\tuser_groups: []\n", - " \t\t\tcustom_properties: {'Producer': 'StressStrain GmBH', 'Room Number': 'B500', 'Description': 'Compression Test Machine'}\n", - " \t\t\tcreated_at: 2024-09-26T14:44:24.494230\n", - " \t\t\tupdated_at: 2024-09-26T14:44:24.494230\n", - " \t\t]}" - ] - }, - "execution_count": 12, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "item5.linked_kitems.by_ktype" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "... and retrieve them by type:" - ] - }, - { - "cell_type": "code", - "execution_count": 13, - "metadata": {}, - "outputs": [ - { - "data": { - "text/plain": [ - "KItem(\n", - "\n", - "\tname = Machine-1, \n", - "\n", - "\tid = 6dd446f1-cc37-462b-83d5-cc55d46d57b1, \n", - "\n", - "\tktype_id = testing-machine, \n", - "\n", - "\tin_backend = True, \n", - "\n", - "\tslug = machine-1-6dd446f1, \n", - "\n", - "\tannotations = [\n", - "\t\t{\n", - "\t\t\tiri: https://w3id.org/steel/ProcessOntology/TestingMachine,\n", - "\t\t\tname: TestingMachine,\n", - "\t\t\tnamespace: https://w3id.org/steel/ProcessOntology,\n", - "\t\t\tdescription: None\n", - "\t\t}\n", - "\t], \n", - "\n", - "\tattachments = [], \n", - "\n", - "\tlinked_kitems = [\n", - "\t\t\n", - "\t\t\tid: 7b58fc00-bdb3-4584-a86b-b8f447189429\n", - "\t\t\tname: Research Institute ABC\n", - "\t\t\tslug: researchinstituteabc-7b58fc00\n", - "\t\t\tktype_id: organization\n", - "\t\t\tsummary: None\n", - "\t\t\tavatar_exists: False\n", - "\t\t\tannotations: [{\n", - "\t\t\tiri: www.researchBACiri.org/foo,\n", - "\t\t\tname: foo,\n", - "\t\t\tnamespace: www.researchBACiri.org,\n", - "\t\t\tdescription: None\n", - "\t\t}]\n", - "\t\t\tlinked_kitems: [{\n", - "\t\t\tid: 6dd446f1-cc37-462b-83d5-cc55d46d57b1\n", - "\t\t}, {\n", - "\t\t\tid: fd1a2a9a-7353-476c-a8b5-19fe6e6d75e1\n", - "\t\t}]\n", - "\t\t\texternal_links: []\n", - "\t\t\tcontacts: []\n", - "\t\t\tauthors: [{\n", - "\t\t\tuser_id: 7f0e5a37-353b-4bbc-b1f1-b6ad575f562d\n", - "\t\t}]\n", - "\t\t\tlinked_affiliations: []\n", - "\t\t\tattachments: []\n", - "\t\t\tuser_groups: []\n", - "\t\t\tcustom_properties: None\n", - "\t\t\tcreated_at: 2024-09-26T14:44:25.705701\n", - "\t\t\tupdated_at: 2024-09-26T14:44:25.705701\n", - "\t\t, \n", - "\t\t\n", - "\t\t\tid: e6ef3088-bb47-471b-bd31-ffb1b06cd184\n", - "\t\t\tname: Specimen-1\n", - "\t\t\tslug: specimen-1-e6ef3088\n", - "\t\t\tktype_id: specimen\n", - "\t\t\tsummary: None\n", - "\t\t\tavatar_exists: False\n", - "\t\t\tannotations: [{\n", - "\t\t\tiri: https://w3id.org/steel/ProcessOntology/TestPiece,\n", - "\t\t\tname: TestPiece,\n", - "\t\t\tnamespace: https://w3id.org/steel/ProcessOntology,\n", - "\t\t\tdescription: None\n", - "\t\t}]\n", - "\t\t\tlinked_kitems: [{\n", - "\t\t\tid: 6dd446f1-cc37-462b-83d5-cc55d46d57b1\n", - "\t\t}]\n", - "\t\t\texternal_links: []\n", - "\t\t\tcontacts: []\n", - "\t\t\tauthors: [{\n", - "\t\t\tuser_id: 7f0e5a37-353b-4bbc-b1f1-b6ad575f562d\n", - "\t\t}]\n", - "\t\t\tlinked_affiliations: []\n", - "\t\t\tattachments: []\n", - "\t\t\tuser_groups: []\n", - "\t\t\tcustom_properties: {'sampletype': None, 'sampleinformation': None, 'sampleproductionprocess': None, 'Geometry': 'Cylindrical 150mm x 20mm x 40mm', 'Material': 'Concrete', 'Project ID': 'ConstructionProject2024'}\n", - "\t\t\tcreated_at: 2024-09-26T14:44:24.894772\n", - "\t\t\tupdated_at: 2024-09-26T14:44:24.894772\n", - "\t\t\n", - "\t], \n", - "\n", - "\taffiliations = [], \n", - "\n", - "\tauthors = [\n", - "\t\t{\n", - "\t\t\tuser_id: 7f0e5a37-353b-4bbc-b1f1-b6ad575f562d\n", - "\t\t}\n", - "\t], \n", - "\n", - "\tavatar_exists = False, \n", - "\n", - "\tcontacts = [], \n", - "\n", - "\tcreated_at = 2024-09-26 14:44:24.055330, \n", - "\n", - "\tupdated_at = 2024-09-26 14:44:24.055330, \n", - "\n", - "\texternal_links = [], \n", - "\n", - "\tkitem_apps = [], \n", - "\n", - "\tsummary = None, \n", - "\n", - "\tuser_groups = [], \n", - "\n", - "\tcustom_properties = {\n", - "\t\tProducer: TestingLab GmBH, \n", - "\t\tRoom Number: A404, \n", - "\t\tDescription: Bending Test Machine\n", - "\t}, \n", - "\n", - "\tdataframe = None, \n", - "\n", - "\trdf_exists = False\n", - ")" - ] - }, - "execution_count": 13, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "item5.linked_kitems.by_ktype[dsms.ktypes.TestingMachine][0].fetch()" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "Clean up the DSMS from the tutortial:" - ] - }, - { - "cell_type": "code", - "execution_count": 14, - "metadata": {}, - "outputs": [], - "source": [ - "del dsms[item1]\n", - "del dsms[item2]\n", - "del dsms[item3]\n", - "del dsms[item4]\n", - "del dsms[item5]\n", - "\n", - "dsms.commit()" - ] - } - ], - "metadata": { - "kernelspec": { - "display_name": "sdk", - "language": "python", - "name": "python3" - }, - "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.12.2" - } - }, - "nbformat": 4, - "nbformat_minor": 2 -} diff --git a/examples/tutorials/6_apps.ipynb b/examples/tutorials/6_apps.ipynb deleted file mode 100644 index b658a96..0000000 --- a/examples/tutorials/6_apps.ipynb +++ /dev/null @@ -1,1031 +0,0 @@ -{ - "cells": [ - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "# 6. DSMS Apps and Pipelines\n", - "\n", - "In this tutorial we see how to create apps and run them manually" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "### 6.1: Setting up\n" - ] - }, - { - "cell_type": "code", - "execution_count": 1, - "metadata": {}, - "outputs": [], - "source": [ - "from dsms import DSMS, KItem, AppConfig\n", - "import time" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "Now source the environmental variables from an `.env` file and start the DSMS-session." - ] - }, - { - "cell_type": "code", - "execution_count": 2, - "metadata": {}, - "outputs": [], - "source": [ - "dsms = DSMS(env=\"../../.env\")" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "### 6.1. Investigating Available Apps" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "We can investigate which apps are available:" - ] - }, - { - "cell_type": "code", - "execution_count": 3, - "metadata": {}, - "outputs": [ - { - "data": { - "text/plain": [ - "[AppConfig(name=ckan-fetch, specification={'metadata': {'generateName': 'ckan-resource-request-'}}),\n", - " AppConfig(name=csv_tensile_test, specification={'metadata': {'generateName': 'data2rdf-'}}),\n", - " AppConfig(name=csv_tensile_test_f2, specification={'metadata': {'generateName': 'data2rdf-'}}),\n", - " AppConfig(name=excel_notched_tensile_test, specification={'metadata': {'generateName': 'data2rdf-'}}),\n", - " AppConfig(name=excel_shear_test, specification={'metadata': {'generateName': 'data2rdf-'}}),\n", - " AppConfig(name=excel_tensile_test, specification={'metadata': {'generateName': 'data2rdf-'}}),\n", - " AppConfig(name=ternary-plot, specification={'metadata': {'generateName': 'ckan-tenary-app-'}})]" - ] - }, - "execution_count": 3, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "dsms.app_configs" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "### 6.2 Create a new app config and apply it to a KItem" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "### 6.2.1 Arbitrary python code" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "To be defined." - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "### 6.2.2 - Data2RDF" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "#### 6.2.2.1 Prepare app and its config" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "In the following example, we would like to upload some csv with some arbitrary data and describe it through an RDF. This will give us the opportunity to harmonize the entities of the data file through ontological concepts and allow us to convert values of the data frame columns in to any compatible unit we would like to have.\n", - "\n", - "Fist of all, let us define the data:" - ] - }, - { - "cell_type": "code", - "execution_count": 4, - "metadata": {}, - "outputs": [], - "source": [ - "data = \"\"\"A,B,C\n", - "1.2,1.3,1.5\n", - "1.7,1.8,1.9\n", - "2.0,2.1,2.3\n", - "2.5,2.6,2.8\n", - "3.0,3.2,3.4\n", - "3.6,3.7,3.9\n", - "4.1,4.3,4.4\n", - "4.7,4.8,5.0\n", - "5.2,5.3,5.5\n", - "5.8,6.0,6.1\n", - "\"\"\"" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "We will also give the config a defined name:" - ] - }, - { - "cell_type": "code", - "execution_count": 5, - "metadata": {}, - "outputs": [], - "source": [ - "configname = \"testapp2\"" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "As a next step, we want to create a new app specification. The specification is following the definition of an [**Argo Workflow**](https://argo-workflows.readthedocs.io/en/latest/). The workflow shall trigger a pipeline from a docker image with the [**Data2RDF package**](https://data2rdf.readthedocs.io/en/latest/). \n", - "\n", - "The image has already been deployed on the k8s cluster of the DSMS and the workflow template with the name `dsms-data2rdf` has been implemented previously. Hence we only need to configure our pipeline for our data shown above, which we would like to upload and describe through an RDF.\n", - "\n", - "For more details about the data2rdf package, please refer to the documentation of Data2RDF mentioned above.\n", - "\n", - "The parameters of the app config are defining the inputs for our Data2RDF pipeline. This e.g. are: \n", - "\n", - "* the parser kind (`csv` here)\n", - "* the time series header length (`1` here)\n", - "* the metadata length (`0` here)\n", - "* the time series separator (`,` here)\n", - "* the log level (`DEBUG` here)\n", - "* the mapping \n", - " * `A` is the test time and has a unit in seconds\n", - " * `B` is the standard force in kilonewtons\n", - " * `C` is the absolut cross head travel in millimeters" - ] - }, - { - "cell_type": "code", - "execution_count": 6, - "metadata": {}, - "outputs": [], - "source": [ - "parameters = [\n", - " {\"name\": \"parser\", \"value\": \"csv\"},\n", - " {\"name\": \"time_series_header_length\", \"value\": 1},\n", - " {\"name\": \"metadata_length\", \"value\": 0},\n", - " {\"name\": \"time_series_sep\", \"value\": \",\"},\n", - " {\"name\": \"log_level\", \"value\": \"DEBUG\"},\n", - " {\n", - " \"name\": \"mapping\",\n", - " \"value\": \"\"\"\n", - " [\n", - " {\n", - " \"key\": \"A\",\n", - " \"iri\": \"https://w3id.org/steel/ProcessOntology/TestTime\",\n", - " \"unit\": \"s\"\n", - " },\n", - " {\n", - " \"key\": \"B\",\n", - " \"iri\": \"https://w3id.org/steel/ProcessOntology/StandardForce\",\n", - " \"unit\": \"kN\"\n", - " },\n", - " {\n", - " \"key\": \"C\",\n", - " \"iri\": \"https://w3id.org/steel/ProcessOntology/AbsoluteCrossheadTravel\",\n", - " \"unit\": \"mm\"\n", - " }\n", - " ]\n", - " \"\"\",\n", - " },\n", - "]" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "Now we add the parameters to our app specification. We assign a prefix `datardf-` which shall generate a new name with some random characters as suffix. The workflow template with the Docker image we want to run is called `dsms-data2rdf` and its `entrypoint` is `execute_pipeline`." - ] - }, - { - "cell_type": "code", - "execution_count": 7, - "metadata": {}, - "outputs": [], - "source": [ - "# Define app specification\n", - "specification = {\n", - " \"apiVersion\": \"argoproj.io/v1alpha1\",\n", - " \"kind\": \"Workflow\",\n", - " \"metadata\": {\"generateName\": \"data2rdf-\"},\n", - " \"spec\": {\n", - " \"entrypoint\": \"execute_pipeline\",\n", - " \"workflowTemplateRef\": {\"name\": \"dsms-data2rdf\"},\n", - " \"arguments\": {\"parameters\": parameters},\n", - " },\n", - "}" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "Now we instanciate the new app config:" - ] - }, - { - "cell_type": "code", - "execution_count": 8, - "metadata": {}, - "outputs": [], - "source": [ - "appspec = AppConfig(\n", - " name=configname,\n", - " specification=specification, # this can also be a file path to a yaml file instead of a dict\n", - " expose_sdk_config=True,\n", - ")\n" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "Please note that the `expose_sdk_config` is important here, since the pipeline needs to be aware of the settings of our platform and our current SDK-session." - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "We commit the new app config:" - ] - }, - { - "cell_type": "code", - "execution_count": 9, - "metadata": {}, - "outputs": [], - "source": [ - "dsms.commit()" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "Now we would like to apply the app config to a KItem. The set the `triggerUponUpload` must be set to `True` so that the app is triggered automatically when we upload an attachment.\n", - "\n", - "Additionally, we must tell the file extension for which the upload shall be triggered. Here it is `.csv`.\n", - "\n", - "We also want to generate a qr code as avatar for the KItem with `avatar={\"include_qr\": True}`." - ] - }, - { - "cell_type": "code", - "execution_count": 10, - "metadata": {}, - "outputs": [], - "source": [ - "item = KItem(\n", - " name=\"my tensile test experiment\",\n", - " ktype_id=dsms.ktypes.Dataset,\n", - " kitem_apps=[\n", - " {\n", - " \"executable\": appspec.name,\n", - " \"title\": \"data2rdf\",\n", - " \"additional_properties\": {\n", - " \"triggerUponUpload\": True,\n", - " \"triggerUponUploadFileExtensions\": [\".csv\"],\n", - " },\n", - " }\n", - " ],\n", - " avatar={\"include_qr\": True},\n", - ")" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "We commit the KItem:" - ] - }, - { - "cell_type": "code", - "execution_count": 11, - "metadata": {}, - "outputs": [], - "source": [ - "dsms.commit()" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "Now we add our data with our attachment:" - ] - }, - { - "cell_type": "code", - "execution_count": 12, - "metadata": {}, - "outputs": [], - "source": [ - "item.attachments = [{\"name\": \"dummy_data.csv\", \"content\": data}]" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "And we commit again:" - ] - }, - { - "cell_type": "code", - "execution_count": 13, - "metadata": {}, - "outputs": [], - "source": [ - "dsms.commit()" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "#### 6.2.2.2 Get results" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "Now we can verify that the data extraction was successful:" - ] - }, - { - "cell_type": "code", - "execution_count": 14, - "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "KItem(\n", - "\n", - "\tname = my tensile test experiment, \n", - "\n", - "\tid = 58683a2d-7823-4638-bc8e-91b461afa593, \n", - "\n", - "\tktype_id = dataset, \n", - "\n", - "\tin_backend = True, \n", - "\n", - "\tslug = mytensiletestexperiment-58683a2d, \n", - "\n", - "\tannotations = [], \n", - "\n", - "\tattachments = [\n", - "\t\t{\n", - "\t\t\tname: dummy_data.csv\n", - "\t\t}\n", - "\t], \n", - "\n", - "\tlinked_kitems = [], \n", - "\n", - "\taffiliations = [], \n", - "\n", - "\tauthors = [\n", - "\t\t{\n", - "\t\t\tuser_id: 7f0e5a37-353b-4bbc-b1f1-b6ad575f562d\n", - "\t\t}\n", - "\t], \n", - "\n", - "\tavatar_exists = True, \n", - "\n", - "\tcontacts = [], \n", - "\n", - "\tcreated_at = 2024-08-20 08:04:25.756982, \n", - "\n", - "\tupdated_at = 2024-08-20 08:04:25.756982, \n", - "\n", - "\texternal_links = [], \n", - "\n", - "\tkitem_apps = [\n", - "\t\t{\n", - "\t\t\tkitem_app_id: 22,\n", - "\t\t\texecutable: testapp2,\n", - "\t\t\ttitle: data2rdf,\n", - "\t\t\tdescription: None,\n", - "\t\t\ttags: None,\n", - "\t\t\tadditional_properties: {triggerUponUpload: True, triggerUponUploadFileExtensions: ['.csv']}\n", - "\t\t}\n", - "\t], \n", - "\n", - "\tsummary = None, \n", - "\n", - "\tuser_groups = [], \n", - "\n", - "\tcustom_properties = None, \n", - "\n", - "\tdataframe = [\n", - "\t\t{\n", - "\t\t\tcolumn_id: 0,\n", - "\t\t\tname: TestTime\n", - "\t\t}, \n", - "\t\t{\n", - "\t\t\tcolumn_id: 1,\n", - "\t\t\tname: StandardForce\n", - "\t\t}, \n", - "\t\t{\n", - "\t\t\tcolumn_id: 2,\n", - "\t\t\tname: AbsoluteCrossheadTravel\n", - "\t\t}\n", - "\t], \n", - "\n", - "\trdf_exists = True\n", - ")\n" - ] - } - ], - "source": [ - "print(item)" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "And also that the RDF generation was successful:" - ] - }, - { - "cell_type": "code", - "execution_count": 15, - "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "@prefix csvw: .\n", - "@prefix dcat: .\n", - "@prefix dcterms: .\n", - "@prefix ns1: .\n", - "@prefix ns2: .\n", - "@prefix rdfs: .\n", - "@prefix xsd: .\n", - "\n", - " a dcat:Dataset ;\n", - " dcterms:hasPart ;\n", - " dcat:distribution [ a dcat:Distribution ;\n", - " dcat:accessURL \"https://bue.materials-data.space/api/knowledge/data_api/58683a2d-7823-4638-bc8e-91b461afa593\"^^xsd:anyURI ;\n", - " dcat:mediaType \"http://www.iana.org/assignments/media-types/text/csv\"^^xsd:anyURI ] .\n", - "\n", - " a ;\n", - " ns1:hasUnit \"http://qudt.org/vocab/unit/MilliM\"^^xsd:anyURI .\n", - "\n", - " a ;\n", - " ns1:hasUnit \"http://qudt.org/vocab/unit/KiloN\"^^xsd:anyURI .\n", - "\n", - " a ;\n", - " ns1:hasUnit \"http://qudt.org/vocab/unit/SEC\"^^xsd:anyURI .\n", - "\n", - " a csvw:TableGroup ;\n", - " csvw:table [ a csvw:Table ;\n", - " rdfs:label \"Time series data\" ;\n", - " csvw:tableSchema [ a csvw:Schema ;\n", - " csvw:column [ a csvw:Column ;\n", - " ns1:quantity ;\n", - " csvw:titles \"C\"^^xsd:string ;\n", - " ns2:page [ a ns2:Document ;\n", - " dcterms:format \"https://www.iana.org/assignments/media-types/application/json\"^^xsd:anyURI ;\n", - " dcterms:identifier \"https://bue.materials-data.space/api/knowledge/data_api/column-2\"^^xsd:anyURI ;\n", - " dcterms:type \"http://purl.org/dc/terms/Dataset\"^^xsd:anyURI ] ],\n", - " [ a csvw:Column ;\n", - " ns1:quantity ;\n", - " csvw:titles \"B\"^^xsd:string ;\n", - " ns2:page [ a ns2:Document ;\n", - " dcterms:format \"https://www.iana.org/assignments/media-types/application/json\"^^xsd:anyURI ;\n", - " dcterms:identifier \"https://bue.materials-data.space/api/knowledge/data_api/column-1\"^^xsd:anyURI ;\n", - " dcterms:type \"http://purl.org/dc/terms/Dataset\"^^xsd:anyURI ] ],\n", - " [ a csvw:Column ;\n", - " ns1:quantity ;\n", - " csvw:titles \"A\"^^xsd:string ;\n", - " ns2:page [ a ns2:Document ;\n", - " dcterms:format \"https://www.iana.org/assignments/media-types/application/json\"^^xsd:anyURI ;\n", - " dcterms:identifier \"https://bue.materials-data.space/api/knowledge/data_api/column-0\"^^xsd:anyURI ;\n", - " dcterms:type \"http://purl.org/dc/terms/Dataset\"^^xsd:anyURI ] ] ] ] .\n", - "\n", - "\n" - ] - } - ], - "source": [ - "print(item.subgraph.serialize())" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "And now we are able to convert our data into any compatiable unit we want. For the `StandardForce`, it was previously `kN`, but we want to have it in `N` now:\n" - ] - }, - { - "cell_type": "code", - "execution_count": 16, - "metadata": {}, - "outputs": [ - { - "data": { - "text/plain": [ - "[1300.0,\n", - " 1800.0,\n", - " 2100.0,\n", - " 2600.0,\n", - " 3200.0,\n", - " 3700.0,\n", - " 4300.0,\n", - " 4800.0,\n", - " 5300.0,\n", - " 6000.0]" - ] - }, - "execution_count": 16, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "item.dataframe.StandardForce.convert_to(\"N\")" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "#### 6.2.2.3 Manipulate dataframe" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "We are able to retrieve the dataframe as pd.DataFrame:" - ] - }, - { - "cell_type": "code", - "execution_count": 17, - "metadata": {}, - "outputs": [ - { - "data": { - "text/html": [ - "
\n", - "\n", - "\n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - "
TestTimeStandardForceAbsoluteCrossheadTravel
01.21.31.5
11.71.81.9
22.02.12.3
32.52.62.8
43.03.23.4
53.63.73.9
64.14.34.4
74.74.85.0
85.25.35.5
95.86.06.1
\n", - "
" - ], - "text/plain": [ - " TestTime StandardForce AbsoluteCrossheadTravel\n", - "0 1.2 1.3 1.5\n", - "1 1.7 1.8 1.9\n", - "2 2.0 2.1 2.3\n", - "3 2.5 2.6 2.8\n", - "4 3.0 3.2 3.4\n", - "5 3.6 3.7 3.9\n", - "6 4.1 4.3 4.4\n", - "7 4.7 4.8 5.0\n", - "8 5.2 5.3 5.5\n", - "9 5.8 6.0 6.1" - ] - }, - "execution_count": 17, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "item.dataframe.to_df()" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "We are able to overwrite the dataframe with new data:" - ] - }, - { - "cell_type": "code", - "execution_count": 18, - "metadata": {}, - "outputs": [], - "source": [ - "item.dataframe = {\n", - " \"TestTime\": list(range(100)),\n", - " \"StandardForce\": list(range(1,101)),\n", - " \"AbsoluteCrossheadTravel\": list(range(2,102))\n", - "}\n", - "dsms.commit()" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "We are able to retrieve the data colum-wise:" - ] - }, - { - "cell_type": "code", - "execution_count": 19, - "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "column: TestTime ,\n", - " data: [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95, 96, 97, 98, 99]\n", - "column: StandardForce ,\n", - " data: [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95, 96, 97, 98, 99, 100]\n", - "column: AbsoluteCrossheadTravel ,\n", - " data: [2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95, 96, 97, 98, 99, 100, 101]\n" - ] - } - ], - "source": [ - "for column in item.dataframe:\n", - " print(\"column:\", column.name, \",\\n\", \"data:\", column.get())\n" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "... and also to modify the dataframe directly as we need:" - ] - }, - { - "cell_type": "code", - "execution_count": 20, - "metadata": {}, - "outputs": [], - "source": [ - "new_df = item.dataframe.to_df().drop(['TestTime'], axis=1)\n", - "item.dataframe = new_df" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "#### 6.2.2.4 Run app on demand" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "We are able to run the app on demand, not being triggered automatically during the upload of an attachment every time. For this purpose, we just need to refer to the name of the app we assigned during the KItem creation ( here it is simply `data2rdf`).\n", - "\n", - "Additionally, we need to tell the `attachment_name` and hand over the access token and host url to the app by explicitly setting `expose_sdk_config` to `True`. This is basically telling the SDK that the app is using the SDK also internally and that the app should receive its parameters from the current SDK session.\n", - "\n", - "The app is running synchronously, hence the `job` is created when the pipeline run finished." - ] - }, - { - "cell_type": "code", - "execution_count": 21, - "metadata": {}, - "outputs": [], - "source": [ - "job = item.kitem_apps.by_title[\"data2rdf\"].run(\n", - " attachment_name=item.attachments[0].name,\n", - " expose_sdk_config=True\n", - ")" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "We are able to retrieve the job status:" - ] - }, - { - "cell_type": "code", - "execution_count": 22, - "metadata": {}, - "outputs": [ - { - "data": { - "text/plain": [ - "JobStatus(phase='Succeeded', estimated_duration=None, finished_at='08/20/2024, 08:05:35', started_at='08/20/2024, 08:05:15', message=None, progress='1/1')" - ] - }, - "execution_count": 22, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "job.status" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "... and the job logs:" - ] - }, - { - "cell_type": "code", - "execution_count": 23, - "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "\"[2024-08-20 08:05:23,481 - dsms_data2rdf.main - INFO]: Fetch KItem: \\n KItem(\\n\\n\\tname = my tensile test experiment, \\n\\n\\tid = 58683a2d-7823-4638-bc8e-91b461afa593, \\n\\n\\tktype_id = dataset, \\n\\n\\tin_backend = True, \\n\\n\\tslug = mytensiletestexperiment-58683a2d, \\n\\n\\tannotations = [], \\n\\n\\tattachments = [\\n\\t\\t{\\n\\t\\t\\tname: dummy_data.csv\\n\\t\\t}\\n\\t], \\n\\n\\tlinked_kitems = [], \\n\\n\\taffiliations = [], \\n\\n\\tauthors = [\\n\\t\\t{\\n\\t\\t\\tuser_id: 7f0e5a37-353b-4bbc-b1f1-b6ad575f562d\\n\\t\\t}\\n\\t], \\n\\n\\tavatar_exists = True, \\n\\n\\tcontacts = [], \\n\\n\\tcreated_at = 2024-08-20 08:04:25.756982, \\n\\n\\tupdated_at = 2024-08-20 08:04:25.756982, \\n\\n\\texternal_links = [], \\n\\n\\tkitem_apps = [\\n\\t\\t{\\n\\t\\t\\tkitem_app_id: 22,\\n\\t\\t\\texecutable: testapp2,\\n\\t\\t\\ttitle: data2rdf,\\n\\t\\t\\tdescription: None,\\n\\t\\t\\ttags: None,\\n\\t\\t\\tadditional_properties: {triggerUponUpload: True, triggerUponUploadFileExtensions: ['.csv']}\\n\\t\\t}\\n\\t], \\n\\n\\tsummary = None, \\n\\n\\tuser_groups = [], \\n\\n\\tcustom_properties = None, \\n\\n\\tdataframe = [\\n\\t\\t{\\n\\t\\t\\tcolumn_id: 0,\\n\\t\\t\\tname: TestTime\\n\\t\\t}, \\n\\t\\t{\\n\\t\\t\\tcolumn_id: 1,\\n\\t\\t\\tname: StandardForce\\n\\t\\t}, \\n\\t\\t{\\n\\t\\t\\tcolumn_id: 2,\\n\\t\\t\\tname: AbsoluteCrossheadTravel\\n\\t\\t}\\n\\t], \\n\\n\\trdf_exists = True\\n)\\n[2024-08-20 08:05:23,494 - dsms_data2rdf.main - INFO]: Run pipeline with the following parser arguments: {'metadata_sep': ',', 'metadata_length': '0', 'time_series_sep': ',', 'time_series_header_length': '1', 'drop_na': 'false', 'fillna': ''}\\n[2024-08-20 08:05:23,494 - dsms_data2rdf.main - INFO]: Run pipeline with the following parser: Parser.csv\\n[2024-08-20 08:05:23,494 - dsms_data2rdf.main - INFO]: Run pipeline with the following config: {'base_iri': 'https://bue.materials-data.space/58683a2d-7823-4638-bc8e-91b461afa593', 'data_download_uri': 'https://bue.materials-data.space/api/knowledge/data_api/58683a2d-7823-4638-bc8e-91b461afa593', 'graph_identifier': 'https://bue.materials-data.space/58683a2d-7823-4638-bc8e-91b461afa593', 'separator': '/', 'encoding': 'utf-8'}\\n[2024-08-20 08:05:28,419 - dsms_data2rdf.main - INFO]: Pipeline did detect any metadata. Will not make annotations for KItem\\n[2024-08-20 08:05:28,810 - dsms_data2rdf.main - INFO]: Checking that dataframe is up to date.\\n[2024-08-20 08:05:28,810 - dsms_data2rdf.main - INFO]: Dataframe upload was successful after 0 retries.\\n[2024-08-20 08:05:28,810 - dsms_data2rdf.main - INFO]: Done!\\n\"\n" - ] - } - ], - "source": [ - "print(job.logs)" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "In case we would like to run the job in the background, we simply add a `wait=False`:" - ] - }, - { - "cell_type": "code", - "execution_count": 24, - "metadata": {}, - "outputs": [], - "source": [ - "job = item.kitem_apps.by_title[\"data2rdf\"].run(\n", - " attachment_name=item.attachments[0].name,\n", - " expose_sdk_config=True,\n", - " wait=False,\n", - ")" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "We are able to monitor the job status and logs asynchronously:" - ] - }, - { - "cell_type": "code", - "execution_count": 25, - "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "\n", - " Current status:\n", - "phase='Running' estimated_duration=None finished_at=None started_at='08/20/2024, 08:05:39' message=None progress='0/1'\n", - "\n", - " Current logs:\n", - "\"\"\n", - "\n", - " Current status:\n", - "phase='Running' estimated_duration=None finished_at=None started_at='08/20/2024, 08:05:39' message=None progress='0/1'\n", - "\n", - " Current logs:\n", - "\"\"\n", - "\n", - " Current status:\n", - "phase='Running' estimated_duration=None finished_at=None started_at='08/20/2024, 08:05:39' message=None progress='0/1'\n", - "\n", - " Current logs:\n", - "\"\"\n", - "\n", - " Current status:\n", - "phase='Running' estimated_duration=None finished_at=None started_at='08/20/2024, 08:05:39' message=None progress='0/1'\n", - "\n", - " Current logs:\n", - "\"\"\n", - "\n", - " Current status:\n", - "phase='Running' estimated_duration=None finished_at=None started_at='08/20/2024, 08:05:39' message=None progress='0/1'\n", - "\n", - " Current logs:\n", - "\"\"\n", - "\n", - " Current status:\n", - "phase='Running' estimated_duration=None finished_at=None started_at='08/20/2024, 08:05:39' message=None progress='0/1'\n", - "\n", - " Current logs:\n", - "\"\"\n", - "\n", - " Current status:\n", - "phase='Running' estimated_duration=None finished_at=None started_at='08/20/2024, 08:05:39' message=None progress='0/1'\n", - "\n", - " Current logs:\n", - "\"\"\n", - "\n", - " Current status:\n", - "phase='Running' estimated_duration=None finished_at=None started_at='08/20/2024, 08:05:39' message=None progress='0/1'\n", - "\n", - " Current logs:\n", - "\"\"\n", - "\n", - " Current status:\n", - "phase='Succeeded' estimated_duration=None finished_at='08/20/2024, 08:05:59' started_at='08/20/2024, 08:05:39' message=None progress='1/1'\n", - "\n", - " Current logs:\n", - "\"[2024-08-20 08:05:45,472 - dsms_data2rdf.main - INFO]: Fetch KItem: \\n KItem(\\n\\n\\tname = my tensile test experiment, \\n\\n\\tid = 58683a2d-7823-4638-bc8e-91b461afa593, \\n\\n\\tktype_id = dataset, \\n\\n\\tin_backend = True, \\n\\n\\tslug = mytensiletestexperiment-58683a2d, \\n\\n\\tannotations = [], \\n\\n\\tattachments = [\\n\\t\\t{\\n\\t\\t\\tname: dummy_data.csv\\n\\t\\t}\\n\\t], \\n\\n\\tlinked_kitems = [], \\n\\n\\taffiliations = [], \\n\\n\\tauthors = [\\n\\t\\t{\\n\\t\\t\\tuser_id: 7f0e5a37-353b-4bbc-b1f1-b6ad575f562d\\n\\t\\t}\\n\\t], \\n\\n\\tavatar_exists = True, \\n\\n\\tcontacts = [], \\n\\n\\tcreated_at = 2024-08-20 08:04:25.756982, \\n\\n\\tupdated_at = 2024-08-20 08:04:25.756982, \\n\\n\\texternal_links = [], \\n\\n\\tkitem_apps = [\\n\\t\\t{\\n\\t\\t\\tkitem_app_id: 22,\\n\\t\\t\\texecutable: testapp2,\\n\\t\\t\\ttitle: data2rdf,\\n\\t\\t\\tdescription: None,\\n\\t\\t\\ttags: None,\\n\\t\\t\\tadditional_properties: {triggerUponUpload: True, triggerUponUploadFileExtensions: ['.csv']}\\n\\t\\t}\\n\\t], \\n\\n\\tsummary = None, \\n\\n\\tuser_groups = [], \\n\\n\\tcustom_properties = None, \\n\\n\\tdataframe = [\\n\\t\\t{\\n\\t\\t\\tcolumn_id: 0,\\n\\t\\t\\tname: TestTime\\n\\t\\t}, \\n\\t\\t{\\n\\t\\t\\tcolumn_id: 1,\\n\\t\\t\\tname: StandardForce\\n\\t\\t}, \\n\\t\\t{\\n\\t\\t\\tcolumn_id: 2,\\n\\t\\t\\tname: AbsoluteCrossheadTravel\\n\\t\\t}\\n\\t], \\n\\n\\trdf_exists = True\\n)\\n[2024-08-20 08:05:45,485 - dsms_data2rdf.main - INFO]: Run pipeline with the following parser arguments: {'metadata_sep': ',', 'metadata_length': '0', 'time_series_sep': ',', 'time_series_header_length': '1', 'drop_na': 'false', 'fillna': ''}\\n[2024-08-20 08:05:45,485 - dsms_data2rdf.main - INFO]: Run pipeline with the following parser: Parser.csv\\n[2024-08-20 08:05:45,485 - dsms_data2rdf.main - INFO]: Run pipeline with the following config: {'base_iri': 'https://bue.materials-data.space/58683a2d-7823-4638-bc8e-91b461afa593', 'data_download_uri': 'https://bue.materials-data.space/api/knowledge/data_api/58683a2d-7823-4638-bc8e-91b461afa593', 'graph_identifier': 'https://bue.materials-data.space/58683a2d-7823-4638-bc8e-91b461afa593', 'separator': '/', 'encoding': 'utf-8'}\\n[2024-08-20 08:05:50,422 - dsms_data2rdf.main - INFO]: Pipeline did detect any metadata. Will not make annotations for KItem\\n[2024-08-20 08:05:50,816 - dsms_data2rdf.main - INFO]: Checking that dataframe is up to date.\\n[2024-08-20 08:05:50,816 - dsms_data2rdf.main - INFO]: Dataframe upload was successful after 0 retries.\\n[2024-08-20 08:05:50,816 - dsms_data2rdf.main - INFO]: Done!\\n\"\n" - ] - } - ], - "source": [ - "while True:\n", - " time.sleep(1)\n", - " print(\"\\n Current status:\")\n", - " print(job.status)\n", - " print(\"\\n Current logs:\")\n", - " print(job.logs)\n", - " if job.status.phase != \"Running\":\n", - " break" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "**IMPORTANT**: When job has run asychronously (in the background), we need to manually refresh the KItem afterwards:" - ] - }, - { - "cell_type": "code", - "execution_count": 26, - "metadata": {}, - "outputs": [], - "source": [ - "item.refresh()" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "Clean up the DSMS from the tutorial" - ] - }, - { - "cell_type": "code", - "execution_count": 27, - "metadata": {}, - "outputs": [], - "source": [ - "del dsms[item]\n", - "del dsms[appspec]\n", - "dsms.commit()" - ] - } - ], - "metadata": { - "kernelspec": { - "display_name": "sdk", - "language": "python", - "name": "python3" - }, - "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.12.2" - } - }, - "nbformat": 4, - "nbformat_minor": 2 -} diff --git a/examples/tutorials/7_ktypes.ipynb b/examples/tutorials/7_ktypes.ipynb deleted file mode 100644 index 633ef62..0000000 --- a/examples/tutorials/7_ktypes.ipynb +++ /dev/null @@ -1,423 +0,0 @@ -{ - "cells": [ - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "# 7. Interact with KTypes through the SDK\n" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "## 7.1. Setting up\n", - "\n", - "Import the needed classes and functions." - ] - }, - { - "cell_type": "code", - "execution_count": 12, - "metadata": {}, - "outputs": [], - "source": [ - "from dsms import DSMS, KType" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "Now source the environmental variables from an `.env` file and start the DSMS-session." - ] - }, - { - "cell_type": "code", - "execution_count": 13, - "metadata": {}, - "outputs": [], - "source": [ - "dsms = DSMS(env=\"../../.env\")" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "## 7.2. Create KTypes\n", - "\n", - "New KTypes can be created by a simple class inititation." - ] - }, - { - "cell_type": "code", - "execution_count": 14, - "metadata": {}, - "outputs": [ - { - "data": { - "text/plain": [ - "Batch(\n", - "\tid=batch,\n", - "\tname=Batch,\n", - "\twebform=None,\n", - "\tjson_schema=None,\n", - "\trdf_mapping=None,\n", - "\tcreated_at=None,\n", - "\tupdated_at=None\n", - ")" - ] - }, - "execution_count": 14, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "ktype = KType( \n", - " id='batch',\n", - " name='Batch'\n", - ")\n", - "\n", - "ktype" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "The `commit` method should be executed to synchronize the changes with the DSMS SDK." - ] - }, - { - "cell_type": "code", - "execution_count": 15, - "metadata": {}, - "outputs": [], - "source": [ - "dsms.commit()" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "The `type` object will automatically get updated with after the commit." - ] - }, - { - "cell_type": "code", - "execution_count": 16, - "metadata": {}, - "outputs": [ - { - "data": { - "text/plain": [ - "Batch(\n", - "\tid=batch,\n", - "\tname=Batch,\n", - "\twebform=None,\n", - "\tjson_schema=None,\n", - "\trdf_mapping=None,\n", - "\tcreated_at=2024-10-01T14:21:01.164121,\n", - "\tupdated_at=2024-10-01T14:21:01.164121\n", - ")" - ] - }, - "execution_count": 16, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "ktype" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "## 7.3. Update KTypes" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "The ktype object can be fetched using its id." - ] - }, - { - "cell_type": "code", - "execution_count": 17, - "metadata": {}, - "outputs": [ - { - "data": { - "text/plain": [ - "Batch(\n", - "\tid=batch,\n", - "\tname=Batch,\n", - "\twebform=None,\n", - "\tjson_schema=None,\n", - "\trdf_mapping=None,\n", - "\tcreated_at=2024-10-01T14:21:01.164121,\n", - "\tupdated_at=2024-10-01T14:21:01.164121\n", - ")" - ] - }, - "execution_count": 17, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "ktype = dsms.ktypes.Batch\n", - "ktype" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "We can change e.g. the name of the ktype" - ] - }, - { - "cell_type": "code", - "execution_count": 18, - "metadata": {}, - "outputs": [], - "source": [ - "ktype.name = 'Batches'\n", - "dsms.commit()" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "After the committing, we can see the changes of the ktype" - ] - }, - { - "cell_type": "code", - "execution_count": 19, - "metadata": {}, - "outputs": [ - { - "data": { - "text/plain": [ - "Batch(\n", - "\tid=batch,\n", - "\tname=Batches,\n", - "\twebform=None,\n", - "\tjson_schema=None,\n", - "\trdf_mapping=None,\n", - "\tcreated_at=2024-10-01T14:21:01.164121,\n", - "\tupdated_at=2024-10-01T14:21:12.169973\n", - ")" - ] - }, - "execution_count": 19, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "ktype" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "## 7.5. Fetching KTypes\n", - "\n", - "The existing KTypes can be fetched as follows." - ] - }, - { - "cell_type": "code", - "execution_count": 20, - "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "Organization(\n", - "\tid=organization,\n", - "\tname=None,\n", - "\twebform=None,\n", - "\tjson_schema=None,\n", - "\trdf_mapping=None,\n", - "\tcreated_at=2024-05-06T13:01:42.756035,\n", - "\tupdated_at=2024-05-06T13:01:42.756035\n", - ")\n", - "App(\n", - "\tid=app,\n", - "\tname=None,\n", - "\twebform=None,\n", - "\tjson_schema=None,\n", - "\trdf_mapping=None,\n", - "\tcreated_at=2024-05-06T13:01:42.756035,\n", - "\tupdated_at=2024-05-06T13:01:42.756035\n", - ")\n", - "Dataset(\n", - "\tid=dataset,\n", - "\tname=dataset,\n", - "\twebform=None,\n", - "\tjson_schema=None,\n", - "\trdf_mapping=None,\n", - "\tcreated_at=2024-05-06T13:01:42.756035,\n", - "\tupdated_at=2024-05-06T13:01:42.756035\n", - ")\n", - "DatasetCatalog(\n", - "\tid=dataset-catalog,\n", - "\tname=dataset catalog,\n", - "\twebform=None,\n", - "\tjson_schema=None,\n", - "\trdf_mapping=None,\n", - "\tcreated_at=2024-05-06T13:01:42.756035,\n", - "\tupdated_at=2024-05-06T13:01:42.756035\n", - ")\n", - "Expert(\n", - "\tid=expert,\n", - "\tname=expert,\n", - "\twebform={\n", - "\t\tname=dict(annotation=Union[str, NoneType] required=False default=None),\n", - "\t\tskills=dict(annotation=Union[str, NoneType] required=False default=None)\n", - "\t},\n", - "\tjson_schema=None,\n", - "\trdf_mapping=None,\n", - "\tcreated_at=2024-05-06T13:01:42.756035,\n", - "\tupdated_at=2024-05-06T17:09:46.125058\n", - ")\n", - "Test(\n", - "\tid=test,\n", - "\tname=test,\n", - "\twebform=None,\n", - "\tjson_schema=None,\n", - "\trdf_mapping=None,\n", - "\tcreated_at=2024-05-14T07:45:38.051796,\n", - "\tupdated_at=2024-05-14T07:45:38.051796\n", - ")\n", - "Specimen(\n", - "\tid=specimen,\n", - "\tname=Specimen,\n", - "\twebform={\n", - "\t\tsampletype=dict(annotation=Union[str, NoneType] required=False default=None),\n", - "\t\tsampleinformation=dict(annotation=Union[str, NoneType] required=False default=None),\n", - "\t\tsampleproductionprocess=dict(annotation=Union[str, NoneType] required=False default=None)\n", - "\t},\n", - "\tjson_schema=None,\n", - "\trdf_mapping=None,\n", - "\tcreated_at=2024-05-22T07:19:24.079365,\n", - "\tupdated_at=2024-05-22T07:20:08.774884\n", - ")\n", - "Resource(\n", - "\tid=resource,\n", - "\tname=Resource,\n", - "\twebform=None,\n", - "\tjson_schema=None,\n", - "\trdf_mapping=None,\n", - "\tcreated_at=2024-06-10T10:17:31.071959,\n", - "\tupdated_at=2024-06-10T10:17:40.156104\n", - ")\n", - "TestingMachine(\n", - "\tid=testing-machine,\n", - "\tname=Testing Machine,\n", - "\twebform=None,\n", - "\tjson_schema=None,\n", - "\trdf_mapping=None,\n", - "\tcreated_at=2024-08-19T17:13:57.534570,\n", - "\tupdated_at=2024-08-19T18:11:40.465640\n", - ")\n", - "Batch(\n", - "\tid=batch,\n", - "\tname=Batches,\n", - "\twebform=None,\n", - "\tjson_schema=None,\n", - "\trdf_mapping=None,\n", - "\tcreated_at=2024-10-01T14:21:01.164121,\n", - "\tupdated_at=2024-10-01T14:21:12.169973\n", - ")\n" - ] - } - ], - "source": [ - "for ktype in dsms.ktypes:\n", - " print(ktype)" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "## 7.4. Delete KTypes" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "The fetched ktype can be deleted by applying the `del`-operator to the `dsms` object with the individual `KType` object." - ] - }, - { - "cell_type": "code", - "execution_count": 21, - "metadata": {}, - "outputs": [], - "source": [ - "del dsms[ktype]" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "As always, commit the changes." - ] - }, - { - "cell_type": "code", - "execution_count": 22, - "metadata": {}, - "outputs": [], - "source": [ - "dsms.commit()" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "The available KTypes in the SDK can be fetched from an enum list." - ] - } - ], - "metadata": { - "kernelspec": { - "display_name": "sdk", - "language": "python", - "name": "python3" - }, - "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.12.2" - } - }, - "nbformat": 4, - "nbformat_minor": 2 -} diff --git a/examples/tutorials/testfile.txt b/examples/tutorials/testfile.txt deleted file mode 100644 index 7976166..0000000 --- a/examples/tutorials/testfile.txt +++ /dev/null @@ -1 +0,0 @@ -This is a calibration protocol!