Skip to content

Commit

Permalink
Handle multilingual fields in base dcat profile
Browse files Browse the repository at this point in the history
  • Loading branch information
amercader committed Oct 24, 2024
1 parent ae96bea commit 4a59cc4
Showing 1 changed file with 30 additions and 6 deletions.
36 changes: 30 additions & 6 deletions ckanext/dcat/profiles/euro_dcat_ap_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -274,9 +274,19 @@ def _graph_from_dataset_base(self, dataset_dict, dataset_ref):
g.add((dataset_ref, RDF.type, DCAT.Dataset))

# Basic fields
title_key = (
"title_translated"
if "title_translated" in dataset_dict
else "title"
)
notes_key = (
"notes_translated"
if "notes_translated" in dataset_dict
else "notes"
)
items = [
("title", DCT.title, None, Literal),
("notes", DCT.description, None, Literal),
(title_key, DCT.title, None, Literal),
(notes_key, DCT.description, None, Literal),
("url", DCAT.landingPage, None, URIRef, FOAF.Document),
("identifier", DCT.identifier, ["guid", "id"], URIRefOrLiteral),
("version", OWL.versionInfo, ["dcat_version"], Literal),
Expand All @@ -287,8 +297,13 @@ def _graph_from_dataset_base(self, dataset_dict, dataset_ref):
self._add_triples_from_dict(dataset_dict, dataset_ref, items)

# Tags
for tag in dataset_dict.get("tags", []):
g.add((dataset_ref, DCAT.keyword, Literal(tag["name"])))
if "tags_translated" in dataset_dict:
for lang in dataset_dict["tags_translated"]:
for value in dataset_dict["tags_translated"][lang]:
g.add((dataset_ref, DCAT.keyword, Literal(value, lang=lang)))
else:
for tag in dataset_dict.get("tags", []):
g.add((dataset_ref, DCAT.keyword, Literal(tag["name"])))

# Dates
items = [
Expand Down Expand Up @@ -525,9 +540,18 @@ def _graph_from_dataset_base(self, dataset_dict, dataset_ref):
g.add((distribution, RDF.type, DCAT.Distribution))

# Simple values
name_key = (
"name_translated" if "name_translated" in resource_dict else "name"
)
description_key = (
"description_translated"
if "description_translated" in resource_dict
else "description"
)

items = [
("name", DCT.title, None, Literal),
("description", DCT.description, None, Literal),
(name_key, DCT.title, None, Literal),
(description_key, DCT.description, None, Literal),
("status", ADMS.status, None, URIRefOrLiteral),
("license", DCT.license, None, URIRefOrLiteral, DCT.LicenseDocument),
("access_url", DCAT.accessURL, None, URIRef, RDFS.Resource),
Expand Down

0 comments on commit 4a59cc4

Please sign in to comment.