Skip to content

Commit

Permalink
Add classes to DCAT-AP 1 and 2 properties
Browse files Browse the repository at this point in the history
There are two of them that are not added:

* All the properties that have `skos:Concept`. Adding this class makes
  the range validation pass, but the shapes one fail, because we need to
  provide a `skos:prefLabel` value. This makes sense but the parser does
  not currently support it. It will probably have to be implemented as
  part of codelists support
* All the properties that have `dcat:Dataset` range. Again, this makes
  the range tests pass but the shapes fail, because a `dct:title` and
  `dct:description` is expected of `dcat:Datasets`. I actually think
  this is a mistake on the validation, as it doesn't make sense to
  require those for referenced datasets (things like `serves_dataset` or
  `is_version_of`).
  • Loading branch information
amercader committed Jul 16, 2024
1 parent 69aea63 commit 2f3fe27
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 29 deletions.
34 changes: 20 additions & 14 deletions ckanext/dcat/profiles/euro_dcat_ap.py
Original file line number Diff line number Diff line change
Expand Up @@ -279,10 +279,10 @@ def graph_from_dataset(self, dataset_dict, dataset_ref):
("identifier", DCT.identifier, ["guid", "id"], URIRefOrLiteral),
("version", OWL.versionInfo, ["dcat_version"], Literal),
("version_notes", ADMS.versionNotes, None, Literal),
("frequency", DCT.accrualPeriodicity, None, URIRefOrLiteral),
("access_rights", DCT.accessRights, None, URIRefOrLiteral),
("dcat_type", DCT.type, None, Literal),
("provenance", DCT.provenance, None, Literal),
("frequency", DCT.accrualPeriodicity, None, URIRefOrLiteral, DCT.Frequency),
("access_rights", DCT.accessRights, None, URIRefOrLiteral, DCT.AccessRights),
("dcat_type", DCT.type, None, URIRefOrLiteral),
("provenance", DCT.provenance, None, URIRefOrLiteral, DCT.ProvenanceStatement),
]
self._add_triples_from_dict(dataset_dict, dataset_ref, items)

Expand All @@ -301,14 +301,14 @@ def graph_from_dataset(self, dataset_dict, dataset_ref):
items = [
("language", DCT.language, None, URIRefOrLiteral, DCT.LinguisticSystem),
("theme", DCAT.theme, None, URIRef),
("conforms_to", DCT.conformsTo, None, Literal),
("alternate_identifier", ADMS.identifier, None, URIRefOrLiteral),
("conforms_to", DCT.conformsTo, None, URIRefOrLiteral, DCT.Standard),
("alternate_identifier", ADMS.identifier, None, URIRefOrLiteral, ADMS.Identifier),
("documentation", FOAF.page, None, URIRefOrLiteral, FOAF.Document),
("related_resource", DCT.relation, None, URIRefOrLiteral),
("related_resource", DCT.relation, None, URIRefOrLiteral, RDFS.Resource),
("has_version", DCT.hasVersion, None, URIRefOrLiteral),
("is_version_of", DCT.isVersionOf, None, URIRefOrLiteral),
("source", DCT.source, None, URIRefOrLiteral),
("sample", ADMS.sample, None, URIRefOrLiteral),
("sample", ADMS.sample, None, URIRefOrLiteral, DCAT.Distribution),
]
self._add_list_triples_from_dict(dataset_dict, dataset_ref, items)

