Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dataset Series serialization #334

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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"])),
)
)