Skip to content

Commit

Permalink
Fix parsing of statements after #313
Browse files Browse the repository at this point in the history
  • Loading branch information
amercader committed Oct 17, 2024
1 parent 1ea2371 commit 82d8186
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 0 deletions.
2 changes: 2 additions & 0 deletions ckanext/dcat/profiles/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,8 @@ def _object_value(self, subject, predicate):
# Use first object as fallback if no object with the default language is available
elif fallback == "":
fallback = str(o)
elif len(list(self.g.objects(o, RDFS.label))):
return str(next(self.g.objects(o, RDFS.label)))
else:
return str(o)
return fallback
Expand Down
48 changes: 48 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 @@ -790,6 +790,54 @@ def test_e2e_dcat_to_ckan(self):
"http://publications.europa.eu/webapi/rdf/sparql"
]

def test_statement_label(self):
data = """
@prefix dcat: <http://www.w3.org/ns/dcat#> .
@prefix dct: <http://purl.org/dc/terms/> .
@prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> .
<https://example.com/dataset1>
a dcat:Dataset ;
dct:title "Dataset 1" ;
dct:description "This is a dataset" ;
dct:accessRights [
a dct:RightsStatement;
rdfs:label "Some statement"
]
.
"""
p = RDFParser()

p.parse(data, _format="ttl")
datasets = [d for d in p.datasets()]

dataset = datasets[0]

assert dataset["notes"] == "This is a dataset"
assert dataset["access_rights"] == "Some statement"

def test_statement_literal(self):
data = """
@prefix dcat: <http://www.w3.org/ns/dcat#> .
@prefix dct: <http://purl.org/dc/terms/> .
@prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> .
<https://example.com/dataset1>
a dcat:Dataset ;
dct:title "Dataset 1" ;
dct:description "This is a dataset" ;
dct:accessRights "Some statement"
.
"""
p = RDFParser()

p.parse(data, _format="ttl")
datasets = [d for d in p.datasets()]

dataset = datasets[0]

assert dataset["notes"] == "This is a dataset"
assert dataset["access_rights"] == "Some statement"

@pytest.mark.usefixtures("with_plugins", "clean_db", "clean_index")
@pytest.mark.ckan_config("ckan.plugins", "dcat scheming_datasets")
Expand Down

0 comments on commit 82d8186

Please sign in to comment.