Skip to content

Commit

Permalink
Fist pass at Dataset Series serialization
Browse files Browse the repository at this point in the history
  • Loading branch information
amercader committed Jan 29, 2025
1 parent f9cd102 commit 3923f40
Show file tree
Hide file tree
Showing 2 changed files with 58 additions and 1 deletion.
4 changes: 4 additions & 0 deletions ckanext/dcat/blueprints.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,12 @@ def read_dataset(_id, _format=None, package_type=None):
utils.DEFAULT_CATALOG_ENDPOINT).replace(
'{_format}', '<_format>'),
view_func=read_catalog)

# TODO: Generalize for all dataset types
dcat.add_url_rule('/dataset_series/<_id>.<_format>', view_func=read_dataset)
dcat.add_url_rule('/dataset/<_id>.<_format>', view_func=read_dataset)


if toolkit.asbool(config.get(utils.ENABLE_CONTENT_NEGOTIATION_CONFIG)):
dcat.add_url_rule('/', view_func=read_catalog)

Expand Down
55 changes: 54 additions & 1 deletion ckanext/dcat/profiles/euro_dcat_ap_3.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from rdflib import Literal, BNode
from rdflib import Literal, BNode, URIRef

from ckanext.dcat.profiles import (
DCAT,
Expand All @@ -8,6 +8,7 @@
RDF,
)

from ckanext.dcat.utils import dataset_uri
from .euro_dcat_ap_2 import EuropeanDCATAP2Profile
from .euro_dcat_ap_scheming import EuropeanDCATAPSchemingProfile

Expand Down Expand Up @@ -50,6 +51,14 @@ def graph_from_catalog(self, catalog_dict, catalog_ref):

def _graph_from_dataset_v3(self, dataset_dict, dataset_ref):

dataset_series = False

# TODO: support custom type names (ckan/ckanext-dataset-series#6)
if dataset_dict.get("type") == "dataset_series":
dataset_series = True
self.g.remove((dataset_ref, RDF.type, None))
self.g.add((dataset_ref, RDF.type, DCAT.DatasetSeries))

# byteSize decimal -> nonNegativeInteger
for subject, predicate, object in self.g.triples((None, DCAT.byteSize, None)):
if object and object.datatype == XSD.decimal:
Expand All @@ -72,3 +81,47 @@ def _graph_from_dataset_v3(self, dataset_dict, dataset_ref):
self.g.add((dataset_ref, ADMS.identifier, identifier))
self.g.add((identifier, RDF.type, ADMS.Identifier))
self.g.add((identifier, SKOS.notation, Literal(item)))

# Dataset Series
if dataset_series and dataset_dict.get("series_navigation"):

if dataset_dict["series_navigation"].get("first"):
self.g.add(
(
dataset_ref,
DCAT.first,
URIRef(dataset_uri(dataset_dict["series_navigation"]["first"])),
)
)
if dataset_dict["series_navigation"].get("last"):
self.g.add(
(
dataset_ref,
DCAT.last,
URIRef(dataset_uri(dataset_dict["series_navigation"]["last"])),
)
)
elif dataset_dict.get("in_series"):
for series_id in dataset_dict["in_series"]:
# TODO: dataset type?
self.g.add(
(dataset_ref, DCAT.inSeries, URIRef(dataset_uri({"id": series_id})))
)
for series_nav in dataset_dict.get("series_navigation", []):
if series_nav["id"] == series_id:
if series_nav.get("previous"):
self.g.add(
(
dataset_ref,
DCAT.previous,
URIRef(dataset_uri(series_nav["previous"])),
)
)
if series_nav.get("next"):
self.g.add(
(
dataset_ref,
DCAT.next,
URIRef(dataset_uri(series_nav["next"])),
)
)

0 comments on commit 3923f40

Please sign in to comment.