From 957d295a859d6c5b9a65bc8dc77295e35fe94272 Mon Sep 17 00:00:00 2001 From: Matthias Probst Date: Mon, 24 Jun 2024 08:07:31 +0200 Subject: [PATCH] Update Examples.ipynb --- docs/userguide/layout/Examples.ipynb | 145 ++++++++++++++++++++++++++- 1 file changed, 143 insertions(+), 2 deletions(-) diff --git a/docs/userguide/layout/Examples.ipynb b/docs/userguide/layout/Examples.ipynb index 594d400..d4dccfd 100644 --- a/docs/userguide/layout/Examples.ipynb +++ b/docs/userguide/layout/Examples.ipynb @@ -101,7 +101,7 @@ "+--------------------------------------+--------+--------------------+---------------------------+---------------+---------------+-----------------------------------------+\n", "| id | flag | flag description | description | target_type | target_name | func |\n", "|--------------------------------------+--------+--------------------+---------------------------+---------------+---------------+-----------------------------------------|\n", - "| 258da4da-f080-404a-bfdc-2faa6b32e60b | 1 | SUCCESSFUL | String dataset must be 1D | Group | tmp0.hdf | h5rdmtoolbox.database.hdfdb.filedb.find |\n", + "| 39344777-7032-4f34-9f1f-ad14989430f5 | 1 | SUCCESSFUL | String dataset must be 1D | Group | tmp0.hdf | h5rdmtoolbox.database.hdfdb.filedb.find |\n", "+--------------------------------------+--------+--------------------+---------------------------+---------------+---------------+-----------------------------------------+\n", "--> Layout is valid\n" ] @@ -142,10 +142,151 @@ "re.search('^(?!S).*', 'M123')" ] }, + { + "cell_type": "markdown", + "id": "6d8709ac-3676-4a56-891a-832deca11db4", + "metadata": {}, + "source": [ + "## Defining RDF specifications\n", + "\n", + "All dataset must have the attribute units, which shall be semantically described by `http://w3id.org/nfdi4ing/metadata4ing#hasUnit`" + ] + }, + { + "cell_type": "code", + "execution_count": 8, + "id": "b6bda83f-582e-48d0-a9dc-7b8fc0576520", + "metadata": {}, + "outputs": [], + "source": [ + "rdf_lay = layout.Layout()" + ] + }, + { + "cell_type": "code", + "execution_count": 9, + "id": "a98ad451-b361-4f62-a24e-bc6840f9ae2f", + "metadata": {}, + "outputs": [], + "source": [ + "is_dataset = rdf_lay.add(\n", + " hdfdb.FileDB.find,\n", + " flt={'units': {'$exists': True}},\n", + " recursive=True,\n", + " objfilter='dataset',\n", + " description='String dataset must be 1D',\n", + " n={'$gt': 0}\n", + ")" + ] + }, + { + "cell_type": "code", + "execution_count": 10, + "id": "edbd9a8f-03a0-41e8-b954-a97b1b5d180c", + "metadata": {}, + "outputs": [], + "source": [ + "from h5rdmtoolbox.database import rdf_find" + ] + }, + { + "cell_type": "code", + "execution_count": 11, + "id": "515b96d8-9025-4696-a5d7-6a2d0bc996f4", + "metadata": {}, + "outputs": [], + "source": [ + "is_dataset = is_dataset.add(\n", + " rdf_find,\n", + " rdf_predicate=\"http://w3id.org/nfdi4ing/metadata4ing#hasUnit\",\n", + " n=1\n", + ")" + ] + }, + { + "cell_type": "markdown", + "id": "89fb9a00-eb31-42cf-9de1-e6e9785499b8", + "metadata": {}, + "source": [ + "Test the layout specification" + ] + }, + { + "cell_type": "code", + "execution_count": 16, + "id": "4605bae5-fca9-4e0f-9249-cb77c05aab2a", + "metadata": {}, + "outputs": [], + "source": [ + "with h5tbx.File() as h5:\n", + " ds =h5.create_dataset('velocity', data=4.5, attrs={'units': 'm/s'})" + ] + }, + { + "cell_type": "code", + "execution_count": 17, + "id": "83cd6254-f597-4dad-b281-7a594a0aec83", + "metadata": {}, + "outputs": [ + { + "name": "stderr", + "output_type": "stream", + "text": [ + "2024-06-23_15:25:31,621 ERROR [core.py:330] Applying spec. \"LayoutSpecification(kwargs={'rdf_predicate': 'http://w3id.org/nfdi4ing/metadata4ing#hasUnit'})\" failed due to not matching the number of results: 1 != 0\n" + ] + }, + { + "data": { + "text/plain": [ + "False" + ] + }, + "execution_count": 17, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "rdf_lay.validate(h5.hdf_filename).is_valid()" + ] + }, + { + "cell_type": "code", + "execution_count": 18, + "id": "bb359f6d-929e-46fa-a9c6-6c33e38658a3", + "metadata": {}, + "outputs": [], + "source": [ + "with h5tbx.File() as h5:\n", + " ds =h5.create_dataset('velocity', data=4.5, attrs={'units': 'm/s'})\n", + " ds.rdf['units'].predicate = \"http://w3id.org/nfdi4ing/metadata4ing#hasUnit\"" + ] + }, + { + "cell_type": "code", + "execution_count": 19, + "id": "264024ed-44a5-40ad-b2da-1075c7a58c69", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "True" + ] + }, + "execution_count": 19, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "rdf_lay.validate(h5.hdf_filename).is_valid()" + ] + }, { "cell_type": "code", "execution_count": null, - "id": "95ff9f7c-2f9d-4552-bdad-7139e4ea445d", + "id": "6d93fd9a-8df5-413a-ad92-23021ae8fc19", "metadata": {}, "outputs": [], "source": []