{ "cells": [ { "cell_type": "markdown", "id": "0ea02b0c", "metadata": {}, "source": [ "
\n", "\n", "# Swiss Parliament: Commissions\n", "\n", "The Federal Chancellery maintains data on the Swiss political system. The curia dataset is publicly available it provides data on political parties, parliamentary comissions, members of parliament and their affiliations. \n", "\n", "Parliament data is also available as [Linked Data](https://en.wikipedia.org/wiki/Linked_data). " ] }, { "cell_type": "markdown", "id": "06f10cf8", "metadata": {}, "source": [ "## Setup" ] }, { "cell_type": "markdown", "id": "9b91c431", "metadata": {}, "source": [ "### SPARQL endpoint\n", "\n", "Swiss political 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://lindas.admin.ch/query).** " ] }, { "cell_type": "markdown", "id": "b7a85d46", "metadata": {}, "source": [ "### SPARQL client\n", "\n", "We will use the `SparqlClient` from [graphly](https://github.com/zazuko/graphly) to communicate with the database. \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": "c0bfc3f4", "metadata": {}, "outputs": [], "source": [ "import pandas as pd\n", "import plotly.express as px\n", "import plotly.graph_objects as go\n", "import matplotlib.pyplot as plt\n", "import matplotlib.colors as mcolors\n", "import warnings\n", "\n", "from plotly.subplots import make_subplots\n", "from graphly.api_client import SparqlClient\n", "\n", "%matplotlib inline\n", "pd.set_option('display.max_rows', 100)\n", "warnings.filterwarnings('ignore')" ] }, { "cell_type": "code", "execution_count": null, "id": "5abffb11", "metadata": {}, "outputs": [], "source": [ "# Uncomment to install dependencies in Colab environment\n", "#!pip install git+https://github.com/zazuko/graphly.git" ] }, { "cell_type": "markdown", "id": "d06f39ee", "metadata": {}, "source": [] }, { "cell_type": "code", "execution_count": null, "id": "35033b56", "metadata": {}, "outputs": [], "source": [ "sparql = SparqlClient(\"https://int.lindas.admin.ch/query\")\n", "\n", "sparql.add_prefixes({\n", " \"schema\": \"