diff --git a/ckanext/dcat/profiles/euro_dcat_ap.py b/ckanext/dcat/profiles/euro_dcat_ap.py index 72a45334..476db265 100644 --- a/ckanext/dcat/profiles/euro_dcat_ap.py +++ b/ckanext/dcat/profiles/euro_dcat_ap.py @@ -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), ] diff --git a/ckanext/dcat/profiles/euro_dcat_ap_2.py b/ckanext/dcat/profiles/euro_dcat_ap_2.py index bf59e990..efaf8d50 100644 --- a/ckanext/dcat/profiles/euro_dcat_ap_2.py +++ b/ckanext/dcat/profiles/euro_dcat_ap_2.py @@ -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 @@ -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 @@ -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 ( @@ -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( @@ -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, @@ -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) @@ -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) @@ -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), ] @@ -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( diff --git a/ckanext/dcat/tests/test_shacl.py b/ckanext/dcat/tests/test_shacl.py index acc3ea72..308261f4 100644 --- a/ckanext/dcat/tests/test_shacl.py +++ b/ckanext/dcat/tests/test_shacl.py @@ -2,6 +2,7 @@ import os from random import randrange +from rdflib import URIRef from pyshacl import validate import pytest @@ -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(