-
Notifications
You must be signed in to change notification settings - Fork 146
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Distribution byte size should be nonNegativeInteger
- Loading branch information
Showing
2 changed files
with
54 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
34
ckanext/dcat/tests/test_euro_dcatap_3_profile_serialize.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |