{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "\n", "# pyJedAI Spatial Component\n", "\n", "\n", "In this notebook we present the pyJedAI Geospatial Interlinking functionality." ] }, { "cell_type": "code", "execution_count": 1, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "^C\n" ] } ], "source": [ "!pip install pyjedai:0.1.4" ] }, { "cell_type": "code", "execution_count": 1, "metadata": { "pycharm": { "is_executing": true } }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Python 3.9.16\n" ] } ], "source": [ "!python --version" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Libraries injection" ] }, { "cell_type": "code", "execution_count": 2, "metadata": { "pycharm": { "is_executing": true } }, "outputs": [], "source": [ "import csv\n", "import sys\n", "import os\n", "\n", "from pyjedai.datamodel import SpatialData\n", "from pyjedai.spatial.filtering import StandardSpatialFiltering\n", "from pyjedai.spatial.initialization import StandardSpatialInitialization\n", "from pyjedai.spatial.verification import StandardSpatialVerification" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Data reading and pyJedAI-formating" ] }, { "cell_type": "code", "execution_count": 3, "metadata": {}, "outputs": [], "source": [ "data_dir = '../data/spatial/'\n", "\n", "maxInt = sys.maxsize\n", "while True:\n", " try:\n", " csv.field_size_limit(maxInt)\n", " break\n", " except OverflowError:\n", " maxInt = int(maxInt/10)\n", "\n", "path1 = os.path.join(data_dir,\"regions_gr.csv\")\n", "path2 = os.path.join(data_dir,\"wildlife_sanctuaries.csv\")\n", "\n", "delimiter1 = \"\\t\"\n", "delimiter2 = \"\\t\"\n", "\n", "# Read the CSV files\n", "file1 = open(path1, newline='', encoding='utf-8')\n", "file2 = open(path2, newline='', encoding='utf-8')\n", "\n", "dataset_1 = csv.reader(file1, delimiter=delimiter1)\n", "dataset_2 = csv.reader(file2, delimiter=delimiter1)\n", "\n", "spatial_data = \\\n", " SpatialData(source_reader=dataset_1,\n", " source_delimiter=\"\\t\",\n", " target_reader=dataset_2, target_delimiter=\"\\t\",\n", " skip_header=True)\n" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Spatial Filtering" ] }, { "cell_type": "code", "execution_count": 4, "metadata": {}, "outputs": [], "source": [ "SSF = StandardSpatialFiltering()\n", "spatial_index, theta_x, theta_y = SSF.process(spatial_data)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Spatial Initialization" ] }, { "cell_type": "code", "execution_count": 5, "metadata": {}, "outputs": [], "source": [ "SSI = StandardSpatialInitialization(budget=1000, wScheme=\"MBR\")\n", "priority_pairs = SSI.process(spatial_data, spatial_index, theta_x=theta_x, theta_y=theta_y)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Spatial Verification" ] }, { "cell_type": "code", "execution_count": 6, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "───────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────\n", "Performance:\n", "\tPrecision: 0.72% \n", "\tRecall: 6.48%\n", "\tF1-score: 1.29%\n", "\tProgressive Geometry Recall: 2.33%\n", "───────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────\n" ] }, { "data": { "text/plain": [ "{'Precision:': 0.7192008879023307,\n", " 'Recall:': 6.48,\n", " 'F1-score:': 1.2947052947052946,\n", " 'Progressivr geometry recall:': 2.3338068812430635}" ] }, "execution_count": 6, "metadata": {}, "output_type": "execute_result" } ], "source": [ "SSV = StandardSpatialVerification(q_pairs=100)\n", "SSV.process(spatial_data=spatial_data, priority_pairs=priority_pairs)\n", "SSV.evaluate()" ] } ], "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.10.5" } }, "nbformat": 4, "nbformat_minor": 4 }