{ "cells": [ { "cell_type": "markdown", "id": "6eb15a7a-59b5-4a69-b63d-8fc3d98fb0df", "metadata": {}, "source": [ "# metadata4Ing\n", "\n", "[Metadata4Ing](https://nfdi4ing.pages.rwth-aachen.de/metadata4ing/metadata4ing/) is an ontology developed within the NFDI Consortium [NFDI4Ing](https://nfdi4ing.de/) \"with the aim of providing a thorough framework for the semantic description of research data, with a particular focus on engineering sciences and neighbouring disciplines.\"\n", "\n", "The *h5RDMtoolbox* allows translating JSON-LD data into the HDF5 structure and wise versa (see [here](../userguide/wrapper/FAIRAttributes.ipynb)). This way, engineering process metadata can be added easily to the HDF5 file. \n", "\n", "Consider the following example file taken from the *m4i* ontology [\"first steps guide\"](https://git.rwth-aachen.de/nfdi4ing/metadata4ing/metadata4ing/-/blob/1.2.1/training/first-steps-guide.md), which describes an experimental investigation. You can find the full content of the JSON-LD file [here](min_m4i_ex.jsonld), the following shows an excerpt:" ] }, { "cell_type": "raw", "id": "86c0f874-af71-4aeb-bb15-02aac1a598e8", "metadata": {}, "source": [ "{\n", " \"@context\": \n", " {\n", " \"@import\": \"https://w3id.org/nfdi4ing/metadata4ing/m4i_context.jsonld\",\n", " \"local\": \"https://local-domain.org/\"\n", " },\n", " \"@graph\": [\n", " {\n", " \"@id\": \"local:preparation_0001\",\n", " \"@type\": \"processing step\",\n", " \"label\": \"Sample preparation and parameter definition\",\n", " \"has participant\": \"local:alex\",\n", " \"start time\": \"2022-09-22T10:31:22\"\n", " },\n", "...\n", " ]\n", "}" ] }, { "cell_type": "code", "execution_count": null, "id": "b11673a2-beae-4f8b-b038-674f92a75f89", "metadata": {}, "outputs": [], "source": [ "import h5rdmtoolbox as h5tbx\n", "_ = h5tbx.set_config(auto_create_h5tbx_version=False)" ] }, { "cell_type": "markdown", "id": "6310b7bc-085c-4068-9650-824ebe3e097a", "metadata": {}, "source": [ "With a single call (`h5tbx.jsonld.to_hdf`) it is possible to read in the JSON-LD data and parse it into the HDF5 structure:" ] }, { "cell_type": "code", "execution_count": null, "id": "04c5502d-480f-45cd-804f-6afa50aedafd", "metadata": {}, "outputs": [], "source": [ "with h5tbx.File() as h5:\n", " h5.create_group('metadata')\n", " h5tbx.jsonld.to_hdf(h5.metadata, source='min_m4i_ex.jsonld')\n", " h5.dump(collapsed=False)" ] }, { "cell_type": "code", "execution_count": null, "id": "f0756149-dc6f-468d-808f-5c8ad88ecae4", "metadata": {}, "outputs": [], "source": [ "print(h5tbx.dump_jsonld(h5.hdf_filename,\n", " structural=False,\n", " resolve_keys=True,\n", " indent=2,\n", " context={\"@import\": \"https://w3id.org/nfdi4ing/metadata4ing/m4i_context.jsonld\"}))" ] }, { "cell_type": "code", "execution_count": null, "id": "66c16084-0071-4ca8-a9b2-373247df0860", "metadata": {}, "outputs": [], "source": [] } ], "metadata": { "kernelspec": { "display_name": "Python 3 (ipykernel)", "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.8.20" } }, "nbformat": 4, "nbformat_minor": 5 }