Skip to content

Commit

Permalink
Finish support for qualified relations in all DCAT profiles
Browse files Browse the repository at this point in the history
Fixed RDF type and classes to pass Shacl validation, updated examples
and tests
  • Loading branch information
amercader committed Jan 9, 2025
1 parent 30f3bac commit 97ca441
Show file tree
Hide file tree
Showing 9 changed files with 90 additions and 1 deletion.
5 changes: 4 additions & 1 deletion ckanext/dcat/profiles/euro_dcat_ap_scheming.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
FOAF,
SKOS,
LOCN,
RDFS,
)


Expand Down Expand Up @@ -355,7 +356,7 @@ def _add_relationship(
else:
agent_ref = BNode()

self.g.add((agent_ref, DCT.type, DCAT.Relationship))
self.g.add((agent_ref, RDF.type, DCAT.Relationship))
self.g.add((dataset_ref, rdf_predicate, agent_ref))

self._add_triple_from_dict(
Expand All @@ -364,13 +365,15 @@ def _add_relationship(
DCT.relation,
"relation",
_type=URIRefOrLiteral,
_class=RDFS.Resource,
)
self._add_triple_from_dict(
relation,
agent_ref,
DCAT.hadRole,
"role",
_type=URIRefOrLiteral,
_class=DCAT.Role,
)

@staticmethod
Expand Down
17 changes: 17 additions & 0 deletions ckanext/dcat/schemas/dcat_ap_full.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -268,6 +268,23 @@ dataset_fields:
help_inline: true
help_text: This property refers to a related Dataset that is a version, edition, or adaptation of the described Dataset.

- field_name: qualified_relation
label: Qualified relation
repeating_label: Relationship
repeating_subfields:

- field_name: uri
label: URI

- field_name: relation
label: Relation
help_text: The resource related to the source resource.

- field_name: role
label: Role
help_text: The function of an entity or agent with respect to another entity or resource.
help_text: A description of a relationship with another resource.

#- field_name: hvd_category
# label: HVD Category
# preset: multiple_text
Expand Down
17 changes: 17 additions & 0 deletions ckanext/dcat/schemas/dcat_us_full.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -331,6 +331,23 @@ dataset_fields:
- field_name: license
label: License

- field_name: qualified_relation
label: Qualified relation
repeating_label: Relationship
repeating_subfields:

- field_name: uri
label: URI

- field_name: relation
label: Relation
help_text: The resource related to the source resource.

- field_name: role
label: Role
help_text: The function of an entity or agent with respect to another entity or resource.
help_text: A description of a relationship with another resource.

# Note: if not provided, this will be autogenerated
- field_name: uri
label: URI
Expand Down
22 changes: 22 additions & 0 deletions ckanext/dcat/tests/profiles/dcat_ap_2/test_scheming_support.py
Original file line number Diff line number Diff line change
Expand Up @@ -265,6 +265,17 @@ def test_e2e_ckan_to_dcat(self):
wkt_geom = wkt.dumps(dataset["spatial_coverage"][0]["geom"], decimals=4)
assert self._triple(g, spatial[0][2], LOCN.Geometry, wkt_geom, GSP.wktLiteral)

# Test qualified relation
relation = [t for t in g.triples((dataset_ref, DCAT.qualifiedRelation, None))]
assert len(relation) == 1
relation_items = [
(DCT.relation, URIRef(dataset_dict["qualified_relation"][0]["relation"])),
(DCAT.hadRole, URIRef(dataset_dict["qualified_relation"][0]["role"])),
]
for predicate, value in relation_items:
assert self._triple(
g, relation[0][2], predicate, value
), f"relation Predicate {predicate} does not have value {value}"
# Statements
for item in [
("access_rights", DCT.accessRights),
Expand Down Expand Up @@ -747,6 +758,17 @@ def test_e2e_dcat_to_ckan(self):
)
assert dataset["spatial_coverage"][0]["geom"]

assert len(dataset["qualified_relation"]) == 1
assert (
dataset["qualified_relation"][0]["relation"]
== "http://example.com/dataset/3.141592"
)
assert (
dataset["qualified_relation"][0]["role"]
== "http://www.iana.org/assignments/relation/related"
)


resource = dataset["resources"][0]

# Resources: core fields
Expand Down
3 changes: 3 additions & 0 deletions ckanext/dcat/tests/shacl/test_shacl.py
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,9 @@ def test_validate_dcat_ap_2_graph_shapes_range():
known_failures = [
"Value does not have class skos:Concept",
"Value does not have class dcat:Dataset",
# Qualified relations
"Value does not conform to Shape :DcatResource_Shape. See details for more information.",
"The node is either a Catalog, Dataset or a DataService",
]

assert set(failures) - set(known_failures) == set(), results_text
Expand Down
7 changes: 7 additions & 0 deletions examples/ckan/ckan_full_dataset_dcat_ap.json
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,13 @@
}
],
"spatial_resolution_in_meters": 1.5,
"qualified_relation": [
{
"uri": "",
"relation": "http://example.com/dataset/3.141592",
"role": "http://www.iana.org/assignments/relation/related"
}
],
"resources": [
{
"name": "Resource 1",
Expand Down
7 changes: 7 additions & 0 deletions examples/ckan/ckan_full_dataset_dcat_ap_vocabularies.json
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,13 @@
}
],
"spatial_resolution_in_meters": 1.5,
"qualified_relation": [
{
"uri": "",
"relation": "http://example.com/dataset/3.141592",
"role": "http://www.iana.org/assignments/relation/related"
}
],
"resources": [
{
"name": "Resource 1",
Expand Down
7 changes: 7 additions & 0 deletions examples/ckan/ckan_full_dataset_dcat_us_vocabularies.json
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,13 @@
"license": "https://resources.data.gov/vocab/license/TODO/CC_BYNC_4_0"
}
],
"qualified_relation": [
{
"uri": "",
"relation": "http://example.com/dataset/3.141592",
"role": "http://www.iana.org/assignments/relation/related"
}
],
"resources": [
{
"name": "Resource 1",
Expand Down
6 changes: 6 additions & 0 deletions examples/dcat/dataset.rdf
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,12 @@
</dct:PeriodOfTime>
</dct:temporal>
<dcat:temporalResolution rdf:datatype="http://www.w3.org/2001/XMLSchema#duration">PT15M</dcat:temporalResolution>
<dcat:qualifiedRelation>
<dcat:Relationship>
<dct:relation rdf:resource="http://example.com/dataset/3.141592"/>
<dcat:hadRole rdf:resource="http://www.iana.org/assignments/relation/related"/>
</dcat:Relationship>
</dcat:qualifiedRelation>
<dcat:contactPoint>
<vcard:Organization>
<vcard:fn>Point of Contact</vcard:fn>
Expand Down

0 comments on commit 97ca441

Please sign in to comment.