{ "cells": [ { "attachments": {}, "cell_type": "markdown", "metadata": { "ExecuteTime": { "end_time": "2019-09-23T18:50:19.036357Z", "start_time": "2019-09-23T18:50:19.031896Z" } }, "source": [ "# Querying\n", "\n", "This notebook demonstrates Nexus Forge data [querying features](https://nexus-forge.readthedocs.io/en/latest/interaction.html#querying)." ] }, { "cell_type": "code", "execution_count": 1, "metadata": { "ExecuteTime": { "end_time": "2019-09-23T18:50:20.068658Z", "start_time": "2019-09-23T18:50:19.054054Z" } }, "outputs": [], "source": [ "from kgforge.core import KnowledgeGraphForge" ] }, { "attachments": {}, "cell_type": "markdown", "metadata": {}, "source": [ "A configuration file is needed in order to create a KnowledgeGraphForge session. A configuration can be generated using the notebook [00-Initialization.ipynb](00%20-%20Initialization.ipynb)." ] }, { "cell_type": "code", "execution_count": 2, "metadata": {}, "outputs": [ { "ename": "Exception", "evalue": "Mapping loading failed", "output_type": "error", "traceback": [ "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m", "\u001b[0;31mException\u001b[0m Traceback (most recent call last)", "Cell \u001b[0;32mIn[2], line 1\u001b[0m\n\u001b[0;32m----> 1\u001b[0m forge \u001b[38;5;241m=\u001b[39m \u001b[43mKnowledgeGraphForge\u001b[49m\u001b[43m(\u001b[49m\u001b[38;5;124;43m\"\u001b[39;49m\u001b[38;5;124;43m../../configurations/forge.yml\u001b[39;49m\u001b[38;5;124;43m\"\u001b[39;49m\u001b[43m)\u001b[49m\n", "File \u001b[0;32m~/work_dir/nexus-forge/venv/lib/python3.8/site-packages/kgforge/core/forge.py:249\u001b[0m, in \u001b[0;36mKnowledgeGraphForge.__init__\u001b[0;34m(self, configuration, **kwargs)\u001b[0m\n\u001b[1;32m 246\u001b[0m resolvers_config \u001b[38;5;241m=\u001b[39m config\u001b[38;5;241m.\u001b[39mpop(\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mResolvers\u001b[39m\u001b[38;5;124m\"\u001b[39m, \u001b[38;5;28;01mNone\u001b[39;00m)\n\u001b[1;32m 247\u001b[0m \u001b[38;5;66;03m# Format: Optional[Dict[scope_name, Dict[resolver_name, Resolver]]].\u001b[39;00m\n\u001b[1;32m 248\u001b[0m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39m_resolvers: Optional[Dict[\u001b[38;5;28mstr\u001b[39m, Dict[\u001b[38;5;28mstr\u001b[39m, Resolver]]] \u001b[38;5;241m=\u001b[39m (\n\u001b[0;32m--> 249\u001b[0m \u001b[43mprepare_resolvers\u001b[49m\u001b[43m(\u001b[49m\u001b[43mresolvers_config\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43mstore_config\u001b[49m\u001b[43m)\u001b[49m\n\u001b[1;32m 250\u001b[0m \u001b[38;5;28;01mif\u001b[39;00m resolvers_config\n\u001b[1;32m 251\u001b[0m \u001b[38;5;28;01melse\u001b[39;00m \u001b[38;5;28;01mNone\u001b[39;00m\n\u001b[1;32m 252\u001b[0m )\n\u001b[1;32m 254\u001b[0m \u001b[38;5;66;03m# Formatters.\u001b[39;00m\n\u001b[1;32m 255\u001b[0m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39m_formatters: Optional[Dict[\u001b[38;5;28mstr\u001b[39m, \u001b[38;5;28mstr\u001b[39m]] \u001b[38;5;241m=\u001b[39m config\u001b[38;5;241m.\u001b[39mpop(\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mFormatters\u001b[39m\u001b[38;5;124m\"\u001b[39m, \u001b[38;5;28;01mNone\u001b[39;00m)\n", "File \u001b[0;32m~/work_dir/nexus-forge/venv/lib/python3.8/site-packages/kgforge/core/forge.py:958\u001b[0m, in \u001b[0;36mprepare_resolvers\u001b[0;34m(config, store_config)\u001b[0m\n\u001b[1;32m 955\u001b[0m \u001b[38;5;28;01mdef\u001b[39;00m \u001b[38;5;21mprepare_resolvers\u001b[39m(\n\u001b[1;32m 956\u001b[0m config: Dict, store_config: Dict\n\u001b[1;32m 957\u001b[0m ) \u001b[38;5;241m-\u001b[39m\u001b[38;5;241m>\u001b[39m Dict[\u001b[38;5;28mstr\u001b[39m, Dict[\u001b[38;5;28mstr\u001b[39m, Resolver]]:\n\u001b[0;32m--> 958\u001b[0m \u001b[38;5;28;01mreturn\u001b[39;00m {\n\u001b[1;32m 959\u001b[0m scope: \u001b[38;5;28mdict\u001b[39m(prepare_resolver(x, store_config) \u001b[38;5;28;01mfor\u001b[39;00m x \u001b[38;5;129;01min\u001b[39;00m configs)\n\u001b[1;32m 960\u001b[0m \u001b[38;5;28;01mfor\u001b[39;00m scope, configs \u001b[38;5;129;01min\u001b[39;00m config\u001b[38;5;241m.\u001b[39mitems()\n\u001b[1;32m 961\u001b[0m }\n", "File \u001b[0;32m~/work_dir/nexus-forge/venv/lib/python3.8/site-packages/kgforge/core/forge.py:959\u001b[0m, in \u001b[0;36m\u001b[0;34m(.0)\u001b[0m\n\u001b[1;32m 955\u001b[0m \u001b[38;5;28;01mdef\u001b[39;00m \u001b[38;5;21mprepare_resolvers\u001b[39m(\n\u001b[1;32m 956\u001b[0m config: Dict, store_config: Dict\n\u001b[1;32m 957\u001b[0m ) \u001b[38;5;241m-\u001b[39m\u001b[38;5;241m>\u001b[39m Dict[\u001b[38;5;28mstr\u001b[39m, Dict[\u001b[38;5;28mstr\u001b[39m, Resolver]]:\n\u001b[1;32m 958\u001b[0m \u001b[38;5;28;01mreturn\u001b[39;00m {\n\u001b[0;32m--> 959\u001b[0m scope: \u001b[38;5;28;43mdict\u001b[39;49m\u001b[43m(\u001b[49m\u001b[43mprepare_resolver\u001b[49m\u001b[43m(\u001b[49m\u001b[43mx\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43mstore_config\u001b[49m\u001b[43m)\u001b[49m\u001b[43m \u001b[49m\u001b[38;5;28;43;01mfor\u001b[39;49;00m\u001b[43m \u001b[49m\u001b[43mx\u001b[49m\u001b[43m \u001b[49m\u001b[38;5;129;43;01min\u001b[39;49;00m\u001b[43m \u001b[49m\u001b[43mconfigs\u001b[49m\u001b[43m)\u001b[49m\n\u001b[1;32m 960\u001b[0m \u001b[38;5;28;01mfor\u001b[39;00m scope, configs \u001b[38;5;129;01min\u001b[39;00m config\u001b[38;5;241m.\u001b[39mitems()\n\u001b[1;32m 961\u001b[0m }\n", "File \u001b[0;32m~/work_dir/nexus-forge/venv/lib/python3.8/site-packages/kgforge/core/forge.py:959\u001b[0m, in \u001b[0;36m\u001b[0;34m(.0)\u001b[0m\n\u001b[1;32m 955\u001b[0m \u001b[38;5;28;01mdef\u001b[39;00m \u001b[38;5;21mprepare_resolvers\u001b[39m(\n\u001b[1;32m 956\u001b[0m config: Dict, store_config: Dict\n\u001b[1;32m 957\u001b[0m ) \u001b[38;5;241m-\u001b[39m\u001b[38;5;241m>\u001b[39m Dict[\u001b[38;5;28mstr\u001b[39m, Dict[\u001b[38;5;28mstr\u001b[39m, Resolver]]:\n\u001b[1;32m 958\u001b[0m \u001b[38;5;28;01mreturn\u001b[39;00m {\n\u001b[0;32m--> 959\u001b[0m scope: \u001b[38;5;28mdict\u001b[39m(\u001b[43mprepare_resolver\u001b[49m\u001b[43m(\u001b[49m\u001b[43mx\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43mstore_config\u001b[49m\u001b[43m)\u001b[49m \u001b[38;5;28;01mfor\u001b[39;00m x \u001b[38;5;129;01min\u001b[39;00m configs)\n\u001b[1;32m 960\u001b[0m \u001b[38;5;28;01mfor\u001b[39;00m scope, configs \u001b[38;5;129;01min\u001b[39;00m config\u001b[38;5;241m.\u001b[39mitems()\n\u001b[1;32m 961\u001b[0m }\n", "File \u001b[0;32m~/work_dir/nexus-forge/venv/lib/python3.8/site-packages/kgforge/core/forge.py:982\u001b[0m, in \u001b[0;36mprepare_resolver\u001b[0;34m(config, store_config)\u001b[0m\n\u001b[1;32m 980\u001b[0m resolver_name \u001b[38;5;241m=\u001b[39m config\u001b[38;5;241m.\u001b[39mpop(\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mresolver\u001b[39m\u001b[38;5;124m\"\u001b[39m)\n\u001b[1;32m 981\u001b[0m resolver \u001b[38;5;241m=\u001b[39m import_class(resolver_name, \u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mresolvers\u001b[39m\u001b[38;5;124m\"\u001b[39m)\n\u001b[0;32m--> 982\u001b[0m \u001b[38;5;28;01mreturn\u001b[39;00m resolver\u001b[38;5;241m.\u001b[39m\u001b[38;5;18m__name__\u001b[39m, \u001b[43mresolver\u001b[49m\u001b[43m(\u001b[49m\u001b[38;5;241;43m*\u001b[39;49m\u001b[38;5;241;43m*\u001b[39;49m\u001b[43mconfig\u001b[49m\u001b[43m)\u001b[49m\n", "File \u001b[0;32m~/work_dir/nexus-forge/venv/lib/python3.8/site-packages/kgforge/specializations/resolvers/demo_resolver.py:33\u001b[0m, in \u001b[0;36mDemoResolver.__init__\u001b[0;34m(self, source, targets, result_resource_mapping, **source_config)\u001b[0m\n\u001b[1;32m 31\u001b[0m \u001b[38;5;28;01mdef\u001b[39;00m \u001b[38;5;21m__init__\u001b[39m(\u001b[38;5;28mself\u001b[39m, source: \u001b[38;5;28mstr\u001b[39m, targets: List[Dict[\u001b[38;5;28mstr\u001b[39m, Any]], result_resource_mapping: \u001b[38;5;28mstr\u001b[39m,\n\u001b[1;32m 32\u001b[0m \u001b[38;5;241m*\u001b[39m\u001b[38;5;241m*\u001b[39msource_config) \u001b[38;5;241m-\u001b[39m\u001b[38;5;241m>\u001b[39m \u001b[38;5;28;01mNone\u001b[39;00m:\n\u001b[0;32m---> 33\u001b[0m \u001b[38;5;28;43msuper\u001b[39;49m\u001b[43m(\u001b[49m\u001b[43m)\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[38;5;21;43m__init__\u001b[39;49m\u001b[43m(\u001b[49m\u001b[43msource\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43mtargets\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43mresult_resource_mapping\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[38;5;241;43m*\u001b[39;49m\u001b[38;5;241;43m*\u001b[39;49m\u001b[43msource_config\u001b[49m\u001b[43m)\u001b[49m\n", "File \u001b[0;32m~/work_dir/nexus-forge/venv/lib/python3.8/site-packages/kgforge/core/archetypes/resolver.py:53\u001b[0m, in \u001b[0;36mResolver.__init__\u001b[0;34m(self, source, targets, result_resource_mapping, **source_config)\u001b[0m\n\u001b[1;32m 51\u001b[0m filters \u001b[38;5;241m=\u001b[39m \u001b[38;5;28;01mNone\u001b[39;00m\n\u001b[1;32m 52\u001b[0m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39mtargets[target[\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124midentifier\u001b[39m\u001b[38;5;124m\"\u001b[39m]] \u001b[38;5;241m=\u001b[39m {\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mbucket\u001b[39m\u001b[38;5;124m\"\u001b[39m: target[\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mbucket\u001b[39m\u001b[38;5;124m\"\u001b[39m], \u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mfilters\u001b[39m\u001b[38;5;124m\"\u001b[39m: filters}\n\u001b[0;32m---> 53\u001b[0m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39mresult_mapping: Any \u001b[38;5;241m=\u001b[39m \u001b[38;5;28;43mself\u001b[39;49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mmapping\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mload\u001b[49m\u001b[43m(\u001b[49m\u001b[43mresult_resource_mapping\u001b[49m\u001b[43m)\u001b[49m\n\u001b[1;32m 54\u001b[0m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39mservice: Any \u001b[38;5;241m=\u001b[39m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39m_initialize_service(\u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39msource, \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39mtargets, \u001b[38;5;241m*\u001b[39m\u001b[38;5;241m*\u001b[39msource_config)\n", "File \u001b[0;32m~/work_dir/nexus-forge/venv/lib/python3.8/site-packages/kgforge/core/archetypes/mapping.py:69\u001b[0m, in \u001b[0;36mMapping.load\u001b[0;34m(cls, source, mapping_type)\u001b[0m\n\u001b[1;32m 67\u001b[0m \u001b[38;5;28;01mif\u001b[39;00m e \u001b[38;5;129;01mis\u001b[39;00m \u001b[38;5;129;01mnot\u001b[39;00m \u001b[38;5;28;01mNone\u001b[39;00m:\n\u001b[1;32m 68\u001b[0m \u001b[38;5;28;01mreturn\u001b[39;00m e\n\u001b[0;32m---> 69\u001b[0m \u001b[38;5;28;01mraise\u001b[39;00m \u001b[38;5;167;01mException\u001b[39;00m(\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mMapping loading failed\u001b[39m\u001b[38;5;124m\"\u001b[39m)\n\u001b[1;32m 71\u001b[0m \u001b[38;5;28;01mif\u001b[39;00m mapping_type \u001b[38;5;241m==\u001b[39m MappingType\u001b[38;5;241m.\u001b[39mFILE:\n\u001b[1;32m 72\u001b[0m \u001b[38;5;28;01mreturn\u001b[39;00m \u001b[38;5;28mcls\u001b[39m\u001b[38;5;241m.\u001b[39mload_file(source)\n", "\u001b[0;31mException\u001b[0m: Mapping loading failed" ] } ], "source": [ "forge = KnowledgeGraphForge(\"../../configurations/forge.yml\")" ] }, { "attachments": {}, "cell_type": "markdown", "metadata": {}, "source": [ "## Imports" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "from kgforge.core import Resource\n", "from kgforge.specializations.resources import Dataset\n", "from kgforge.core.wrappings.paths import Filter, FilterOperator" ] }, { "attachments": {}, "cell_type": "markdown", "metadata": {}, "source": [ "## Retrieval" ] }, { "attachments": {}, "cell_type": "markdown", "metadata": {}, "source": [ "### latest version" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "jane = Resource(type=\"Person\", name=\"Jane Doe\", award=[\"Nobel\"])" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "forge.register(jane)" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "resource = forge.retrieve(jane.id)" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "resource == jane" ] }, { "attachments": {}, "cell_type": "markdown", "metadata": {}, "source": [ "### specific version" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "jane = Resource(type=\"Person\", name=\"Jane Doe\", award=[\"Nobel\"])" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "forge.register(jane)" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "forge.tag(jane, \"v1\")" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "jane.email = [\"jane.doe@epfl.ch\", \"jane.doe@example.org\"]" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "forge.update(jane)" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "ExecuteTime": { "end_time": "2019-09-23T18:50:21.317601Z", "start_time": "2019-09-23T18:50:21.310418Z" } }, "outputs": [], "source": [ "try:\n", " # DemoStore\n", " print(jane._store_metadata.version)\n", "except:\n", " # BlueBrainNexus\n", " print(jane._store_metadata._rev)" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "ExecuteTime": { "end_time": "2019-09-23T18:50:21.332678Z", "start_time": "2019-09-23T18:50:21.322025Z" } }, "outputs": [], "source": [ "jane_v1 = forge.retrieve(jane.id, version=1)" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "ExecuteTime": { "end_time": "2019-09-23T18:50:21.370051Z", "start_time": "2019-09-23T18:50:21.363782Z" } }, "outputs": [], "source": [ "jane_v1_tag = forge.retrieve(jane.id, version=\"v1\")" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "jane_v1_rev = forge.retrieve(jane.id+\"?rev=1\")" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "ExecuteTime": { "end_time": "2019-09-23T18:50:21.379911Z", "start_time": "2019-09-23T18:50:21.373539Z" } }, "outputs": [], "source": [ "jane_v1 == jane_v1_tag" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "jane_v1 == jane_v1_rev" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "jane_v1 != jane" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "try:\n", " # DemoStore\n", " print(jane_v1._store_metadata.version)\n", "except:\n", " # BlueBrainNexus\n", " print(jane_v1._store_metadata._rev)" ] }, { "attachments": {}, "cell_type": "markdown", "metadata": {}, "source": [ "### crossbucket retrieval\n", "It is possible to retrieve resources stored in buckets different then the configured one. The configured store should of course support it." ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "resource = forge.retrieve(jane.id, cross_bucket=True) # cross_bucket defaults to False" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "resource._store_metadata" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "resource._last_action" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "resource._synchronized" ] }, { "attachments": {}, "cell_type": "markdown", "metadata": {}, "source": [ "### Retrieving using the resorce url\n", "One can also use the value of `_self` from ._stote_metadata to retrieve a resource" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "import copy" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "other_resource = copy.deepcopy(resource)" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "other_resource.id = \"https://myincreadibleid-987654321\"" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "forge.register(other_resource)" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "url = other_resource._store_metadata['_self']" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "same_resource_url = forge.retrieve(id=url)\n", "same_resource_id = forge.retrieve(id=other_resource.id)" ] }, { "attachments": {}, "cell_type": "markdown", "metadata": {}, "source": [ "Confirm they are the same" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "same_resource_id == same_resource_url" ] }, { "attachments": {}, "cell_type": "markdown", "metadata": {}, "source": [ "### Original source retrieval\n", "When using BlueBrainNexusStore, it is possible to retrieve resources' payload as they were registered (retrieve_source=True) without any changes related to store added metadata or JSONLD framing." ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "resource = forge.retrieve(jane.id, retrieve_source=False) # retrieve_source defaults to True" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "forge.as_json(resource)" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "resource._store_metadata" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "resource._last_action" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "resource._synchronized" ] }, { "attachments": {}, "cell_type": "markdown", "metadata": {}, "source": [ "### error handling" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "resource = forge.retrieve(\"123\")" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "resource is None" ] }, { "attachments": {}, "cell_type": "markdown", "metadata": {}, "source": [ "## Searching" ] }, { "attachments": {}, "cell_type": "markdown", "metadata": {}, "source": [ "Note: DemoModel and RdfModel schemas have not been synchronized yet. This section is to be run with RdfModel. Commented lines are for DemoModel." ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "jane = Resource(type=\"Person\", name=\"Jane Doe\")\n", "contribution_jane = Resource(type=\"Contribution\", agent=jane)" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "john = Resource(type=\"Person\", name=\"John Smith\")\n", "contribution_john = Resource(type=\"Contribution\", agent=john)" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "dataset = Dataset(forge, type=\"Dataset\", contribution=[contribution_jane, contribution_john])\n", "dataset.add_distribution(\"../../data/associations.tsv\")" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "forge.register(dataset)" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "forge.as_json(dataset)" ] }, { "attachments": {}, "cell_type": "markdown", "metadata": {}, "source": [ "### Using resource paths as filters" ] }, { "attachments": {}, "cell_type": "markdown", "metadata": {}, "source": [ "The `paths` method load the template or property paths (ie. expected properties) for a given type.\n", "\n", "Please refer to the [Modeling.ipynb](11%20-%20Modeling.ipynb) notebook to learn about templates and types." ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "p = forge.paths(\"Dataset\")" ] }, { "attachments": {}, "cell_type": "markdown", "metadata": {}, "source": [ "Autocompletion is enabled on `p` and this can be used to create search filters." ] }, { "attachments": {}, "cell_type": "markdown", "metadata": {}, "source": [ "Note: There is a known issue for RdfModel which requires using `p.type.id` instead of `p.type`." ] }, { "attachments": {}, "cell_type": "markdown", "metadata": {}, "source": [ "All [python comparison operators](https://www.w3schools.com/python/gloss_python_comparison_operators.asp) are supported." ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "resources = forge.search(p.type.id==\"Person\", limit=3)" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "type(resources)" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "len(resources)" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "forge.as_dataframe(resources)" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "forge.as_dataframe(resources, store_metadata=True)" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "# Search results are not synchronized\n", "resources[0]._synchronized" ] }, { "attachments": {}, "cell_type": "markdown", "metadata": {}, "source": [ "#### Using nested resource property" ] }, { "attachments": {}, "cell_type": "markdown", "metadata": {}, "source": [ "Property autocompletion is available on a path `p` even for nested properties like `p.contribution`." ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "# Search for resources of type Dataset and with text/tab-separated-values as distribution.encodingFormat\n", "resources = forge.search(p.type.id == \"Dataset\", p.distribution.encodingFormat == \"text/tab-separated-values\", limit=3)" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "len(resources)" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "scrolled": true }, "outputs": [], "source": [ "forge.as_dataframe(resources)" ] }, { "attachments": {}, "cell_type": "markdown", "metadata": {}, "source": [ "### Using dictionaries as filters\n", "A dictionary can be provided for filters:\n", "* {'type': {'id':'Dataset'}} is equivalent to p.type.id==\"Dataset\"\n", "* only the '==' operator is supported\n", "* nested dict are supported\n", "* it is not mandatory for the provided properties and values to be defined in the forge model. Results will be retrieved if there are corresponding data in the store.\n", "\n", "This feature is not supported when using the DemoStore\n" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "# Search for resources of type Dataset and with text/tab-separated-values as distribution.encodingFormat\n", "# and created a given dateTime (by default, dateTime values should be signaled by the suffix \"^^xsd:dateTime\")\n", "filters = {\n", " \"type\": \"Dataset\", \n", " \"distribution\":{\"encodingFormat\":\"text/tab-separated-values\"},\n", " \"_createdAt\":dataset._store_metadata._createdAt+\"^^xsd:dateTime\"\n", " }\n", "resources = forge.search(filters, limit=3)" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "type(resources)" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "len(resources)" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "forge.as_dataframe(resources, store_metadata=True)" ] }, { "attachments": {}, "cell_type": "markdown", "metadata": {}, "source": [ "### Using built-in Filter objects" ] }, { "attachments": {}, "cell_type": "markdown", "metadata": {}, "source": [ "#### Supported filter operators" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "[f\"{op.value} ({op.name})\" for op in FilterOperator] # These are equivalent to the Python comparison operators" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "# Search for resources of type Dataset and with text/tab-separated-values as distribution.encodingFormat\n", "# and created a given dateTime (dateTime values should be signaled by the suffix \"^^xsd:dateTime\")\n", "filter_1 = Filter(operator=FilterOperator.EQUAL, path=[\"type\"], value=\"Dataset\")\n", "filter_2 = Filter(operator=FilterOperator.EQUAL, path=[\"distribution\",\"encodingFormat\"], value=\"text/tab-separated-values\")\n", "filter_3 = Filter(operator=FilterOperator.LOWER_OR_Equal_Than, path=[\"_createdAt\"], value=dataset._store_metadata._createdAt+\"^^xsd:dateTime\")\n", "\n", "resources = forge.search(filter_1, filter_2, filter_3, limit=3)" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "type(resources)" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "len(resources)" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "forge.as_dataframe(resources, store_metadata=True)" ] }, { "attachments": {}, "cell_type": "markdown", "metadata": {}, "source": [ "### Using search endpoints\n", "\n", "Two types of search endpoints are supported: 'sparql' (default) for graph queries and 'elastic' for document oriented queries. The types of available search endpoint can be configured (see [00-Initialization.ipynb](00%20-%20Initialization.ipynb) for an example of search endpoints config) or set when creating a KnowledgeGraphForge session using the 'searchendpoints' arguments.\n", "\n", "The search endpoint to hit when calling forge.search(...) is 'sparql' by default but can be specified using the 'search_endpoint' argument." ] }, { "attachments": {}, "cell_type": "markdown", "metadata": {}, "source": [ "#### SPARQL Search Endpoint" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "# Search for resources of type Person\n", "filters = {\"type\": \"Person\"}\n", "resources = forge.search(filters, limit=3, search_endpoint='sparql')" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "type(resources)" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "len(resources)" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "forge.as_dataframe(resources, store_metadata=True)" ] }, { "attachments": {}, "cell_type": "markdown", "metadata": {}, "source": [ "#### ElasticSearch Endpoint" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "# Search for resources of type Person and retrieve their ids and names.\n", "filters = {\"@type\": \"http://schema.org/Person\"}\n", "resources = forge.search(filters, limit=3, \n", " search_endpoint='elastic', \n", " includes=[\"@id\", \"@type\"]) # fields can also be excluded with 'excludes'" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "type(resources)" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "len(resources)" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "forge.as_dataframe(resources, store_metadata=True)" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "# Search results are not synchronized\n", "resources[0]._synchronized" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "resources[0].id" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "resources[0].type" ] }, { "attachments": {}, "cell_type": "markdown", "metadata": {}, "source": [ "### Crossbucket search\n", "It is possible to search for resources stored in buckets different than the configured one. The configured store should of course support it." ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "resources = forge.search(p.type.id == \"Association\", limit=3, cross_bucket=True) # cross_bucket defaults to False" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "type(resources)" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "len(resources)" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "forge.as_dataframe(resources)" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "#Furthermore it is possible to filter by bucket when cross_bucket is set to True. Setting a bucket value when cross_bucket is False will trigger a not_supported exception.\n", "resources = forge.search(p.type.id == \"Person\", limit=3, cross_bucket=True, bucket=\"dke/kgforge\") # add a bucket" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "type(resources)" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "len(resources)" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "forge.as_dataframe(resources)" ] }, { "attachments": {}, "cell_type": "markdown", "metadata": {}, "source": [ "### Searching original source\n", "When using BlueBrainNexusStore, it is possible to retrieve resources' payload as they were registered (retrieve_source=True) without any changes related to store added metadata or JSONLD framing." ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "resources = forge.search(p.type.id == \"Association\", limit=3, retrieve_source=False) # retrieve_source defaults to True" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "type(resources)" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "len(resources)" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "forge.as_dataframe(resources)" ] }, { "attachments": {}, "cell_type": "markdown", "metadata": {}, "source": [ "## Graph traversing\n", "\n", "SPARQL is used as a query language to perform graph traversing.\n", "\n", "Nexus Forge implements a SPARQL query rewriting strategy leveraging a configured RDFModel that lets users write SPARQL queries without adding prefix declarations, prefix names or long IRIs. With this strategy, only type and property names can be provided.\n", "\n", "Please refer to the [Modeling.ipynb](11%20-%20Modeling.ipynb) notebook to learn about templates." ] }, { "attachments": {}, "cell_type": "markdown", "metadata": {}, "source": [ "Note: DemoStore doesn't implement SPARQL operations yet. Please use another store for this section." ] }, { "attachments": {}, "cell_type": "markdown", "metadata": {}, "source": [ "Note: DemoModel and RdfModel schemas have not been synchronized yet. This section is to be run with RdfModel." ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "jane = Resource(type=\"Person\", name=\"Jane Doe\")\n", "contribution_jane = Resource(type=\"Contribution\", agent=jane)" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "john = Resource(type=\"Person\", name=\"John Smith\")\n", "contribution_john = Resource(type=\"Contribution\", agent=john)" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "association = Resource(type=\"Dataset\", contribution=[contribution_jane, contribution_john])" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "forge.register(association)" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "scrolled": true }, "outputs": [], "source": [ "forge.template(\"Dataset\") # Templates help know which property to use when writing a query to serach for a given type" ] }, { "attachments": {}, "cell_type": "markdown", "metadata": {}, "source": [ "### Prefix and namespace free SPARQL query\n", "\n", "When a forge RDFModel is configured, then there is no need to provide prefixes and namespaces when writing a SPARQL query. Prefixes and namespaces will be automatically inferred from the provided schemas and/or JSON-LD context and the query rewritten accordingly." ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "query = \"\"\"\n", " SELECT ?id ?name ?contributor\n", " WHERE {\n", " ?id a Dataset ;\n", " contribution/agent ?contributor.\n", " ?contributor name ?name.\n", " }\n", "\"\"\"" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "resources = forge.sparql(query, limit=3)" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "type(resources)" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "len(resources)" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "print(resources[0])" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "forge.as_dataframe(resources)" ] }, { "attachments": {}, "cell_type": "markdown", "metadata": {}, "source": [ "### display rewritten SPARQL query " ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "resources = forge.sparql(query, limit=3, debug=True)" ] }, { "attachments": {}, "cell_type": "markdown", "metadata": {}, "source": [ "### Full SPARQL query\n", "\n", "Regular SPARQL query can also be provided. When provided, the limit and offset arguments superseed any in query limit or offset values." ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "query = \"\"\"\n", "PREFIX dc: \n", " PREFIX dcat: \n", " PREFIX dcterms: \n", " PREFIX mba: \n", " PREFIX nsg: \n", " PREFIX owl: \n", " PREFIX prov: \n", " PREFIX rdf: \n", " PREFIX rdfs: \n", " PREFIX schema: \n", " PREFIX sh: \n", " PREFIX shsh: \n", " PREFIX skos: \n", " PREFIX vann: \n", " PREFIX void: \n", " PREFIX xsd: \n", " PREFIX : \n", " SELECT ?id ?name\n", " WHERE {\n", " ?id a schema:Dataset ;\n", " nsg:contribution/prov:agent ?contributor.\n", " ?contributor schema:name ?name.\n", " }\n", " ORDER BY ?id\n", " LIMIT 1\n", " OFFSET 0\n", "\"\"\"" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "# it is recommended to set 'rewrite' to 'False' to prevent the sparql query rewriting when a syntactically correct SPARQL query is provided.\n", "resources = forge.sparql(query, rewrite=False, limit=3, offset=1, debug=True) " ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "type(resources)" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "len(resources)" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "type(resources[0])" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "forge.as_dataframe(resources)" ] }, { "attachments": {}, "cell_type": "markdown", "metadata": {}, "source": [ "### Avoid rewriting the query" ] }, { "attachments": {}, "cell_type": "markdown", "metadata": {}, "source": [ "To not assign any limit or offset, one can pass `None` to those parameters" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "query_without_limit = \"\"\"\n", " PREFIX dc: \n", " PREFIX dcat: \n", " PREFIX dcterms: \n", " PREFIX mba: \n", " PREFIX nsg: \n", " PREFIX owl: \n", " PREFIX prov: \n", " PREFIX rdf: \n", " PREFIX rdfs: \n", " PREFIX schema: \n", " PREFIX sh: \n", " PREFIX shsh: \n", " PREFIX skos: \n", " PREFIX vann: \n", " PREFIX void: \n", " PREFIX xsd: \n", " PREFIX : \n", " SELECT ?id ?name\n", " WHERE {\n", " ?id a schema:Dataset ;\n", " nsg:contribution/prov:agent ?contributor.\n", " ?contributor schema:name ?name.\n", " }\n", " ORDER BY ?id\n", "\"\"\"" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "\n", "resources = forge.sparql(query_without_limit, rewrite=False, limit=None, offset=None, debug=True)" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "len(resources)" ] }, { "attachments": {}, "cell_type": "markdown", "metadata": {}, "source": [ "If you only want to add the context, but keep the content of the query the same, you need to set the `rewrite` parameter to `False`" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "query_without_context = \"\"\"\n", " SELECT ?id ?name ?contributor\n", " WHERE {\n", " ?id a Dataset ;\n", " contribution/agent ?contributor.\n", " ?contributor name ?name.\n", " }\n", "\"\"\"" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "resources = forge.sparql(query_without_context, limit=None, debug=True)" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "len(resources)" ] }, { "attachments": {}, "cell_type": "markdown", "metadata": {}, "source": [ "## ElasticSearch DSL Query\n", "\n", "ElasticSearch DSL can be used as a query language search for resources provided that the configured store supports it. The 'BlueBrainNexusStore' supports ElasticSearch." ] }, { "attachments": {}, "cell_type": "markdown", "metadata": {}, "source": [ "Note: DemoStore doesn't implement ElasaticSearch DSL operations." ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "jane = Resource(type=\"Person\", name=\"Jane Doe\")\n", "contribution_jane = Resource(type=\"Contribution\", agent=jane)" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "john = Resource(type=\"Person\", name=\"John Smith\")\n", "contribution_john = Resource(type=\"Contribution\", agent=john)" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "association = Resource(type=\"Dataset\", contribution=[contribution_jane, contribution_john])" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "forge.register(association)" ] }, { "attachments": {}, "cell_type": "markdown", "metadata": {}, "source": [ "### Plain ElasticSearch DSL" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "query = \"\"\"\n", " {\n", " \"_source\": {\n", " \"includes\": [\n", " \"@id\",\n", " \"name\"\n", " ]\n", " },\n", " \"query\": {\n", " \"term\": {\n", " \"@type\": \"http://schema.org/Dataset\"\n", " }\n", " }\n", " }\n", "\"\"\"" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "# limit and offset (when provided in this method call) superseed 'size' and 'from' values provided in the query\n", "resources = forge.elastic(query, limit=3)" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "type(resources)" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "len(resources)" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "type(resources[0])" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "forge.as_dataframe(resources)" ] }, { "attachments": {}, "cell_type": "markdown", "metadata": {}, "source": [ "## Downloading" ] }, { "attachments": {}, "cell_type": "markdown", "metadata": {}, "source": [ "Note: DemoStore doesn't implement file operations yet. Please use another store for this section." ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "jane = Resource(type=\"Person\", name=\"Jane Doe\")" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "! ls -p ../../data | egrep -v /$" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "distribution = forge.attach(\"../../data\")" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "association = Resource(type=\"Association\", agent=jane, distribution=distribution)" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "forge.register(association)" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "# By default, the downladable file urls are collected from the json path \"distribution.contentUrl\" (follow=\"distribution.contentUrl\") and\n", "# the files are downloaded in the current path (path=\".\"). \n", "# The argument overwrite: bool can be provided to decide whether to overwrite (True) existing files with the same name or\n", "# to create new ones (False) with their names suffixed with a timestamp.\n", "# A cross_bucket argument can be provided to download data from the configured bucket (cross_bucket=False - the default value) \n", "# or from a bucket different than the configured one (cross_bucket=True). The configured store should support crossing buckets for this to work.\n", "forge.download(association)" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "# Specific content type can be downloaded.\n", "forge.download(association, content_type=\"text/tab-separated-values\")" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "# The urls or the files to download can be collected from a different json path (by setting a value for \"follow\") and \n", "# the files downloaded to a different path (by setting a value for \"path\")\n", "forge.download(association, follow=\"distribution.contentUrl\", path=\"./downloaded/\")" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "! ls -l ./downloaded/" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "#! rm -R ./downloaded/" ] } ], "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.17" }, "vscode": { "interpreter": { "hash": "9ac393a5ddd595f2c78ea58b15bf8d269850a4413729cbea5c5fae9013762763" } } }, "nbformat": 4, "nbformat_minor": 4 }