Expand Down Expand Up @@ -404,7 +404,7 @@ def graph_from_dataset(self, dataset_dict, dataset_ref):
}
# Add to graph
if publisher_ref:
g.add((publisher_ref, RDF.type, FOAF.Organization))
g.add((publisher_ref, RDF.type, FOAF.Agent))
g.add((dataset_ref, DCT.publisher, publisher_ref))
items = [
("name", FOAF.name, None, Literal),
Expand Down Expand Up @@ -468,7 +468,7 @@ def graph_from_dataset(self, dataset_dict, dataset_ref):
("name", DCT.title, None, Literal),
("description", DCT.description, None, Literal),
("status", ADMS.status, None, URIRefOrLiteral),
("rights", DCT.rights, None, URIRefOrLiteral),
("rights", DCT.rights, None, URIRefOrLiteral, DCT.RightsStatement),
("license", DCT.license, None, URIRefOrLiteral),
("access_url", DCAT.accessURL, None, URIRef),
("download_url", DCAT.downloadURL, None, URIRef),
Expand All @@ -479,8 +479,8 @@ def graph_from_dataset(self, dataset_dict, dataset_ref):
# Lists
items = [
("documentation", FOAF.page, None, URIRefOrLiteral),
("language", DCT.language, None, URIRefOrLiteral),
("conforms_to", DCT.conformsTo, None, Literal),
("language", DCT.language, None, URIRefOrLiteral, DCT.LinguisticSystem),
("conforms_to", DCT.conformsTo, None, URIRefOrLiteral, DCT.Standard),
]
self._add_list_triples_from_dict(resource_dict, distribution, items)

Expand Down Expand Up @@ -515,10 +515,16 @@ def graph_from_dataset(self, dataset_dict, dataset_ref):
mimetype = None

if mimetype:
g.add((distribution, DCAT.mediaType, URIRefOrLiteral(mimetype)))
mimetype = URIRefOrLiteral(mimetype)
g.add((distribution, DCAT.mediaType, mimetype))
if isinstance(mimetype, URIRef):
g.add((mimetype, RDF.type, DCT.MediaType))

if fmt:
g.add((distribution, DCT["format"], URIRefOrLiteral(fmt)))
fmt = URIRefOrLiteral(fmt)
g.add((distribution, DCT["format"], fmt))
if isinstance(fmt, URIRef):
g.add((fmt, RDF.type, DCT.MediaTypeOrExtent))

# URL fallback and old behavior
url = resource_dict.get("url")
Expand Down
7 changes: 4 additions & 3 deletions ckanext/dcat/profiles/euro_dcat_ap_2.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
DCT,
XSD,
SCHEMA,
RDFS,
)

from .euro_dcat_ap import EuropeanDCATAPProfile
Expand Down Expand Up @@ -254,8 +255,8 @@ def graph_from_dataset(self, dataset_dict, dataset_ref):
# Simple values
items = [
("availability", DCATAP.availability, None, URIRefOrLiteral),
("compress_format", DCAT.compressFormat, None, URIRefOrLiteral),
("package_format", DCAT.packageFormat, None, URIRefOrLiteral),
("compress_format", DCAT.compressFormat, None, URIRefOrLiteral, DCT.MediaType),
("package_format", DCAT.packageFormat, None, URIRefOrLiteral, DCT.MediaType),
]

self._add_triples_from_dict(resource_dict, distribution, items)
Expand Down Expand Up @@ -310,7 +311,7 @@ def graph_from_dataset(self, dataset_dict, dataset_ref):

# Lists
items = [
("endpoint_url", DCAT.endpointURL, None, URIRefOrLiteral),
("endpoint_url", DCAT.endpointURL, None, URIRefOrLiteral, RDFS.Resource),
("serves_dataset", DCAT.servesDataset, None, URIRefOrLiteral),
]
self._add_list_triples_from_dict(
Expand Down
27 changes: 19 additions & 8 deletions ckanext/dcat/profiles/euro_dcat_ap_scheming.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,9 +71,7 @@ def _parse_list_value(data_dict, field_name):
_parse_list_value(resource_dict, field_name)

# Repeating subfields
new_fields_mapping = {
"temporal_coverage": "temporal"
}
new_fields_mapping = {"temporal_coverage": "temporal"}
for schema_field in self._dataset_schema["dataset_fields"]:
if "repeating_subfields" in schema_field:
# Check if existing extras need to be migrated
Expand Down Expand Up @@ -132,7 +130,7 @@ def _not_empty_dict(data_dict):
else:
contact_details = BNode()

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

self._add_triple_from_dict(item, contact_details, VCARD.fn, "name")
Expand All @@ -147,23 +145,32 @@ def _not_empty_dict(data_dict):
)

