diff --git a/package.json b/package.json index 625b6f5c..feb3d744 100644 --- a/package.json +++ b/package.json @@ -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", diff --git a/schemas/context/README.md b/schemas/context/README.md new file mode 100644 index 00000000..4ec5b35e --- /dev/null +++ b/schemas/context/README.md @@ -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 + diff --git a/schemas/context/data-package.json b/schemas/context/data-package.json new file mode 100644 index 00000000..3aefe281 --- /dev/null +++ b/schemas/context/data-package.json @@ -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" +} diff --git a/test/files/data-package-1.json b/test/files/data-package-1.json new file mode 100644 index 00000000..863bc82a --- /dev/null +++ b/test/files/data-package-1.json @@ -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": "archive@example.org", + "version": "0.0.1" + }], + "contributors": [{ + "title": "Ex Ample", + "email": "ex@example.org", + "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" + }] +} diff --git a/test/files/data-package-1.nt b/test/files/data-package-1.nt new file mode 100644 index 00000000..c88c14d0 --- /dev/null +++ b/test/files/data-package-1.nt @@ -0,0 +1,20 @@ + "0.0.1" . + "archive@example.org" . + "Sample Source" . + "ODC-PDDL-1.0" . + "Open Data Commons Public Domain Dedication and License v1.0" . + _:b0 . + "1985-04-12T23:20:50.52Z" . + "whatever..." . + "name-of-package" . + . + "A nice title" . + "1.2.3" . + "example" . + "stuff" . + . + . + "http://example.org/image.png" . +_:b0 "ex@example.org" . +_:b0 "Ex Ample" . +_:b0 "Acme" . diff --git a/test/rdf.js b/test/rdf.js new file mode 100644 index 00000000..5d06b1f9 --- /dev/null +++ b/test/rdf.js @@ -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) + }) +})