import pandas as pd
from rdflib import Graph
g = Graph()
g.parse("stelselcatalogus.rdf");
prefix = """
PREFIX begrip_brk: <http://opendata.stelselcatalogus.nl/brk/id/begrip/>
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
PREFIX sc: <http://opendata.stelselcatalogus.nl/def/stelselcatalogus#>
PREFIX skos: <http://www.w3.org/2004/02/skos/core#>
"""
q = """
SELECT ?basisregistratie ?begrip ?definitie
WHERE {
?p
a sc:Begrip ;
sc:basisregistratie ?basisregistratie ;
rdfs:label ?begrip ;
skos:definition ?definitie .
}
"""
columns = ["basisregistratie", "begrip", "definitie"]
r = [
(r.basisregistratie.toPython().split("/")[-1], r.begrip.value, r.definitie.value)
for r in g.query(prefix + q)
]
pd.DataFrame.from_records(r, columns=columns).sort_values(columns).reset_index(
drop=True
)
begrip = "nummeraanduiding"
q2 = f"SELECT ?attribuut WHERE {{begrip_brk:{begrip} sc:attribuut ?attribuut.}}"
[r.attribuut.toPython().split("/")[-1] for r in g.query(prefix + q2)]