The Federal Office of Justice maintains ZEFIX, the swiss commerce register for all legally operating businesses.
The register provides us with company name, type, description, and address.
ZEFIX is also available as Linked Data.
Swiss commerce register data can be accessed with SPARQL queries.
You can send queries using HTTP requests. The API endpoint is https://lindas.admin.ch/query/.
To understand companies' location, we will work with Swiss geodata. It can be accessed with GeoSPARQL under https://ld.geo.admin.ch/query.
import json
import os.path
import folium
import mapclassify
import matplotlib as mpl
import matplotlib.pyplot as plt
import pandas as pd
import geopandas as gpd
import plotly.express as px
import plotly.graph_objects as go
from plotly.subplots import make_subplots
from graphly.api_client import SparqlClient
%matplotlib inline
# Uncomment to install dependencies in Colab environment
#!pip install mapclassify
#!pip install git+https://github.com/zazuko/graphly.git
sparql = SparqlClient("https://lindas.admin.ch/query")
geosparql = SparqlClient("https://ld.geo.admin.ch/query")
sparql.add_prefixes({
"schema": "<http://schema.org/>",
"admin": "<https://schema.ld.admin.ch/>"
})
geosparql.add_prefixes({
"dct": "<http://purl.org/dc/terms/>",
"geonames": "<http://www.geonames.org/ontology#>",
"schema": "<http://schema.org/>",
"geosparql": "<http://www.opengis.net/ont/geosparql#>",
})
SPARQL queries can become very long. To improve the readibility, we will work wih prefixes.
Using the add_prefixes
method, we can define persistent prefixes.
Every time you send a query, graphly
will now automatically add the prefixes for you.
Swiss law offers many opportnities to business owners. They can choose from several legal entites. What entities can we find in ZEFIX? Which ones are the most popular among enterpreneurs?
query = """
SELECT ?type (COUNT(DISTINCT ?company_iri) AS ?ccount)
WHERE {
?company_iri a admin:ZefixOrganisation.
?company_iri schema:additionalType/schema:name ?type .
FILTER(LANG(?type) = "de")
}
GROUP BY ?type
ORDER BY DESC(?ccount)
"""
df = sparql.send_query(query)
# Let's rename variables to english
de2en = {'Kommanditgesellschaft': "Limited Partnership",
'Ausländische Niederlassung im Handelsregister eingetragen': "Foreign Branch",
'Genossenschaft': "Cooperative",
'Verein': "Association",
'Kollektivgesellschaft': "General Partnership",
'Schweizerische Zweigniederlassung im Handelsregister eingetragen': "Swiss Branch",
'Stiftung': "Foundation",
'Einzelunternehmen': "Sole proprietorship",
'Aktiengesellschaft': "Joint-stock Company",
'Gesellschaft mit beschränkter Haftung GMBH / SARL': "Limited Liability Company"}
df["type"] = df["type"].apply(lambda x: de2en[x] if x in de2en else x)
fig = px.bar(df[df.ccount > 500], y="type", x="ccount", orientation = "h", labels={"type": "", "ccount": "Company Count"})
fig.update_layout(
title='Which company type is most popular?',
title_x=0.5,
)
fig.update_layout(bargap=0.40)
fig.show()