Skip to content

Commit

Permalink
feat: add support for dct:identifier in publisher details
Browse files Browse the repository at this point in the history
  • Loading branch information
Hans-Chrstian committed Sep 9, 2024
1 parent cde864e commit aefa22c
Show file tree
Hide file tree
Showing 11 changed files with 102 additions and 72 deletions.
13 changes: 11 additions & 2 deletions ckanext/dcat/converters.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,17 @@ def dcat_to_ckan(dcat_dict):
if isinstance(dcat_publisher, basestring):
package_dict['extras'].append({'key': 'dcat_publisher_name', 'value': dcat_publisher})
elif isinstance(dcat_publisher, dict) and dcat_publisher.get('name'):
package_dict['extras'].append({'key': 'dcat_publisher_name', 'value': dcat_publisher.get('name')})
package_dict['extras'].append({'key': 'dcat_publisher_email', 'value': dcat_publisher.get('mbox')})
if dcat_publisher.get('name'):
package_dict['extras'].append({'key': 'dcat_publisher_name', 'value': dcat_publisher.get('name')})

if dcat_publisher.get('mbox'):
package_dict['extras'].append({'key': 'dcat_publisher_email', 'value': dcat_publisher.get('mbox')})

if dcat_publisher.get('identifier'):
package_dict['extras'].append({
'key': 'dcat_publisher_id',
'value': dcat_publisher.get('identifier') # This could be a URI like https://ror.org/05wg1m734
})

package_dict['extras'].append({
'key': 'language',
Expand Down
3 changes: 2 additions & 1 deletion ckanext/dcat/processors.py
Original file line number Diff line number Diff line change
Expand Up @@ -407,7 +407,8 @@ def _get_from_extra(key):
('name', Literal, FOAF.name, True,),
('email', Literal, FOAF.mbox, False,),
('url', URIRef, FOAF.homepage,False,),
('type', Literal, DCT.type, False,))
('type', Literal, DCT.type, False,),
('identifier', URIRef, DCT.identifier, False,))

_pub = _get_from_extra('source_catalog_publisher')
if _pub:
Expand Down
2 changes: 2 additions & 0 deletions ckanext/dcat/profiles/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -468,6 +468,8 @@ def _publisher(self, subject, predicate):

publisher["type"] = self._object_value(agent, DCT.type)

publisher['identifier'] = self._object_value(agent, DCT.identifier)

return publisher

def _contact_details(self, subject, predicate):
Expand Down
2 changes: 1 addition & 1 deletion ckanext/dcat/profiles/euro_dcat_ap_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ def _parse_dataset_base(self, dataset_dict, dataset_ref):

# Publisher
publisher = self._publisher(dataset_ref, DCT.publisher)
for key in ("uri", "name", "email", "url", "type"):
for key in ("uri", "name", "email", "url", "type", "identifier"):
if publisher.get(key):
dataset_dict["extras"].append(
{"key": "publisher_{0}".format(key), "value": publisher.get(key)}
Expand Down
4 changes: 4 additions & 0 deletions ckanext/dcat/profiles/schemaorg.py
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,10 @@ def _publisher_graph(self, dataset_ref, dataset_dict):

self._add_triples_from_dict(dataset_dict, contact_point, items)

publisher_identifier = self._get_dataset_value(dataset_dict, "publisher_identifier")
if publisher_identifier:
self.g.add((publisher_details, SCHEMA.identifier, Literal(publisher_identifier)))

def _temporal_graph(self, dataset_ref, dataset_dict):
start = self._get_dataset_value(dataset_dict, "temporal_start")
end = self._get_dataset_value(dataset_dict, "temporal_end")
Expand Down
5 changes: 5 additions & 0 deletions ckanext/dcat/schemas/dcat_ap_recommended.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,11 @@ dataset_fields:

- field_name: type
label: Type

- field_name: identifier
label: Identifier
help_text: Unique identifier for the publisher, such as a ROR ID.

help_text: Entity responsible for making the dataset available.

- field_name: license_id
Expand Down
2 changes: 2 additions & 0 deletions ckanext/dcat/tests/profiles/base/test_base_profile.py
Original file line number Diff line number Diff line change
Expand Up @@ -647,6 +647,7 @@ def test_publisher_foaf(self):
<foaf:mbox>[email protected]</foaf:mbox>
<foaf:homepage>http://some.org</foaf:homepage>
<dct:type rdf:resource="http://purl.org/adms/publishertype/NonProfitOrganisation"/>
<dct:identifier rdf:resource="https://ror.org/05wg1m734"/>
</foaf:Organization>
</dct:publisher>
</rdfs:SomeClass>
Expand All @@ -666,6 +667,7 @@ def test_publisher_foaf(self):
assert publisher['email'] == '[email protected]'
assert publisher['url'] == 'http://some.org'
assert publisher['type'] == 'http://purl.org/adms/publishertype/NonProfitOrganisation'
assert publisher['identifier'] == 'https://ror.org/05wg1m734'

def test_publisher_ref(self):

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,7 @@ def _get_extra_value_as_list(key):
assert _get_extra_value('publisher_email') == '[email protected]'
assert _get_extra_value('publisher_url') == 'http://some.org'
assert _get_extra_value('publisher_type') == 'http://purl.org/adms/publishertype/NonProfitOrganisation'
assert _get_extra_value('publisher_identifier') == 'https://ror.org/05wg1m734'
assert _get_extra_value('contact_name') == 'Point of Contact'
# mailto gets removed for storage and is added again on output
assert _get_extra_value('contact_email') == '[email protected]'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@ def test_publisher_extras(self):
{'key': 'publisher_email', 'value': '[email protected]'},
{'key': 'publisher_url', 'value': 'http://example.com/publisher/home'},
{'key': 'publisher_type', 'value': 'http://purl.org/adms/publishertype/Company'},
{'key': 'publisher_identifier', 'value': 'https://ror.org/05wg1m734'},
]


Expand All @@ -121,6 +122,7 @@ def test_publisher_extras(self):
assert str(publisher) == extras['publisher_uri']
assert self._triple(g, publisher, RDF.type, SCHEMA.Organization)
assert self._triple(g, publisher, SCHEMA.name, extras['publisher_name'])
assert self._triple(g, publisher, SCHEMA.identifier, extras['publisher_identifier'])

contact_point = self._triple(g, publisher, SCHEMA.contactPoint, None)[2]
assert contact_point
Expand All @@ -144,6 +146,7 @@ def test_publisher_no_uri(self):
{'key': 'publisher_email', 'value': '[email protected]'},
{'key': 'publisher_url', 'value': 'http://example.com/publisher/home'},
{'key': 'publisher_type', 'value': 'http://purl.org/adms/publishertype/Company'},
{'key': 'publisher_identifier', 'value': 'https://ror.org/05wg1m734'},
]
}
extras = self._extras(dataset)
Expand All @@ -158,6 +161,7 @@ def test_publisher_no_uri(self):
assert isinstance(publisher, BNode)
assert self._triple(g, publisher, RDF.type, SCHEMA.Organization)
assert self._triple(g, publisher, SCHEMA.name, extras['publisher_name'])
assert self._triple(g, publisher, SCHEMA.identifier, extras['publisher_identifier'])

contact_point = self._triple(g, publisher, SCHEMA.contactPoint, None)[2]
assert contact_point
Expand Down
Loading

0 comments on commit aefa22c

Please sign in to comment.