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

Stub of random datacrate generator

parent 4f1437e2
Branches
Tags
No related merge requests found
...@@ -60,6 +60,10 @@ const DEFAULT_IRI_PREFS = { ...@@ -60,6 +60,10 @@ const DEFAULT_IRI_PREFS = {
}; };
// TODO - a general function for minting new internal IRIs given one
// of the above prefixes ()
// dataset -> about -> subjects // dataset -> about -> subjects
// dataset -> spatialCoverage -> place // dataset -> spatialCoverage -> place
// dataset -> temporalCoverage -> time // dataset -> temporalCoverage -> time
...@@ -181,17 +185,15 @@ async function datapub2catalog(options) { ...@@ -181,17 +185,15 @@ async function datapub2catalog(options) {
// this isn't working with trim_context, which is clobbering the // this isn't working with trim_context, which is clobbering the
// geojson types for reasons I don't understand - see PT // geojson types for reasons I don't understand - see PT
// if( datapub['geospatial'] ) { if( datapub['geospatial'] ) {
// console.log("datapub has geospatial"); const geocontext = await fs.readJson(GEOCONTEXT);
// const geocontext = await fs.readJson(GEOCONTEXT); Object.keys(geocontext['@context']).map((k) => {
// Object.keys(geocontext['@context']).map((k) => { if( context[k] ) {
// if( context[k] ) { console.error("Duplicate geocontext for " + k);
// console.error("Duplicate geocontext for " + k); }
// } context[k] = geocontext[k];
// context[k] = geocontext[k]; })
// }) }
// console.log(JSON.stringify(context, null, 2));
// }
const catalog = { const catalog = {
'@context': context, '@context': context,
...@@ -222,6 +224,7 @@ function link_id(item) { ...@@ -222,6 +224,7 @@ function link_id(item) {
return { '@id': item['@id'] }; return { '@id': item['@id'] };
} }
// TODO: isBasedOn the data record // TODO: isBasedOn the data record
function make_dataset(id, datapub, organisation, dates, files) { function make_dataset(id, datapub, organisation, dates, files) {
...@@ -452,7 +455,8 @@ function make_spatial(datapub, prefix) { ...@@ -452,7 +455,8 @@ function make_spatial(datapub, prefix) {
var items = []; var items = [];
var i = 1; var i = 1;
if( datapub['geolocations'] ) { if( datapub['geolocations'] ) {
items = datapub['geolocations'].map((gl) => { const geols = datapub['geolocations'].filter((g) => !_.isEmpty(g));
items = geols.map((gl) => {
const id = prefix + String(i); const id = prefix + String(i);
i += 1; i += 1;
return { return {
...@@ -468,7 +472,7 @@ function make_spatial(datapub, prefix) { ...@@ -468,7 +472,7 @@ function make_spatial(datapub, prefix) {
} }
}); });
} }
if( datapub['geospatial'] ) { if( datapub['geospatial'] && datapub['geospatial']['type'] ) {
// 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/
// Upstairs, the code that calls this checks for a geospatial // Upstairs, the code that calls this checks for a geospatial
...@@ -523,19 +527,29 @@ function make_temporal(datapub) { ...@@ -523,19 +527,29 @@ function make_temporal(datapub) {
function make_license(datapub, prefix) { function make_license(datapub, prefix) {
if( datapub['license_other_url'] ) { const license = [];
return [{ if( datapub['license_other_url'] || datapub['license_notes'] ) {
'@id': datapub['license_other_url'], if( datapub['license_other_url'] );
'type': 'CreativeWork', licenses.push({
'name': datapub['license_notes'] '@id': datapub['license_other_url'],
}]; '@type': 'CreativeWork',
'url': datapub['license_other_url'],
'name': ( datapub['license_notes'] || datapub['license_other_url'])
});
} else {
licenses.push({
'@id': DEFAULT_IRI_PREFS['licenses'] + 'other',
'@type': 'CreativeWork',
'name': datapub['license_notes']
});
}
} }
if( datapub['license_statement'] ) { if( datapub['license_identifier'] ) {
return [{ licenses.push({
'@id': datapub['license_identifier'], '@id': datapub['license_identifier'],
'type': 'CreativeWork', '@type': 'CreativeWork',
'name': datapub['license_statement'], 'name': datapub['license_identifier'],
'url': datapub['license_statement_url'] 'url': datapub['license_identifier']
}]; }];
} }
return []; return [];
......
// Module to generate a bunch of CATALOG.json files which
// have arbitrary but realistic data
...@@ -53,7 +53,7 @@ const ORG = { ...@@ -53,7 +53,7 @@ const ORG = {
'name': 'University of Technology Sydney' 'name': 'University of Technology Sydney'
}; };
const ALLOW_BAD_TYPES = { 'FeatureCollection': true }; 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
......
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