Skip to content

Commit

Permalink
[#56] [#56] Serialize repeating subfields
Browse files Browse the repository at this point in the history
  • Loading branch information
amercader committed May 20, 2024
1 parent e6583aa commit 2d8d969
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 1 deletion.
26 changes: 26 additions & 0 deletions ckanext/dcat/profiles.py
Original file line number Diff line number Diff line change
Expand Up @@ -1336,6 +1336,32 @@ def graph_from_dataset(self, dataset_dict, dataset_ref):
_type=URIRef, value_modifier=self._add_mailto
)

# TODO: this will go into a separate profile
contact = dataset_dict.get("contact")
if isinstance(contact, list) and len(contact):
for item in contact:
contact_uri = item.get('uri')
if contact_uri:
contact_details = CleanedURIRef(contact_uri)
else:
contact_details = BNode()

g.add((contact_details, RDF.type, VCARD.Organization))
g.add((dataset_ref, DCAT.contactPoint, contact_details))

self._add_triple_from_dict(
item, contact_details,
VCARD.fn, 'name'
)
# Add mail address as URIRef, and ensure it has a mailto: prefix
self._add_triple_from_dict(
item, contact_details,
VCARD.hasEmail, 'email',
_type=URIRef, value_modifier=self._add_mailto
)



# Publisher
if any([
self._get_dataset_value(dataset_dict, 'publisher_uri'),
Expand Down
5 changes: 4 additions & 1 deletion ckanext/dcat/tests/test_scheming_support.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,5 +90,8 @@ def test_e2e_ckan_to_dcat(self):

contact_details = [t for t in g.triples((dataset_ref, DCAT.contactPoint, None))]

# TODO this will fail
assert len(contact_details) == len(dataset["contact"])
self._triple(g, contact_details[0][2], VCARD.fn, dataset_dict["contact"][0]["name"])
self._triple(g, contact_details[0][2], VCARD.hasEmail, dataset_dict["contact"][0]["email"])
self._triple(g, contact_details[1][2], VCARD.fn, dataset_dict["contact"][1]["name"])
self._triple(g, contact_details[1][2], VCARD.hasEmail, dataset_dict["contact"][1]["email"])

0 comments on commit 2d8d969

Please sign in to comment.