Skip to content

Commit

Permalink
Use https in schema.org namespace
Browse files Browse the repository at this point in the history
Annoyingly, the croissant validator does not support the
http://schema.org namespace and insists on https

Ref https://schema.org/docs/faq.html#19
  • Loading branch information
amercader committed Jan 30, 2025
1 parent abb73a8 commit 43840bc
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 5 deletions.
10 changes: 8 additions & 2 deletions ckanext/dcat/profiles/croissant.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

from dateutil.parser import parse as parse_date
from rdflib import URIRef, BNode, Literal
from rdflib.namespace import Namespace
from ckantoolkit import url_for, config

from ckanext.dcat.utils import resource_uri
Expand All @@ -16,9 +17,14 @@
CR,
DCT,
RDF,
SCHEMA,
)

# The Croissant validator insists on https and will consider invalid
# output that uses the http namespace

SCHEMA = Namespace("https://schema.org/")


class CroissantProfile(RDFProfile):
"""
An RDF profile based on the schema.org Dataset, modified by Croissant.
Expand Down Expand Up @@ -360,4 +366,4 @@ def _resource_subresources_graph(self, dataset_ref, resource_ref, resource_dict)
]
self._add_list_triples_from_dict(subresource_dict, subresource_ref, items)

self.g.add((subresource_ref, CR.containedIn, resource_ref))
self.g.add((subresource_ref, CR.containedIn, resource_ref))
6 changes: 4 additions & 2 deletions ckanext/dcat/tests/profiles/croissant/test_validate.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,15 @@

def test_valid_output():

dataset_dict = json.loads(get_file_contents("ckan/ckan_full_dataset_croissant.json"))
dataset_dict = json.loads(
get_file_contents("ckan/ckan_full_dataset_croissant.json")
)

s = RDFSerializer(profiles=["croissant"])

s.graph_from_dataset(dataset_dict)

croissant_dict = s.g.serialize(format="json-ld")
croissant_dict = json.loads(s.g.serialize(format="json-ld", auto_compact=True))

try:
mlc.Dataset(croissant_dict)
Expand Down
2 changes: 1 addition & 1 deletion examples/ckan/ckan_full_dataset_croissant.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"id_given": "my-custom-id",
"is_live_dataset": true,
"url": "http://example.org/ds1",
"version": "1.0b",
"version": "1.0.0",
"tags": [
{
"name": "Tag 1"
Expand Down

0 comments on commit 43840bc

Please sign in to comment.