Skip to content

Commit

Permalink
feat: hardening format/media type mapping for rdf graph
Browse files Browse the repository at this point in the history
  • Loading branch information
sarusarah committed Sep 29, 2023
1 parent 7b06827 commit 12c9d8b
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 1 deletion.
4 changes: 4 additions & 0 deletions ckanext/dcatapchharvest/dcat_helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -252,6 +252,10 @@ def get_iana_media_type_values():
records = root.findall('.//ns:record', media_types_namespaces)
media_type_values = {}
for record in records:
if record.find('ns:file', media_types_namespaces) is None:
continue
if record.find('ns:name', media_types_namespaces) is None:
continue
name = record.find('ns:name', media_types_namespaces).text
file_value = record.find('ns:file', media_types_namespaces).text
media_type_values[name] = media_types_namespaces['ns']+'/'+file_value
Expand Down
3 changes: 2 additions & 1 deletion ckanext/dcatapchharvest/profiles.py
Original file line number Diff line number Diff line change
Expand Up @@ -893,6 +893,7 @@ def graph_from_dataset(self, dataset_dict, dataset_ref): # noqa
g.add((distribution, FOAF.page, doc))

# Format
format_uri = None
if resource_dict.get('format'):
for key, value in valid_formats.items():
if resource_dict.get('format') == key:
Expand All @@ -904,7 +905,7 @@ def graph_from_dataset(self, dataset_dict, dataset_ref): # noqa
))

# Set Media Type value if format does not match
if not format_uri and resource_dict.get('media_type'):
if format_uri is None and resource_dict.get('media_type'):
for key, value in valid_media_types.items():
if resource_dict.get('media_type') == key:
media_type_uri = URIRef(value)
Expand Down

0 comments on commit 12c9d8b

Please sign in to comment.