Skip to content

Commit

Permalink
Merge pull request #159 from GovDataOfficial/jsonld-catalogs-with-at-…
Browse files Browse the repository at this point in the history
…graph

Support JSON-LD catalogs with @graph
  • Loading branch information
amercader authored Jul 12, 2019
2 parents 0588ff4 + b22aba2 commit 15b73fa
Show file tree
Hide file tree
Showing 3 changed files with 93 additions and 1 deletion.
2 changes: 1 addition & 1 deletion ckanext/dcat/processors.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ def __init__(self, profiles=None, compatibility_mode=False):
config.get(COMPAT_MODE_CONFIG_OPTION, False))
self.compatibility_mode = compatibility_mode

self.g = rdflib.Graph()
self.g = rdflib.ConjunctiveGraph()

def _load_profiles(self, profile_names):
'''
Expand Down
29 changes: 29 additions & 0 deletions ckanext/dcat/tests/test_euro_dcatap_profile_parse.py
Original file line number Diff line number Diff line change
Expand Up @@ -652,6 +652,35 @@ def test_dataset_json_ld_1(self):
eq_(resource['url'], u'https://data.agency.gov/datasets/widgets-statistics/widgets.csv')
eq_(resource['download_url'], u'https://data.agency.gov/datasets/widgets-statistics/widgets.csv')

def test_dataset_json_ld_with_at_graph(self):

contents = self._get_file_contents('catalog_with_at_graph.jsonld')

p = RDFParser(profiles=['euro_dcat_ap'])

p.parse(contents, _format='json-ld')

datasets = [d for d in p.datasets()]

eq_(len(datasets), 1)

dataset = datasets[0]
extras = dict((e['key'], e['value']) for e in dataset['extras'])

eq_(dataset['title'], 'Title dataset')

eq_(extras['contact_name'], 'Jane Doe')
# mailto gets removed for storage and is added again on output
eq_(extras['contact_email'], 'jane.doe@agency.gov')

eq_(len(dataset['resources']), 1)

resource = dataset['resources'][0]
eq_(resource['name'], u'download.zip')
eq_(resource['url'], u'http://example2.org/files/download.zip')
eq_(resource['access_url'], u'https://ckan.example.org/dataset/d4ce4e6e-ab89-44cb-bf5c-33a162c234de/resource/a289c289-55c9-410f-b4c7-f88e5f6f4e47')
eq_(resource['download_url'], u'http://example2.org/files/download.zip')

def test_dataset_compatibility_mode(self):

contents = self._get_file_contents('dataset.rdf')
Expand Down
63 changes: 63 additions & 0 deletions examples/catalog_with_at_graph.jsonld
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
{
"@context": {
"dcat": "http://www.w3.org/ns/dcat#",
"dcterms": "http://purl.org/dc/terms/",
"foaf": "http://xmlns.com/foaf/0.1/",
"rdf": "http://www.w3.org/1999/02/22-rdf-syntax-ns#",
"rdfs": "http://www.w3.org/2000/01/rdf-schema#",
"vcard": "http://www.w3.org/2006/vcard/ns#",
"xsd": "http://www.w3.org/2001/XMLSchema#"
},
"@graph": [
{
"@id": "https://example.org#catalog",
"@type": "dcat:Catalog",
"dcat:dataset": {
"@id": "https://ckan.example.org/dataset/d4ce4e6e-ab89-44cb-bf5c-33a162c234de#dataset"
},
"dcterms:description": "Description example.org",
"dcterms:publisher": {
"@id": "https://www.example.org/impressum#publisher"
},
"dcterms:title": "Title example.org"
},
{
"@id": "https://www.example.org/impressum#publisher",
"@type": "foaf:Organization",
"foaf:name": "Organization example.org"
},
{
"@id": "https://ckan.example.org/dataset/d4ce4e6e-ab89-44cb-bf5c-33a162c234de#dataset",
"@type": "dcat:Dataset",
"dcat:contactPoint": {
"@id": "_:ub1365bL31C21"
},
"dcat:distribution": {
"@id": "https://ckan.example.org/dataset/d4ce4e6e-ab89-44cb-bf5c-33a162c234de/resource/a289c289-55c9-410f-b4c7-f88e5f6f4e47#distribution"
},
"dcterms:description": "Description distribution",
"dcterms:title": "Title dataset"
},
{
"@id": "_:ub1365bL31C21",
"@type": "vcard:Individual",
"vcard:fn": "Jane Doe",
"vcard:hasEmail": "mailto:jane.doe@agency.gov",
"vcard:hasTelephone": "+49 40 123 45678"
},
{
"@id": "https://ckan.example.org/dataset/d4ce4e6e-ab89-44cb-bf5c-33a162c234de/resource/a289c289-55c9-410f-b4c7-f88e5f6f4e47#distribution",
"@type": "dcat:Distribution",
"dcterms:title": "download.zip",
"dcat:accessURL": {
"@id": "https://ckan.example.org/dataset/d4ce4e6e-ab89-44cb-bf5c-33a162c234de/resource/a289c289-55c9-410f-b4c7-f88e5f6f4e47"
},
"dcat:downloadURL": {
"@id": "http://example2.org/files/download.zip"
},
"dcterms:license": {
"@id": "http://www.opendefinition.org/licenses/cc-zero"
}
}
]
}

0 comments on commit 15b73fa

Please sign in to comment.