Skip to content

Commit 8786cc0

Browse files
committed
Provide default language in Croissant JSON-LD context
This was to fixed failures caused by the new version of the croissant package (introduced by mlcommons/croissant#932), but it seems like a good thing to do anyway. Sadly this means that the output generated from rdflib changes, from this: ``` "description": "Test description" ``` to this: ``` "description": { "@value": "Test description" } ``` While this is a bit less human readable is perfectly valid JSON-LD, and it will probably align better with multilingual metadata.
1 parent be3c8d6 commit 8786cc0

3 files changed

Lines changed: 10 additions & 7 deletions

File tree

ckanext/dcat/helpers.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ def structured_data(dataset_dict, profiles=None):
7272
return _get_serialization(dataset_dict, profiles, "jsonld")
7373

7474

75-
def croissant(dataset_dict, profiles=None):
75+
def croissant(dataset_dict, profiles=None, jsonld_context=None):
7676
"""
7777
Returns a string containing the Croissant ML representation of the given
7878
dataset using the `croissant` profile.
@@ -82,8 +82,10 @@ def croissant(dataset_dict, profiles=None):
8282
if not profiles:
8383
profiles = config.get("ckanext.dcat.croissant.profiles", ["croissant"])
8484

85-
frame = {"@context": JSONLD_CONTEXT, "@type": "sc:Dataset"}
85+
context = jsonld_context or JSONLD_CONTEXT
86+
87+
frame = {"@context": context, "@type": "sc:Dataset"}
8688

8789
return _get_serialization(
88-
dataset_dict, profiles, "jsonld", context=JSONLD_CONTEXT, frame=frame
90+
dataset_dict, profiles, "jsonld", context=context, frame=frame
8991
)

ckanext/dcat/profiles/croissant.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424

2525
JSONLD_CONTEXT = {
2626
"@vocab": "https://schema.org/",
27+
"@language": config.get("ckan.locale_default"),
2728
"sc": "https://schema.org/",
2829
"cr": "http://mlcommons.org/croissant/",
2930
"rai": "http://mlcommons.org/croissant/RAI/",

ckanext/dcat/tests/test_blueprints.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -612,8 +612,8 @@ def test_croissant_metadata_embedded(self, app):
612612
response = app.get(url)
613613

614614
assert '<script type="application/ld+json">' in response.body
615-
assert '"description": "test description"' in response.body
616-
assert '"conformsTo": "http://mlcommons.org/croissant/1.0"' in response.body
615+
assert '"@value": "test description"' in response.body
616+
assert '"@value": "http://mlcommons.org/croissant/1.0"' in response.body
617617

618618
@pytest.mark.ckan_config('ckan.plugins', 'dcat croissant')
619619
def test_croissant_metadata_endpoint(self, app):
@@ -627,8 +627,8 @@ def test_croissant_metadata_endpoint(self, app):
627627
response = app.get(url)
628628
croissant_dict = json.loads(response.body)
629629

630-
assert croissant_dict["description"] == "test description"
631-
assert croissant_dict["conformsTo"] == "http://mlcommons.org/croissant/1.0"
630+
assert croissant_dict["description"] == {"@value": "test description"}
631+
assert croissant_dict["conformsTo"] == {"@value": "http://mlcommons.org/croissant/1.0"}
632632

633633

634634
@pytest.mark.usefixtures("with_plugins", "clean_db", "clean_index")

0 commit comments

Comments
 (0)