{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# Debugging\n", "\n", "This notebook shows how to set the Forge in debug mode." ] }, { "cell_type": "code", "execution_count": 2, "metadata": {}, "outputs": [], "source": [ "from kgforge.core import KnowledgeGraphForge" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Imports" ] }, { "cell_type": "code", "execution_count": 3, "metadata": {}, "outputs": [], "source": [ "from kgforge.specializations.mappings import DictionaryMapping" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Data & Mapping" ] }, { "cell_type": "code", "execution_count": 4, "metadata": {}, "outputs": [], "source": [ "scientists = [\n", " {\n", " \"id\": 123,\n", " \"name\": \"Marie Curie\",\n", " },\n", " {\n", " \"id\": 456,\n", " \"name\": \"Albert Einstein\",\n", " },\n", "]" ] }, { "cell_type": "code", "execution_count": 5, "metadata": {}, "outputs": [], "source": [ "mapping = DictionaryMapping(\"\"\"\n", " id: forge.format(\"identifier\", \"associations\", x.id)\n", " type: Association\n", " agent: forge.resolve(x.name)\n", "\"\"\")" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Not activated" ] }, { "cell_type": "code", "execution_count": 6, "metadata": {}, "outputs": [], "source": [ "forge_1 = KnowledgeGraphForge(\"../../configurations/demo-forge.yml\")" ] }, { "cell_type": "code", "execution_count": 7, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ " resolve\n", " ResolvingError: resolving scope or resolver name should be specified\n", "\n" ] } ], "source": [ "resources_1 = forge_1.map(scientists, mapping)" ] }, { "cell_type": "code", "execution_count": 8, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "NoneType" ] }, "execution_count": 8, "metadata": {}, "output_type": "execute_result" } ], "source": [ "type(resources_1)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Activated" ] }, { "cell_type": "code", "execution_count": 9, "metadata": {}, "outputs": [], "source": [ "def pexc(e: Exception) -> None:\n", " print(f\"{type(e).__name__}: {e}\")" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### at initialization" ] }, { "cell_type": "code", "execution_count": 10, "metadata": {}, "outputs": [], "source": [ "forge_2 = KnowledgeGraphForge(\"../../configurations/demo-forge.yml\", debug=True)" ] }, { "cell_type": "code", "execution_count": 11, "metadata": { "scrolled": true }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "ResolvingError: resolving scope or resolver name should be specified\n" ] } ], "source": [ "try:\n", " resources_2 = forge_2.map(scientists, mapping)\n", "except Exception as e:\n", " pexc(e)" ] }, { "cell_type": "code", "execution_count": 12, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "NameError: name 'resources_2' is not defined\n" ] } ], "source": [ "try:\n", " resources_2\n", "except Exception as e:\n", " pexc(e)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### on demand" ] }, { "cell_type": "code", "execution_count": 13, "metadata": {}, "outputs": [], "source": [ "forge_3 = KnowledgeGraphForge(\"../../configurations/demo-forge.yml\")" ] }, { "cell_type": "code", "execution_count": 14, "metadata": {}, "outputs": [], "source": [ "forge_3._debug = True" ] }, { "cell_type": "code", "execution_count": 15, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "ResolvingError: resolving scope or resolver name should be specified\n" ] } ], "source": [ "try:\n", " resources_3 = forge_3.map(scientists, mapping)\n", "except Exception as e:\n", " pexc(e)" ] }, { "cell_type": "code", "execution_count": 16, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "NameError: name 'resources_3' is not defined\n" ] } ], "source": [ "try:\n", " resources_3\n", "except Exception as e:\n", " pexc(e)" ] }, { "cell_type": "code", "execution_count": 17, "metadata": {}, "outputs": [], "source": [ "forge_3._debug = False" ] }, { "cell_type": "code", "execution_count": 18, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ " resolve\n", " ResolvingError: resolving scope or resolver name should be specified\n", "\n" ] } ], "source": [ "resources_4 = forge_3.map(scientists, mapping)" ] }, { "cell_type": "code", "execution_count": 19, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "NoneType" ] }, "execution_count": 19, "metadata": {}, "output_type": "execute_result" } ], "source": [ "type(resources_4)" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [] } ], "metadata": { "kernelspec": { "display_name": "Python [conda env:kgforge37]", "language": "python", "name": "conda-env-kgforge37-py" }, "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.7.5" } }, "nbformat": 4, "nbformat_minor": 4 }