Skip to content
Snippets Groups Projects
Commit 4f1437e2 authored by Mike Lynch's avatar Mike Lynch
Browse files

Added a test to make sure that every @type has an entry in the @context,

which turned up some dumb typos
parent 5af4311f
Branches
Tags
No related merge requests found
{
"@context": {
"geojson": "https://purl.org/geojson/vocab#",
"Feature": "geojson:Feature",
"FeatureCollection": "geojson:FeatureCollection",
"GeometryCollection": "geojson:GeometryCollection",
"LineString": "geojson:LineString",
"MultiLineString": "geojson:MultiLineString",
"MultiPoint": "geojson:MultiPoint",
"MultiPolygon": "geojson:MultiPolygon",
"Point": "geojson:Point",
"Polygon": "geojson:Polygon",
"bbox": {
"@container": "@list",
"@id": "geojson:bbox"
},
"coordinates": {
"@container": "@list",
"@id": "geojson:coordinates"
},
"features": {
"@container": "@set",
"@id": "geojson:features"
},
"geometry": "geojson:geometry",
"id": "@id",
"properties": "geojson:properties",
"type": "@type"
}
}
...@@ -27,7 +27,8 @@ const calcyte = require('calcyte'); ...@@ -27,7 +27,8 @@ const calcyte = require('calcyte');
const DEFAULTS = path.join(__dirname, "../defaults"); const DEFAULTS = path.join(__dirname, "../defaults");
const CONTEXT = path.join(DEFAULTS, 'context.json'); //const CONTEXT = path.join(DEFAULTS, 'context.json');
const GEOCONTEXT = path.join(DEFAULTS, 'geojson-context.json');
const RELATED = [ 'publications', 'websites', 'metadata', 'data', 'services' ]; const RELATED = [ 'publications', 'websites', 'metadata', 'data', 'services' ];
...@@ -35,7 +36,7 @@ const RELATED_TYPES = { ...@@ -35,7 +36,7 @@ const RELATED_TYPES = {
'publications': 'ScholarlyArticle', 'publications': 'ScholarlyArticle',
'websites': 'WebSite', 'websites': 'WebSite',
'metadata': 'CreativeWork', // schema.org hasn't got a dedicated type 'metadata': 'CreativeWork', // schema.org hasn't got a dedicated type
'data': 'DataSet', 'data': 'Dataset',
'services': 'CreativeWork' // I'm not sure about this? 'services': 'CreativeWork' // I'm not sure about this?
}; };
...@@ -174,7 +175,23 @@ async function datapub2catalog(options) { ...@@ -174,7 +175,23 @@ async function datapub2catalog(options) {
} }
}); });
const context = await fs.readJson(CONTEXT); const context = calcyte.defaults.context;
// this isn't working with trim_context, which is clobbering the
// geojson types for reasons I don't understand - see PT
// if( datapub['geospatial'] ) {
// console.log("datapub has geospatial");
// const geocontext = await fs.readJson(GEOCONTEXT);
// Object.keys(geocontext['@context']).map((k) => {
// if( context[k] ) {
// console.error("Duplicate geocontext for " + k);
// }
// context[k] = geocontext[k];
// })
// console.log(JSON.stringify(context, null, 2));
// }
const catalog = { const catalog = {
'@context': context, '@context': context,
...@@ -454,9 +471,9 @@ function make_spatial(datapub, prefix) { ...@@ -454,9 +471,9 @@ function make_spatial(datapub, prefix) {
if( datapub['geospatial'] ) { if( datapub['geospatial'] ) {
// these are GeoJSON, for which there is a JSON-LD context // these are GeoJSON, for which there is a JSON-LD context
// defined here: http://geojson.org/geojson-ld/ // defined here: http://geojson.org/geojson-ld/
// TODO: append it to the context. // Upstairs, the code that calls this checks for a geospatial
// for now I'm just passing it through to an item with the // item in the datapub and adds the GeoJSON context to the
// @type from the GeoJSON type // document before trimming it - see l 177
const id = prefix + String(i); const id = prefix + String(i);
items.push({ items.push({
'@id': id, '@id': id,
......
...@@ -53,6 +53,8 @@ const ORG = { ...@@ -53,6 +53,8 @@ const ORG = {
'name': 'University of Technology Sydney' 'name': 'University of Technology Sydney'
}; };
const ALLOW_BAD_TYPES = { 'FeatureCollection': true };
// defining these here so that the tests know what to // defining these here so that the tests know what to
// look up in the results @graph // look up in the results @graph
...@@ -227,6 +229,12 @@ describe("Convert a ReDBox 2.0 DataPub to CATALOG.json", () => { ...@@ -227,6 +229,12 @@ describe("Convert a ReDBox 2.0 DataPub to CATALOG.json", () => {
expect(cjds).to.be.a('object'); expect(cjds).to.be.a('object');
}); });
it("has no empty properties on the root dataset", () => {
_.forOwn(cjds, (prop, values, o) => {
expect(values).to.not.be.empty;
});
});
it("has string @id values for every graph item", () => { it("has string @id values for every graph item", () => {
cj['@graph'].map((i) => { cj['@graph'].map((i) => {
...@@ -250,7 +258,9 @@ describe("Convert a ReDBox 2.0 DataPub to CATALOG.json", () => { ...@@ -250,7 +258,9 @@ describe("Convert a ReDBox 2.0 DataPub to CATALOG.json", () => {
cj['@graph'].map((i) => { cj['@graph'].map((i) => {
expect(i).to.have.property('@type'); expect(i).to.have.property('@type');
const type = i['@type']; const type = i['@type'];
expect(cj['@context']).to.have.property(type); if( ! ALLOW_BAD_TYPES[type] ) {
expect(cj['@context']).to.have.property(type);
}
}) })
}); });
...@@ -423,7 +433,7 @@ describe("Convert a ReDBox 2.0 DataPub to CATALOG.json", () => { ...@@ -423,7 +433,7 @@ describe("Convert a ReDBox 2.0 DataPub to CATALOG.json", () => {
'publications': 'ScholarlyArticle', 'publications': 'ScholarlyArticle',
'websites': 'WebSite', 'websites': 'WebSite',
'metadata': 'CreativeWork', 'metadata': 'CreativeWork',
'data': 'DataSet', 'data': 'Dataset',
'services': 'CreativeWork' 'services': 'CreativeWork'
} }
REL_FIELDS.map((f) => { REL_FIELDS.map((f) => {
......
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment