{ "cells": [ { "cell_type": "markdown", "id": "cd2f0c7a", "metadata": {}, "source": [ "
\n", "\n", "# Swiss commerce register\n", "\n", "The Federal Office of Justice maintains ZEFIX, the swiss commerce register for all legally operating businesses.\n", "\n", "\n", "The register provides us with company name, type, description, and address. \n", "ZEFIX is also available as [Linked Data](https://en.wikipedia.org/wiki/Linked_data). \n" ] }, { "cell_type": "markdown", "id": "eb7bef9c", "metadata": {}, "source": [ "## Setup" ] }, { "cell_type": "markdown", "id": "cc8bbfa9", "metadata": {}, "source": [ "### SPARQL endpoints\n", "\n", "#### For companies data\n", "Swiss commerce register data can be accessed with [SPARQL queries](https://www.w3.org/TR/rdf-sparql-query/). \n", "You can send queries using HTTP requests. The API endpoint is **[https://lindas.admin.ch/query/](https://int.lindas.admin.ch/query).** \n", "\n", "#### For geodata\n", "To understand companies' location, we will work with Swiss geodata. It can be accessed with GeoSPARQL under **[https://geo.ld.admin.ch/query](https://geo.ld.admin.ch/query).** " ] }, { "cell_type": "markdown", "id": "da9db59c", "metadata": {}, "source": [ "### SPARQL client\n", "\n", "Let's use `SparqlClient` from [graphly](https://github.com/zazuko/graphly) to communicate with both databases. \n", "Graphly will allow us to:\n", "* send SPARQL queries\n", "* automatically add prefixes to all queries\n", "* format response to `pandas` or `geopandas`" ] }, { "cell_type": "code", "execution_count": null, "id": "d2f8138f", "metadata": {}, "outputs": [], "source": [ "import json\n", "import os.path\n", "\n", "import folium\n", "import mapclassify\n", "import matplotlib as mpl\n", "import pandas as pd\n", "import geopandas as gpd\n", "import plotly.express as px\n", "import plotly.graph_objects as go\n", "\n", "from graphly.api_client import SparqlClient\n", "from geopy.extra.rate_limiter import RateLimiter\n", "from geopy.geocoders import Nominatim\n", "from shapely.geometry import Point\n", "\n", "%matplotlib inline" ] }, { "cell_type": "code", "execution_count": null, "id": "f80432ff", "metadata": {}, "outputs": [], "source": [ "# Uncomment to install dependencies in Colab environment\n", "#!pip install mapclassify\n", "#!pip install git+https://github.com/zazuko/graphly.git" ] }, { "cell_type": "code", "execution_count": null, "id": "55a2bac1", "metadata": {}, "outputs": [], "source": [ "sparql = SparqlClient(\"https://lindas.admin.ch/query\")\n", "geosparql = SparqlClient(\"https://geo.ld.admin.ch/query\")\n", "\n", "sparql.add_prefixes({\n", " \"schema\": \"