Skip to content

Commit

Permalink
Distribution byte size should be nonNegativeInteger
Browse files Browse the repository at this point in the history
  • Loading branch information
amercader committed Aug 22, 2024
1 parent c8f708a commit d480313
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 1 deletion.
21 changes: 20 additions & 1 deletion ckanext/dcat/profiles/euro_dcat_ap_3.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,27 @@
from ckanext.dcat.profiles import EuropeanDCATAP2Profile
from rdflib import Literal

from ckanext.dcat.profiles import EuropeanDCATAP2Profile, DCAT, XSD


class EuropeanDCATAP3Profile(EuropeanDCATAP2Profile):
"""
An RDF profile based on the DCAT-AP 3 for data portals in Europe
"""

def graph_from_dataset(self, dataset_dict, dataset_ref):

# Call the DCAT AP 2 method
super().graph_from_dataset(dataset_dict, dataset_ref)

# byteSize decimal -> nonNegativeInteger
for subject, predicate, object in self.g.triples((None, DCAT.byteSize, None)):
if object and object.datatype == XSD.decimal:
self.g.remove((subject, predicate, object))

self.g.add(
(
subject,
predicate,
Literal(int(object), datatype=XSD.nonNegativeInteger),
)
)
34 changes: 34 additions & 0 deletions ckanext/dcat/tests/test_euro_dcatap_3_profile_serialize.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
from ckanext.dcat.profiles import DCAT, XSD
from ckanext.dcat.processors import RDFSerializer
from ckanext.dcat.tests.utils import BaseSerializeTest

DCAT_AP_PROFILES = ["euro_dcat_ap_3"]


class TestEuroDCATAP2ProfileSerializeDataset(BaseSerializeTest):

def test_byte_size_non_negative_integer(self):

dataset = {
"id": "4b6fe9ca-dc77-4cec-92a4-55c6624a5bd6",
"name": "test-dataset",
"title": "Test DCAT 2 dataset",
"notes": "Lorem ipsum",
"resources": [
{
"id": "7fffe9b2-7a24-4d43-91f7-8bd58bad9615",
"url": "http://example.org/data.csv",
"size": 1234,
}
],
}

s = RDFSerializer(profiles=DCAT_AP_PROFILES)
g = s.g

dataset_ref = s.graph_from_dataset(dataset)

triple = [t for t in g.triples((None, DCAT.byteSize, None))][0]

assert triple[2].datatype == XSD.nonNegativeInteger
assert int(triple[2]) == 1234

0 comments on commit d480313

Please sign in to comment.