publisher = dataset_dict.get("publisher")
if isinstance(publisher, list) and len(publisher) and _not_empty_dict(publisher[0]):
if (
isinstance(publisher, list)
and len(publisher)
and _not_empty_dict(publisher[0])
):
publisher = publisher[0]
publisher_uri = publisher.get("uri")
if publisher_uri:
publisher_ref = CleanedURIRef(publisher_uri)
else:
publisher_ref = BNode()

self.g.add((publisher_ref, RDF.type, FOAF.Organization))
self.g.add((publisher_ref, RDF.type, FOAF.Agent))
self.g.add((dataset_ref, DCT.publisher, publisher_ref))

self._add_triple_from_dict(publisher, publisher_ref, FOAF.name, "name")
self._add_triple_from_dict(
publisher, publisher_ref, FOAF.homepage, "url", _type=URIRef
)
self._add_triple_from_dict(
publisher, publisher_ref, DCT.type, "type", _type=URIRefOrLiteral
publisher,
publisher_ref,
DCT.type,
"type",
_type=URIRefOrLiteral,
_class=SKOS.Concept,
)
self._add_triple_from_dict(
publisher,
Expand All @@ -175,7 +182,11 @@ def _not_empty_dict(data_dict):
)

temporal = dataset_dict.get("temporal_coverage")
if isinstance(temporal, list) and len(temporal) and _not_empty_dict(temporal[0]):
if (
isinstance(temporal, list)
and len(temporal)
and _not_empty_dict(temporal[0])
):
for item in temporal:
temporal_ref = BNode()
self.g.add((temporal_ref, RDF.type, DCT.PeriodOfTime))
Expand Down
8 changes: 4 additions & 4 deletions ckanext/dcat/tests/test_euro_dcatap_profile_serialize.py
Original file line number Diff line number Diff line change
Expand Up @@ -395,7 +395,7 @@ def test_publisher_extras(self):
assert publisher
assert str(publisher) == extras['publisher_uri']

assert self._triple(g, publisher, RDF.type, FOAF.Organization)
assert self._triple(g, publisher, RDF.type, FOAF.Agent)
assert self._triple(g, publisher, FOAF.name, extras['publisher_name'])
assert self._triple(g, publisher, FOAF.mbox, extras['publisher_email'])
assert self._triple(g, publisher, FOAF.homepage, URIRef(extras['publisher_url']))
Expand Down Expand Up @@ -426,7 +426,7 @@ def test_publisher_org(self):
publisher = self._triple(g, dataset_ref, DCT.publisher, None)[2]
assert publisher

assert self._triple(g, publisher, RDF.type, FOAF.Organization)
assert self._triple(g, publisher, RDF.type, FOAF.Agent)
assert self._triple(g, publisher, FOAF.name, dataset['organization']['title'])

def test_publisher_no_uri(self):
Expand All @@ -448,7 +448,7 @@ def test_publisher_no_uri(self):
assert publisher
assert isinstance(publisher, BNode)

assert self._triple(g, publisher, RDF.type, FOAF.Organization)
assert self._triple(g, publisher, RDF.type, FOAF.Agent)
assert self._triple(g, publisher, FOAF.name, extras['publisher_name'])

def test_publisher_org_no_uri(self):
Expand Down Expand Up @@ -478,7 +478,7 @@ def test_publisher_org_no_uri(self):
assert publisher
assert isinstance(publisher, BNode)

assert self._triple(g, publisher, RDF.type, FOAF.Organization)
assert self._triple(g, publisher, RDF.type, FOAF.Agent)
assert self._triple(g, publisher, FOAF.name, extras['publisher_name'])
assert self._triple(g, publisher, FOAF.mbox, extras['publisher_email'])
assert self._triple(g, publisher, FOAF.homepage, URIRef(extras['publisher_url']))
Expand Down

0 comments on commit 2f3fe27

Please sign in to comment.