{ "cells": [ { "cell_type": "markdown", "id": "3ecac58d-eafd-480f-90a0-6d02f100419f", "metadata": {}, "source": [ "# How to adjust translations\n", "First import the soilpulsecore package and get storage connection through NullConnector - the project structure and all project-related data will be loaded from dedicated filesystem directory in user's home directory.\n", "\n", "Load existing project by providing user_id and the project id.\n", "\n", "note: in case of filesystem stored SoilPulse project (using NullConnector) the user_id parameter is not relevant and all projects are accessible to local user." ] }, { "cell_type": "code", "execution_count": 2, "id": "d1f7733d-5822-4460-b112-8aa067f7895a", "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "> Crawler type 'zero' registered.\n", "Container type 'filesystem' registered\n", "* Keywords database soilpulse\\databases\\keywords_filesystem registered as 'filesystem'\n", "Container type 'file' registered\n", "Container type 'directory' registered\n", "Container type 'archive' registered\n", "> Crawler type 'filesystem' registered.\n", "> Crawler type 'csv' registered.\n", "> Crawler type 'txt' registered.\n", "Container type 'table' registered\n", "> Crawler type 'table' registered.\n", "Container type 'column' registered\n", "> Crawler type 'column' registered.\n", "Container type 'json' registered\n", "* Keywords database soilpulse\\databases\\keywords_json registered as 'json'\n", "> Crawler type 'json' registered.\n", "failed to load concept vocabulary 'AGROVOC' from 'vocabularies\\agrovoc.json'\n", "failed to load concept vocabulary 'TestConceptVocabulary' from 'vocabularies\\_concepts_vocabulary_1.json'\n", "failed to load method vocabulary 'TestMethodsVocabulary' from 'vocabularies\\_methods_vocabulary_1.json'\n", "loaded methods vocabularies: \n", "failed to load units vocabulary 'TestUnitsVocabulary' from 'vocabularies\\_units_vocabulary_1.json'\n", "loaded units vocabularies: \n" ] } ], "source": [ "from soilpulsecore.db_access import NullConnector\n", "from soilpulsecore.project_management import *\n", "from soilpulsecore.resource_managers import filesystem, data_structures, json\n", "\n", "dbcon = NullConnector()\n", "project = ProjectManager(dbcon, user_id=1, id=1)" ] }, { "cell_type": "markdown", "id": "4913a215-fc43-438d-bf06-7125ec4e5441", "metadata": {}, "source": [ "To make sure that the project is correctly loaded we can again show its contents:" ] }, { "cell_type": "code", "execution_count": 3, "id": "adbbe197-c822-4534-831e-3fcc3d9794c9", "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "\n", "================================================================================\n", "SoilPulse testing\n", "container tree:\n", "--------------------------------------------------------------------------------\n", "1 - runoffdb_excerpt.csv (file, 56.2 kB, 18.11.2024/18.11.2024) [1] >root\n", ". 2 - runoffdb_excerpt (table - table) [20] ^1\n", ". . 3 - locality (column - column) [0] ^2\n", " concepts:\n", " locality: 'locality' locality@ownvocab (*own)\n", ". . 4 - latitude (column - column) [0] ^2\n", ". . 5 - longitude (column - column) [0] ^2\n", ". . 6 - run ID (column - column) [0] ^2\n", ". . 7 - date (column - column) [0] ^2\n", " concepts:\n", " date: 'date of experiment' date_of_experiment@ownvocab (methodic)\n", ". . 8 - plot ID (column - column) [0] ^2\n", ". . 9 - simulator (column - column) [0] ^2\n", " concepts:\n", " simulator: 'rainfall simulator' rainfall_simulator@ownvocab (*own)\n", ". . 10 - crop (column - column) [0] ^2\n", ". . 11 - crop type (column - column) [0] ^2\n", ". . 12 - initial cond. (column - column) [0] ^2\n", ". . 13 - init. moisture (column - column) [0] ^2\n", " concepts:\n", " init. moisture: 'initial moisture' initial_moisture@ownvocab (*own)\n", ". . 14 - canopy cover (column - column) [0] ^2\n", " concepts:\n", " canopy cover: 'canopy cover' canopy_cover@ownvocab (*own)\n", ". . 15 - BBCH (column - column) [0] ^2\n", " concepts:\n", " bbch: 'BBCH' bbch@ownvocab (*own)\n", ". . 16 - rain intensity [mm.h^-1] (column - column) [0] ^2\n", ". . 17 - time to runoff (column - column) [0] ^2\n", " concepts:\n", " time to runoff: 'time to runoff' time_to_runoff@ownvocab (*own)\n", ". . 18 - bulk density [g.cm^-3] (column - column) [0] ^2\n", ". . 19 - total time [s] (column - column) [0] ^2\n", ". . 20 - total rainfall [mm.h^-1] (column - column) [0] ^2\n", ". . 21 - total discharge [l] (column - column) [0] ^2\n", ". . 22 - total soil loss [g] (column - column) [0] ^2\n", "================================================================================\n", "\n", "\n" ] } ], "source": [ "project.showContainerTree()" ] }, { "cell_type": "markdown", "id": "8d85911d-ecf9-44dd-ad58-dba7a4f6cb53", "metadata": {}, "source": [ "Now we fine tune the concepts, methods and units assigned to the containers. Add or remove translation assignments from the container by appropriate methods." ] }, { "cell_type": "code", "execution_count": 5, "id": "f232b48c-0083-46ea-80e4-49294385c8e6", "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "\n", "| # 15 | name: 'BBCH' | parent: 2\n", "| class: ColumnContainer| crawler class: ColumnCrawler\n", "| string-concept translations: -\n", "| string-method translations: -\n", "| string-unit translations: -\n", "\n", "\n", "| # 15 | name: 'BBCH' | parent: 2\n", "| class: ColumnContainer| crawler class: ColumnCrawler\n", "| string-concept translations: |\t\"BBCH\"|\t\t{'term': 'phenophase', 'vocabulary': 'ad_hoc_vocabulary', 'uri': 'this/is/non/existent/uri'}\n", "| string-method translations: -\n", "| string-unit translations: -\n", "\n" ] } ], "source": [ "# get reference to a container to work with\n", "cont = project.getContainerByID(15)\n", "# remove all concepts currently assigned to the container\n", "cont.removeAllConcepts()\n", "print(cont)\n", "# create a concept to be assigned\n", "new_concept = {\"term\": \"phenophase\", \"vocabulary\": \"ad_hoc_vocabulary\", \"uri\": \"this/is/non/existent/uri\"}\n", "# assign the \n", "cont.addStringConcept(\"BBCH\", new_concept)\n", "print(cont)" ] } ], "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.11.9" } }, "nbformat": 4, "nbformat_minor": 5 }