Commit 62681ed3 authored by PTSEFTON's avatar PTSEFTON
Browse files

Ckeaniung up demos

parents 7f420ea0 1ba0cd70
...@@ -174,6 +174,8 @@ if (program.generateHtml) { ...@@ -174,6 +174,8 @@ if (program.generateHtml) {
"encodingFormat": "zip" "encodingFormat": "zip"
} }
) )
// Reinitialize the helper object as we have added to the JSON
json_helper.init(json_helper.json_ld);
} }
json_helper.trim_context() json_helper.trim_context()
fs.writeFileSync(path.join(c.dir, defaults.catalog_json_file_name), JSON.stringify(json_helper.json_ld, null, 2 )) fs.writeFileSync(path.join(c.dir, defaults.catalog_json_file_name), JSON.stringify(json_helper.json_ld, null, 2 ))
......
...@@ -70,9 +70,7 @@ module.exports = function() { ...@@ -70,9 +70,7 @@ module.exports = function() {
item_json["TYPE:"] = "Dataset"; item_json["TYPE:"] = "Dataset";
item_json["path"] = collection.rel_path; item_json["path"] = collection.rel_path;
if (!(collection.rel_path === "./")) { if (!(collection.rel_path === "./")) {
//console.log("Setting dataset based on path");
item_json["ID"] = collection.rel_path; item_json["ID"] = collection.rel_path;
//item_json["TYPE:"] = "Dataset";
} else if (!item_json["ID"]) { } else if (!item_json["ID"]) {
item_json["ID"] = collection.rel_path; item_json["ID"] = collection.rel_path;
} }
...@@ -134,7 +132,7 @@ module.exports = function() { ...@@ -134,7 +132,7 @@ module.exports = function() {
}, },
index_graph: function index_graph() { index_graph: function index_graph() {
// TODO - PUT THIS IN A HELPER MODULE // TODO - REMOVE this - we now have a helper for this stuff
this.item_by_id = {}; this.item_by_id = {};
this.item_by_path = {}; this.item_by_path = {};
this.item_by_type = {}; this.item_by_type = {};
......
...@@ -21,7 +21,8 @@ var ejs = require("ejs"); ...@@ -21,7 +21,8 @@ var ejs = require("ejs");
context = require("../defaults/context.json"); context = require("../defaults/context.json");
const path = require("path"); const path = require("path");
const shell = require("shelljs"); const shell = require("shelljs");
const jsonld = require("jsonld"); const jsonld_helper = require("./jsonldhelper")
var helper = new jsonld_helper();
const filesize = require("filesize"); const filesize = require("filesize");
const display_keys = [ const display_keys = [
"name", "name",
...@@ -77,7 +78,7 @@ module.exports = function () { ...@@ -77,7 +78,7 @@ module.exports = function () {
) { ) {
// Item is the thing we're displaying // Item is the thing we're displaying
// K is for Key - ie the property name // K is for Key - ie the property name
// list is the list of values for propery k in item // list is the list of values for property k in item
// details: bool - are we doing pagination? If so need to display the "details element" // details: bool - are we doing pagination? If so need to display the "details element"
var l = list.length; var l = list.length;
var html = ""; var html = "";
...@@ -275,6 +276,10 @@ module.exports = function () { ...@@ -275,6 +276,10 @@ module.exports = function () {
} }
}, },
format_property: function format_property(item, k, part) { format_property: function format_property(item, k, part) {
/*
TODO: Work out *my* path
*/
var td_ele = ""; var td_ele = "";
if (!part) { if (!part) {
...@@ -452,10 +457,18 @@ module.exports = function () { ...@@ -452,10 +457,18 @@ module.exports = function () {
dataset_to_html: function dataset_to_html(node) { dataset_to_html: function dataset_to_html(node) {
// Turns any item into an HTML table // Turns any item into an HTML table
//console.log("Processing dataset", node["@id"]); console.log("Processing dataset", node["@id"]);
var path = "pairtree" + node["@id"].replace(/(..)/g, "/$1");
console.log(path)
var html = ""; var html = "";
var keys = new Set(Object.keys(node)); var keys = new Set(Object.keys(node));
keys.delete("identifier"); if (node["identifier"]) {
node["identifier"] = helper.value_as_array(node["identifier"]).filter(id => id != node["@id"]);
if (node["identifier"].length === 0) {
keys.delete("identifier")
}
}
keys.delete("@id"); keys.delete("@id");
keys.delete("filename"); keys.delete("filename");
if (keys.has("encodingFormat")) { if (keys.has("encodingFormat")) {
......
...@@ -23,6 +23,11 @@ const context = require("../defaults/context.json"); ...@@ -23,6 +23,11 @@ const context = require("../defaults/context.json");
const metadata_property_name = require("./property.js"); const metadata_property_name = require("./property.js");
const uuidv4 = require("uuid/v4"); const uuidv4 = require("uuid/v4");
const ejs = require("ejs"); const ejs = require("ejs");
const jsonld = require("../lib/jsonldhelper.js");
const helper = new jsonld()
module.exports = function() { module.exports = function() {
this.metadata = {}; this.metadata = {};
this.json_ld = {}; this.json_ld = {};
...@@ -113,7 +118,15 @@ module.exports = function() { ...@@ -113,7 +118,15 @@ module.exports = function() {
if (this.collection.bagged && frag.path) { if (this.collection.bagged && frag.path) {
frag.path = path.join("data", frag.path); frag.path = path.join("data", frag.path);
} }
this.json_ld_fragment = frag; var ident = helper.value_as_array(this.id)
for (let id of ident){
if (id && id.match(/(https?:\/\/)(dx\.)?(doi.org\/10\.)/i)) {
helper.push_value(frag, "identifier", id.replace(/https?:\/\//i, ""))
}
this.json_ld_fragment = frag;
}
//console.log(frag); //console.log(frag);
return frag; return frag;
}, },
...@@ -136,6 +149,10 @@ module.exports = function() { ...@@ -136,6 +149,10 @@ module.exports = function() {
//console.log("FILE ", this.collection.path, value); //console.log("FILE ", this.collection.path, value);
this.id = path.join(this.collection.rel_path, value); this.id = path.join(this.collection.rel_path, value);
this.types.push("File"); this.types.push("File");
var pr = new metadata_property_name();
pr.parse("path", this.id);
this.properties[pr.name] = pr;
this.is_file = value; this.is_file = value;
} else if (property.is_id) { } else if (property.is_id) {
//console.log("Got an ID", value); //console.log("Got an ID", value);
......
...@@ -87,14 +87,28 @@ module.exports = function () { ...@@ -87,14 +87,28 @@ module.exports = function () {
}, },
value_as_array: function (value) { value_as_array: function (value) {
if (!Array.isArray(value)) { if (!value) {
return []
}
else if (!Array.isArray(value)) {
return [value]; return [value];
console.log("Making array", key, item[key])
} else { } else {
return value; return value;
} }
}, },
push_value: function(item, key, value) {
if (item[key]) {
if (!Array.isArray(item[key])) {
item[key] = [item[key]]
}
item[key].push(value)
}
else {
item[key] = [value]
}
},
init: function init(json) { init: function init(json) {
this.json_ld = json; this.json_ld = json;
this.item_by_id = {}; this.item_by_id = {};
......
...@@ -52,6 +52,8 @@ describe("Test helper functions", function() { ...@@ -52,6 +52,8 @@ describe("Test helper functions", function() {
"./test/test_output/index.html", "./test/test_output/index.html",
true true
); );
assert.equal( assert.equal(
index_maker.get_href("http://dx.doi.org/10.5281/zenodo.1009240"), index_maker.get_href("http://dx.doi.org/10.5281/zenodo.1009240"),
"../CATALOG.html" "../CATALOG.html"
......
...@@ -66,6 +66,24 @@ describe("Create nested item", function() { ...@@ -66,6 +66,24 @@ describe("Create nested item", function() {
assert.equal(j1["creator"]["@id"], "http://orcid.org/0000-0002-3545-944X"); assert.equal(j1["creator"]["@id"], "http://orcid.org/0000-0002-3545-944X");
//assert(Object.is(c.collection_metadata, {} )); //assert(Object.is(c.collection_metadata, {} ));
t1.load_json(
{
"contactPoint>TYPE:ContactPoint>":
"Email: someone@somewhere.com"
},
new Collection()
);
assert.equal(t1.nested_items["contactPoint"].types[0], "ContactPoint");
assert.equal(
t1.nested_items["contactPoint"].name,
"Email: someone@somewhere.com"
);
j1 = t1.to_json_ld_fragment();
assert.equal(j1["contactPoint"]["@type"][0], "ContactPoint");
assert.equal(j1["contactPoint"]["email"], "someone@somewhere.com");
t1.load_json( t1.load_json(
{ {
"geo>TYPE:GeoCoordinates>": "geo>TYPE:GeoCoordinates>":
...@@ -87,6 +105,7 @@ describe("Create nested item", function() { ...@@ -87,6 +105,7 @@ describe("Create nested item", function() {
done(); done();
}); });
}); });
describe("Create simple item", function() { describe("Create simple item", function() {
it("Should create an empty metadata set", function(done) { it("Should create an empty metadata set", function(done) {
var t1 = new Item(); var t1 = new Item();
......
{
"@context": {
"URL": "http://schema.org/URL",
"description": "http://schema.org/description",
"name": "http://schema.org/name",
"email": "http://schema.org/email",
"familyName": "http://schema.org/familyName",
"givenName": "http://schema.org/givenName",
"identifier": "http://schema.org/identifier",
"path": "http://schema.org/contentUrl",
"hasPart": "http://schema.org/hasPart",
"contentSize": "http://schema.org/contentSize",
"encodingFormat": "http://schema.org/encodingFormat",
"fileFormat": "http://schema.org/fileFormat",
"creator": "http://schema.org/creator",
"license": "http://schema.org/license",
"latitude": "http://schema.org/latitude",
"longitude": "http://schema.org/longitude",
"address": "http://schema.org/address",
"geo": "http://schema.org/geo",
"contentLocation": "http://schema.org/contentLocation",
"datePublished": "http://schema.org/datePublished",
"publisher": "http://schema.org/publisher",
"contactPoint": "http://schema.org/contactPoint",
"Person": "http://schema.org/Person",
"Dataset": "http://schema.org/Dataset",
"File": "http://schema.org/MediaObject",
"GeoCoordinates": "http://schema.org/GeoCoordinates",
"Place": "http://schema.org/Place",
"CreativeWork": "http://schema.org/CreativeWork",
"Organization": "http://schema.org/Organization"
},
"@graph": [
{
"@id": "0d2ae8dc-db25-433c-8129-eb1c675ecd78",
"@type": "Format",
"URL": "https://survex.com/docs/manual/datafile.htm",
"description": "Survex is a multi-platform open-source cave surveying package.",
"extension": ".svx",
"mime": "text/plain",
"name": "Survex file"
},
{
"@id": "Keir Vaughan-Taylor",
"@type": "Person",
"email": "keir@example.com",
"familyName": "Vaughan-Taylor",
"givenName": "Keir",
"identifier": "Keir Vaughan-Taylor",
"name": "Keir Vaughan-Taylor"
},
{
"@id": "asf",
"@type": "Dataset",
"path": "asf",
"hasPart": [
{
"@id": "asf/README.txt"
},
{
"@id": "asf/asf3.svx"
},
{
"@id": "asf/asf4.svx"
},
{
"@id": "asf/asf5.svx"
},
{
"@id": "asf/asf6.svx"
},
{
"@id": "asf/asf7.svx"
},
{
"@id": "asf/asf8.svx"
},
{
"@id": "asf/CATALOG_asf.xlsx"
}
],
"identifier": "asf"
},
{
"@id": "asf/CATALOG_asf.xlsx",
"@type": "File",
"*MISSING-FILE": "1",
"contentSize": "16937",
"encodingFormat": "Microsoft Excel Non-XML Binary Workbook",
"fileFormat": "http://www.nationalarchives.gov.uk/PRONOM/fmt/595",
"filename": [],
"name": "asf/CATALOG_asf.xlsx"
},
{
"@id": "asf/README.txt",
"@type": "File",
"contentSize": "401",
"encodingFormat": "Plain Text File",
"fileFormat": "http://www.nationalarchives.gov.uk/PRONOM/x-fmt/111",
"filename": [],
"name": "asf/README.txt"
},
{
"@id": "asf/asf3.svx",
"@type": "File",
"contentSize": "406",
"encodingFormat": "Plain Text File",
"fileFormat": "http://www.nationalarchives.gov.uk/PRONOM/x-fmt/111",
"filename": [],
"name": "asf/asf3.svx"
},
{
"@id": "asf/asf4.svx",
"@type": "File",
"contentSize": "386",
"encodingFormat": "Plain Text File",
"fileFormat": "http://www.nationalarchives.gov.uk/PRONOM/x-fmt/111",
"filename": [],
"name": "asf/asf4.svx"
},
{
"@id": "asf/asf5.svx",
"@type": "File",
"contentSize": "390",
"encodingFormat": "Plain Text File",
"fileFormat": "http://www.nationalarchives.gov.uk/PRONOM/x-fmt/111",
"filename": [],
"name": "asf/asf5.svx"
},
{
"@id": "asf/asf6.svx",
"@type": "File",
"contentSize": "400",
"encodingFormat": "Plain Text File",
"fileFormat": "http://www.nationalarchives.gov.uk/PRONOM/x-fmt/111",
"filename": [],
"name": "asf/asf6.svx"
},
{
"@id": "asf/asf7.svx",
"@type": "File",
"contentSize": "402",
"encodingFormat": "Plain Text File",
"fileFormat": "http://www.nationalarchives.gov.uk/PRONOM/x-fmt/111",
"filename": [],
"name": "asf/asf7.svx"
},
{
"@id": "asf/asf8.svx",
"@type": "File",
"contentSize": "418",
"encodingFormat": "Plain Text File",
"fileFormat": "http://www.nationalarchives.gov.uk/PRONOM/x-fmt/111",
"filename": [],
"name": "asf/asf8.svx"
},
{
"@id": "cp7glop.ai",
"@type": "File",
"contentSize": "383766",
"creator": {
"@id": "http://orcid.org/0000-0003-4953-9114"
},
"description": "Illustrator file for Glop Pot",
"encodingFormat": "Acrobat PDF 1.5 - Portable Document Format",
"fileFormat": "http://www.nationalarchives.gov.uk/PRONOM/fmt/19",
"filename": [],
"license": {
"@id": "https://creativecommons.org/licenses/by/3.0/au/"
},
"name": "cp7glop.ai"
},
{
"@id": "cp7glop.svx",
"@type": "File",
"contentSize": "2058",
"creator": {
"@id": "http://orcid.org/0000-0003-4953-9114"
},
"description": "Survex data file for Glop Pot",
"encodingFormat": "Plain Text File",
"fileFormat": "http://www.nationalarchives.gov.uk/PRONOM/x-fmt/111",
"filename": [],
"license": {
"@id": "https://creativecommons.org/licenses/by/3.0/au/"
},
"name": "cp7glop.svx"
},
{
"@id": "d06c5dd2-3cf5-4af7-9481-4c5a303e3fd1",
"@type": "GeoCoordinates",
"latitude": "-35.623592",
"longitude": "148.683836",
"name": "Latitude: -35.623592, Longitude: 148.683836"
},
{
"@id": "datasheets",
"@type": "Dataset",
"path": "datasheets",
"hasPart": [
{
"@id": "datasheets/CP7Glopdata01.jpg"
},
{
"@id": "datasheets/CP7Glopdata02.jpg"
}
],
"identifier": "datasheets",
"name": "CP7 Glop Pot, Cooleman Plains, Glop Pot data sheets ",
"organization": "Sydney University Speleological Society"
},
{
"@id": "datasheets/CP7Glopdata01.jpg",
"@type": "File",
"contentSize": "135193",
"creator": [
{
"@id": "Keir Vaughan-Taylor"
},
{
"@id": "http://orcid.org/0000-0003-4953-9114"
},
{
"@id": "http://orcid.org/0000-0002-2038-7922"
}
],
"description": "Sump 2 downstream to sump 1",
"encodingFormat": "JPEG File Interchange Format",
"fileFormat": "http://www.nationalarchives.gov.uk/PRONOM/fmt/43",
"filename": [],
"license": {
"@id": "https://creativecommons.org/licenses/by/3.0/au/"
},
"name": "datasheets/CP7Glopdata01.jpg"
},
{
"@id": "datasheets/CP7Glopdata02.jpg",
"@type": "File",
"contentSize": "199121",
"creator": [
{
"@id": "http://orcid.org/0000-0003-4953-9114"
},
{
"@id": "http://orcid.org/0000-0002-2038-7922"
}
],
"description": "Sump 1 to ladder, Tag to ladder",
"encodingFormat": "JPEG File Interchange Format",
"fileFormat": "http://www.nationalarchives.gov.uk/PRONOM/fmt/43",
"filename": [],
"license": {
"@id": "https://creativecommons.org/licenses/by/3.0/au/"
},
"name": "datasheets/CP7Glopdata02.jpg"
},
{
"@id": "f0e272c0-e267-4a30-ad7c-b5fe4987cd66",
"@type": "Place",
"address": "Cooleman Plains",
"description": "Located in the Snowy Mountains Region of NSW, nearest town Tumut 2720",
"geo": {
"@id": "d06c5dd2-3cf5-4af7-9481-4c5a303e3fd1"
},
"name": "Glop Pot"
},
{
"@id": "http://orcid.org/0000-0002-2038-7922",
"@type": "Person",
"email": "andreas@example.com",
"familyName": "Klocker",
"givenName": "Andreas",
"identifier": "http://orcid.org/0000-0002-2038-7922",
"name": "Andreas Klocker"
},
{
"@id": "http://orcid.org/0000-0003-4953-0830",
"@type": "Person",
"email": "mike.lake@uts.edu.au",
"familyName": "Lake",
"givenName": "Mike",
"identifier": "http://orcid.org/0000-0003-4953-0830",
"name": "Mike Lake"
},
{
"@id": "http://orcid.org/0000-0003-4953-9114",
"@type": "Person",
"email": "phil@example.com",
"familyName": "Maynard",
"givenName": "Phil",
"identifier": "http://orcid.org/0000-0003-4953-9114",
"name": "Phil Maynard"
},
{
"@id": "https://creativecommons.org/licenses/by/3.0/au/",
"@type": "CreativeWork",
"description": "You are free to:\r\r\r\nShare — copy and redistribute the material in any medium or format\r\r\r\nAdapt — remix, transform, and build upon the material\r\r\r\nfor any purpose, even commercially.\r\r\r\n This license is acceptable for Free Cultural Works.\r\r\r\nThe licensor cannot revoke these freedoms as long as you follow the license terms.\r\r\r\nUnder the following terms:\r\r\r\nAttribution — You must give appropriate credit, provide a link to the license, and indicate if changes were made. You may do so in any reasonable manner, but not in any way that suggests the licensor endorses you or your use.\r\r\r\n\r\r\r\nNo additional restrictions — You may not apply legal terms or technological measures that legally restrict others from doing anything the license permits.\r\r\r\nNotices:\r\r\r\nYou do not have to comply with the license for elements of the material in the public domain or where your use is permitted by an applicable exception or limitation.\r\r\r\nNo warranties are given. The license may not give you all of the permissions necessary for your intended use. For example, other rights such as publicity, privacy, or moral rights may limit how you use the material.",
"identifier": "https://creativecommons.org/licenses/by/3.0/au/",
"name": "CC-BY"
},
{
"@id": "https://dx.doi.org/10.1016/this_is_an_example_not_a_real_DOI",
"@type": "Dataset",
"contentLocation": {
"@id": "f0e272c0-e267-4a30-ad7c-b5fe4987cd66"
},
"path": "./",
"creator": [
{
"@id": "http://orcid.org/0000-0003-4953-0830"
},
{
"@id": "Keir Vaughan-Taylor"
},
{
"@id": "http://orcid.org/0000-0002-2038-7922"
},
{
"@id": "http://orcid.org/0000-0003-4953-9114"
}
],
"datePublished": "2017",
"description": "Sketchsheets and data from the Glop Pot cave survey",
"hasPart": [
{
"@id": "cp7glop.svx"
},
{
"@id": "cp7glop.ai"
},
{
"@id": "asf"
},
{
"@id": "datasheets"
},
{
"@id": "sketchsheets"
}
],
"identifier": "https://dx.doi.org/10.1016/this_is_an_example_not_a_real_DOI",