Skip to content

Commit

Permalink
Add JSON-LD Context Document for Data Package (#874)
Browse files Browse the repository at this point in the history
* Add JSON-LD Context Document for Data Package

* Update schemas/context/README.md

Co-authored-by: Dan Feder <[email protected]>

---------

Co-authored-by: Dan Feder <[email protected]>
  • Loading branch information
nichtich and dafeder authored Jun 4, 2024
1 parent 6c9a74f commit 2e24c6a
Show file tree
Hide file tree
Showing 6 changed files with 129 additions and 0 deletions.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
"glob": "^7.1.1",
"js-yaml": "^3.13.1",
"json-schema-ref-parser": "^9.0.9",
"jsonld": "^8.3.2",
"markdown-it-footnote": "",
"mermaid": "^9.1.2",
"mocha": "^9.2.2",
Expand Down
11 changes: 11 additions & 0 deletions schemas/context/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
This directory contains non-normative JSON-LD Context Documents to convert Data Package Formats to RDF.

Right now, it only contains a context for Data Package documents.
Properties `resources`, `profile`, and contributor roles are ignored.

Note that the use of POSIX paths will reduce the ability for RDF conversion. In particular:

- property `id`, if given, MUST be a URI
- property `image` with POSIX path will be ignore
- elements with property `path` having a POSIX path value be ignored

45 changes: 45 additions & 0 deletions schemas/context/data-package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
{
"dcat": "http://www.w3.org/ns/dcat#",
"dct": "http://purl.org/dc/terms/",
"foaf": "http://xmlns.com/foaf/0.1/",
"schema": "https://schema.org/",
"prov": "http://www.w3.org/ns/prov#",
"name": "dct:identifier",
"id": "@id",
"licenses": {
"@id": "dct:license",
"@context":{
"name": "dct:identifier",
"title": "dct:title",
"path": "@id"
}
},
"title": "dct:title",
"description": "dct:description",
"homepage": {
"@id": "foaf:homepage",
"@type": "@id"
},
"version": "dct:version",
"sources": {
"@id": "prov:wasDerivedFrom",
"@context": {
"path": "@id",
"title": "foaf:name",
"email": "foaf:mbox"
}
},
"contributors": {
"@id": "dct:contributor",
"@context": {
"title": "foaf:name",
"organization": "schema:affiliation",
"email": "foaf:mbox"
}
},
"keywords": "dcat:keyword",
"image": {
"@id": "foaf:img"
},
"created": "dct:created"
}
33 changes: 33 additions & 0 deletions test/files/data-package-1.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
{
"name": "name-of-package",
"id": "https://example.org/id/1234",
"licenses": [{
"name": "ODC-PDDL-1.0",
"path": "http://opendatacommons.org/licenses/pddl/",
"title": "Open Data Commons Public Domain Dedication and License v1.0"
}],
"title": "A nice title",
"description": "whatever...",
"homepage": "http://example.org",
"version": "1.2.3",
"sources": [{
"title": "Sample Source",
"path": "http://example.org/source",
"email": "[email protected]",
"version": "0.0.1"
}],
"contributors": [{
"title": "Ex Ample",
"email": "[email protected]",
"path": "http://example.org/staff/ex",
"organization": "Acme",
"role": "author"
}],
"keywords": [ "example", "stuff" ],
"image": "http://example.org/image.png",
"created": "1985-04-12T23:20:50.52Z",
"resources": [{
"name": "resource-name",
"path": "http://example.org/resource-path.csv"
}]
}
20 changes: 20 additions & 0 deletions test/files/data-package-1.nt
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<http://example.org/source> <http://purl.org/dc/terms/version> "0.0.1" .
<http://example.org/source> <http://xmlns.com/foaf/0.1/mbox> "[email protected]" .
<http://example.org/source> <http://xmlns.com/foaf/0.1/name> "Sample Source" .
<http://opendatacommons.org/licenses/pddl/> <http://purl.org/dc/terms/identifier> "ODC-PDDL-1.0" .
<http://opendatacommons.org/licenses/pddl/> <http://purl.org/dc/terms/title> "Open Data Commons Public Domain Dedication and License v1.0" .
<https://example.org/id/1234> <http://purl.org/dc/terms/contributor> _:b0 .
<https://example.org/id/1234> <http://purl.org/dc/terms/created> "1985-04-12T23:20:50.52Z" .
<https://example.org/id/1234> <http://purl.org/dc/terms/description> "whatever..." .
<https://example.org/id/1234> <http://purl.org/dc/terms/identifier> "name-of-package" .
<https://example.org/id/1234> <http://purl.org/dc/terms/license> <http://opendatacommons.org/licenses/pddl/> .
<https://example.org/id/1234> <http://purl.org/dc/terms/title> "A nice title" .
<https://example.org/id/1234> <http://purl.org/dc/terms/version> "1.2.3" .
<https://example.org/id/1234> <http://www.w3.org/ns/dcat#keyword> "example" .
<https://example.org/id/1234> <http://www.w3.org/ns/dcat#keyword> "stuff" .
<https://example.org/id/1234> <http://www.w3.org/ns/prov#wasDerivedFrom> <http://example.org/source> .
<https://example.org/id/1234> <http://xmlns.com/foaf/0.1/homepage> <http://example.org> .
<https://example.org/id/1234> <http://xmlns.com/foaf/0.1/img> "http://example.org/image.png" .
_:b0 <http://xmlns.com/foaf/0.1/mbox> "[email protected]" .
_:b0 <http://xmlns.com/foaf/0.1/name> "Ex Ample" .
_:b0 <https://schema.org/affiliation> "Acme" .
19 changes: 19 additions & 0 deletions test/rdf.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
const util = require('util')
const readFile = util.promisify(require('fs').readFile)
const {assert} = require('chai')
const jsonld = require('jsonld')

const toRDF = async file => {
const doc = require(file)
doc["@context"] = require("../schemas/context/data-package.json")
const triples = await jsonld.toRDF(doc, {format: 'application/n-quads'})
return triples.split("\n").sort().filter(Boolean).join("\n")+"\n"
}

describe('rdf', () => {
it('data-package', async () => {
const rdf = await toRDF('./files/data-package-1.json')
const nt = await readFile('test/files/data-package-1.nt', 'utf-8')
assert.equal(rdf, nt)
})
})

0 comments on commit 2e24c6a

Please sign in to comment.