Skip to content

Commit

Permalink
Merge pull request #88 from opendata-swiss/feat/add-conformsTo-field
Browse files Browse the repository at this point in the history
Harvest conforms_to field to the dataset
  • Loading branch information
kovalch authored Nov 8, 2023
2 parents 7e4ae2d + 4205f56 commit a96cf78
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 3 deletions.
14 changes: 11 additions & 3 deletions ckanext/dcatapchharvest/profiles.py
Original file line number Diff line number Diff line change
Expand Up @@ -526,6 +526,11 @@ def parse_dataset(self, dataset_dict, dataset_ref): # noqa
dataset_ref, FOAF.page
)

# Conformance
dataset_dict['conforms_to'] = self._object_value_list(
dataset_ref, DCT.conformsTo
)

# Resources
for distribution in self._distributions(dataset_ref):
resource_dict = {
Expand Down Expand Up @@ -704,7 +709,6 @@ def graph_from_dataset(self, dataset_dict, dataset_ref): # noqa
items = [
('language', DCT.language, None, Literal),
('theme', DCAT.theme, None, URIRef),
('conforms_to', DCT.conformsTo, None, Literal),
('alternate_identifier', ADMS.identifier, None, Literal),
('has_version', DCT.hasVersion, None, Literal),
('is_version_of', DCT.isVersionOf, None, Literal),
Expand Down Expand Up @@ -818,6 +822,12 @@ def graph_from_dataset(self, dataset_dict, dataset_ref): # noqa
g.add((doc, RDF.type, FOAF.Document))
g.add((dataset_ref, FOAF.page, doc))

# Conformance
conformance_uris = dataset_dict.get('conforms_to', [])
for uri in conformance_uris:
ref = URIRef(uri)
g.add((dataset_ref, DCT.conformsTo, ref))

# Themes
groups = self._get_dataset_value(dataset_dict, 'groups', [])
for group_name in groups:
Expand Down Expand Up @@ -860,7 +870,6 @@ def graph_from_dataset(self, dataset_dict, dataset_ref): # noqa
# Lists
items = [
('language', DCT.language, None, Literal),
('conforms_to', DCT.conformsTo, None, Literal),
]
self._add_list_triples_from_dict(resource_dict, distribution,
items)
Expand Down Expand Up @@ -1248,7 +1257,6 @@ def graph_from_dataset(self, dataset_dict, dataset_ref):
# Lists
items = [
("language", DCT.language, None, Literal),
("conforms_to", DCT.conformsTo, None, Literal),
]
self._add_list_triples_from_dict(resource_dict, distribution,
items)
Expand Down
2 changes: 2 additions & 0 deletions ckanext/dcatapchharvest/tests/fixtures/1901.xml
Original file line number Diff line number Diff line change
Expand Up @@ -92,5 +92,7 @@
<foaf:page>
<foaf:Document rdf:about="https://example.com/documentation-dataset-2"/>
</foaf:page>
<dct:conformsTo rdf:resource="http://resource.geosciml.org/ontology/timescale/gts"/>
<dct:conformsTo rdf:resource="https://inspire.ec.europa.eu/documents"/>
</dcat:Dataset>
</rdf:RDF>
4 changes: 4 additions & 0 deletions ckanext/dcatapchharvest/tests/fixtures/dataset.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@
"url": "http://example.com/ds1",
"version": "1.0b",
"issued": "2015-06-26T15:21:09.034694",
"conforms_to": [
"http://resource.geosciml.org/ontology/timescale/gts",
"https://inspire.ec.europa.eu/documents"
],
"keywords": {
"fr": [],
"de": [
Expand Down
4 changes: 4 additions & 0 deletions ckanext/dcatapchharvest/tests/test_dcatap_ch_parse.py
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,10 @@ def test_dataset_all_fields(self):
sorted(dataset['documentation']),
['https://example.com/documentation-dataset-1', 'https://example.com/documentation-dataset-2']
)
eq_(
sorted(dataset['conforms_to']),
[u'http://resource.geosciml.org/ontology/timescale/gts', u'https://inspire.ec.europa.eu/documents']
)

# Dataset URI
eq_(extras['uri'], u'https://opendata.swiss/dataset/7451e012-64b2-4bbc-af20-a0e2bc61b585')
Expand Down
11 changes: 11 additions & 0 deletions ckanext/dcatapchharvest/tests/test_dcatap_ch_serialize.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,17 @@ def test_graph_from_dataset(self):
for documentation_link in dataset['documentation']:
assert self._triple(g, dataset_ref, FOAF.page, URIRef(documentation_link))

# Conformance
conforms_to = dataset.get("conforms_to", [])
# Check if the number of triples matches the number of conformance uris
eq_(
len(list(g.triples((dataset_ref, DCT.conformsTo, None)))),
len(conforms_to)
)
for link in conforms_to:
# Check if the triple (dataset_ref, DCT.conformsTo, URIRef(link)) exists in the graph
assert (dataset_ref, DCT.conformsTo, URIRef(link)) in g

# List
for item in [
('language', DCT.language, Literal),
Expand Down

0 comments on commit a96cf78

Please sign in to comment.