Skip to content

Commit

Permalink
Add a few more classes, including HVD ones
Browse files Browse the repository at this point in the history
  • Loading branch information
amercader committed Jul 16, 2024
1 parent 2f3fe27 commit 9c3a68a
Show file tree
Hide file tree
Showing 3 changed files with 64 additions and 14 deletions.
8 changes: 4 additions & 4 deletions ckanext/dcat/profiles/euro_dcat_ap.py
Original file line number Diff line number Diff line change
Expand Up @@ -469,16 +469,16 @@ def graph_from_dataset(self, dataset_dict, dataset_ref):
("description", DCT.description, None, Literal),
("status", ADMS.status, None, URIRefOrLiteral),
("rights", DCT.rights, None, URIRefOrLiteral, DCT.RightsStatement),
("license", DCT.license, None, URIRefOrLiteral),
("access_url", DCAT.accessURL, None, URIRef),
("download_url", DCAT.downloadURL, None, URIRef),
("license", DCT.license, None, URIRefOrLiteral, DCT.LicenseDocument),
("access_url", DCAT.accessURL, None, URIRef, RDFS.Resource),
("download_url", DCAT.downloadURL, None, URIRef, RDFS.Resource),
]

self._add_triples_from_dict(resource_dict, distribution, items)

# Lists
items = [
("documentation", FOAF.page, None, URIRefOrLiteral),
("documentation", FOAF.page, None, URIRefOrLiteral, FOAF.Document),
("language", DCT.language, None, URIRefOrLiteral, DCT.LinguisticSystem),
("conforms_to", DCT.conformsTo, None, URIRefOrLiteral, DCT.Standard),
]
Expand Down
58 changes: 48 additions & 10 deletions ckanext/dcat/profiles/euro_dcat_ap_2.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import json
from decimal import Decimal, DecimalException

from rdflib import URIRef, BNode, Literal
from rdflib import URIRef, BNode, Literal, Namespace
from ckanext.dcat.utils import resource_uri

from .base import URIRefOrLiteral, CleanedURIRef
Expand All @@ -19,6 +19,9 @@
from .euro_dcat_ap import EuropeanDCATAPProfile


ELI = Namespace("http://data.europa.eu/eli/ontology#")


class EuropeanDCATAP2Profile(EuropeanDCATAPProfile):
"""
An RDF profile based on the DCAT-AP 2 for data portals in Europe
Expand All @@ -37,7 +40,9 @@ def parse_dataset(self, dataset_dict, dataset_ref):
# Standard values
value = self._object_value(dataset_ref, DCAT.temporalResolution)
if value:
dataset_dict["extras"].append({"key": "temporal_resolution", "value": value})
dataset_dict["extras"].append(
{"key": "temporal_resolution", "value": value}
)

# Lists
for key, predicate in (
Expand Down Expand Up @@ -68,7 +73,8 @@ def parse_dataset(self, dataset_dict, dataset_ref):
# For some reason we incorrectly allowed lists in this property at some point
# keep support for it but default to single value
value = (
spatial_resolution[0] if len(spatial_resolution) == 1
spatial_resolution[0]
if len(spatial_resolution) == 1
else json.dumps(spatial_resolution)
)
dataset_dict["extras"].append(
Expand Down Expand Up @@ -170,16 +176,24 @@ def graph_from_dataset(self, dataset_dict, dataset_ref):
)

# Lists
for key, predicate, fallbacks, type, datatype in (
("is_referenced_by", DCT.isReferencedBy, None, URIRefOrLiteral, None),
for key, predicate, fallbacks, type, datatype, _class in (
(
"is_referenced_by",
DCT.isReferencedBy,
None,
URIRefOrLiteral,
None,
RDFS.Resource,
),
(
"applicable_legislation",
DCATAP.applicableLegislation,
None,
URIRefOrLiteral,
None,
ELI.LegalResource,
),
("hvd_category", DCATAP.hvdCategory, None, URIRefOrLiteral, None),
("hvd_category", DCATAP.hvdCategory, None, URIRefOrLiteral, None, None),
):
self._add_triple_from_dict(
dataset_dict,
Expand Down Expand Up @@ -255,8 +269,20 @@ def graph_from_dataset(self, dataset_dict, dataset_ref):
# Simple values
items = [
("availability", DCATAP.availability, None, URIRefOrLiteral),
("compress_format", DCAT.compressFormat, None, URIRefOrLiteral, DCT.MediaType),
("package_format", DCAT.packageFormat, None, URIRefOrLiteral, DCT.MediaType),
(
"compress_format",
DCAT.compressFormat,
None,
URIRefOrLiteral,
DCT.MediaType,
),
(
"package_format",
DCAT.packageFormat,
None,
URIRefOrLiteral,
DCT.MediaType,
),
]

self._add_triples_from_dict(resource_dict, distribution, items)
Expand All @@ -268,6 +294,7 @@ def graph_from_dataset(self, dataset_dict, dataset_ref):
DCATAP.applicableLegislation,
None,
URIRefOrLiteral,
ELI.LegalResource,
),
]
self._add_list_triples_from_dict(resource_dict, distribution, items)
Expand Down Expand Up @@ -301,7 +328,12 @@ def graph_from_dataset(self, dataset_dict, dataset_ref):
("license", DCT.license, None, URIRefOrLiteral),
("access_rights", DCT.accessRights, None, URIRefOrLiteral),
("title", DCT.title, None, Literal),
("endpoint_description", DCAT.endpointDescription, None, URIRefOrLiteral),
(
"endpoint_description",
DCAT.endpointDescription,
None,
URIRefOrLiteral,
),
("description", DCT.description, None, Literal),
]

Expand All @@ -311,7 +343,13 @@ def graph_from_dataset(self, dataset_dict, dataset_ref):

# Lists
items = [
("endpoint_url", DCAT.endpointURL, None, URIRefOrLiteral, RDFS.Resource),
(
"endpoint_url",
DCAT.endpointURL,
None,
URIRefOrLiteral,
RDFS.Resource,
),
("serves_dataset", DCAT.servesDataset, None, URIRefOrLiteral),
]
self._add_list_triples_from_dict(
Expand Down
12 changes: 12 additions & 0 deletions ckanext/dcat/tests/test_shacl.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import os
from random import randrange

from rdflib import URIRef
from pyshacl import validate
import pytest

Expand Down Expand Up @@ -36,6 +37,17 @@ def graph_from_dataset(file_name):
return generated_graphs[file_name]


def _results_count(results_graph):
return len(
[
t
for t in results_graph.triples(
(None, URIRef("http://www.w3.org/ns/shacl#result"), None)
)
]
)


@pytest.mark.usefixtures("with_plugins")
@pytest.mark.ckan_config("ckan.plugins", "dcat scheming_datasets")
@pytest.mark.ckan_config(
Expand Down

0 comments on commit 9c3a68a

Please sign in to comment.