Commit 04c69333 authored by Mike Lynch's avatar Mike Lynch
Browse files
parents fe2a0450 40819f52
......@@ -32,7 +32,6 @@ const htmlFileName = defaults.html_file_name;
const metadata_file_name = defaults.metadata_json_file_name;
const fs = require("fs-extra")
var dirs = undefined;
program
.version("0.1.0")
.description(
......@@ -158,11 +157,10 @@ async function generateHTML(metadataPath) {
}
const preview = await new Preview(crate);
console.log(HtmlFile)
const f = new HtmlFile(preview);
fs.writeFileSync(path.join(dir, htmlFileName),
await f.render());
await f.render(program.cratescript));
if (program.bag) {
......
......@@ -64,11 +64,9 @@ table.table {
</div>
<p>This file was created at <%- time_stamp %> by
<p>This file was created at <%- time_stamp.toUTCString() %> by
<a href='https://code.research.uts.edu.au/eresearch/calcytejs'>
Calcyte</a> which implements the <a href='<%- spec_id %>'>
Draft RO-Crate format</a>, version <%- ROCrate_version %>
</p>
Calcyte</a>.
</body>
......
......@@ -18,7 +18,6 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
var jsonld = require('jsonld');
var fs = require('fs');
var program = require('commander');
var defaults = require('./defaults');
const rocrate = require('ro-crate');
var XLSX = require('xlsx');
......@@ -49,6 +48,8 @@ module.exports = function() {
this.field_names_by_type = {};
this.existing_metadatas = [];
this.root_node = {};
this.extraContext = {}; // TODO add additional context
this.extraProps = [];
function get_collection_metadata(workbook, collection) {
// TODO - make the collection just another kind of item object
......@@ -85,14 +86,19 @@ module.exports = function() {
collection.items.push(item);
}
}
function flattenit(json, collection) {
var promises = jsonld.promises;
json["@context"] = defaults.context;
fs.writeFileSync("test.jsonld", JSON.stringify(json, null, 2));
defaults.context.push(collection.extraContext)
var promise = promises.flatten(json, defaults.context);
return promise;
}
return {
extraContext: this.extraContext,
extraProps: this.extraProps,
collection_metadata: this.collection_metadata,
children: this.children,
rel_path: this.rel_path,
......@@ -206,7 +212,8 @@ module.exports = function() {
exists = false;
}
}
if (exists) {
//item_json["EXTRA"]= "1";
if (exists && !item_json["*MISSING-FILE"]) {
graph.push(item_json);
}
}
......@@ -233,11 +240,12 @@ module.exports = function() {
this.to_json(this.graph);
json = JSON.parse(JSON.stringify(this.crate.json_ld));
for (var same of this.same_as) {
json["@graph"].push(same)
}
//fs.writeFileSync("test.jsonld", JSON.stringify(json, null, 1))
var collection = this;
promise = flattenit(json, this);
return promise.then(
function(flattenated) {
......@@ -320,7 +328,6 @@ module.exports = function() {
var metadata_file_regex = new RegExp(
`^${defaults.metadata_root_name}.*(xlsx|html|json)$`
);
items = items.filter(item => !metadata_file_regex.test(item));
items = items.filter(item => !defaults.ignore_file_regex.test(item));
items = items.filter(item => shell.test("-f", path.join(dir, item)));
......@@ -379,9 +386,10 @@ module.exports = function() {
sheet_names = this.workbook.SheetNames;
for (var i = 0; i < sheet_names.length; i++) {
sheet_name = sheet_names[i];
var sheet = this.workbook.Sheets[sheet_name];
//console.log(sheet);
//console.log(sheet_name);
if (sheet_name == "Collection") {
get_collection_metadata(this.workbook, this);
} else if (sheet_name == "Files" && this.file_info) {
......@@ -435,11 +443,21 @@ module.exports = function() {
this.workbook.Sheets["@context"]
);
for (var item of extra_context) {
if (item["Key"] && item["Value"]) {
context[item["Key"]] = item["Value"]
if (item["name"] && item["URL"]) {
this.extraContext[item["name"]] = item["URL"]
if (item["SameAs"]) {
this.same_as.push({"@id": item["Value"], "sameAs": item["SameAs"]})
this.same_as.push({"@id": item["URL"], "sameAs": item["SameAs"], "@type": "Thing"})
}
} else if (item["name"] && item["description"] && item["namespace"]){
const URI = `http://purl.org/adhoc?@type=rdf:Property&rdfs:label=${item["name"]}&rdfs:comment=${item["description"]}`
this.extraContext[item["name"]] = URI
/* this.graph.push(
{
"@id": URI,
"@type": "rdf:Property",
"rdfs:comment": item["description"],
"rdfs:label": item["name"]
}); */
}
}
}
......
......@@ -38,7 +38,7 @@ const ROCrate_profile_file = "defaults/profile-datacrate-v" + ROCrate_version +
const path = require("path")
const DEFAULTS = path.join(__dirname, '../defaults');
const defaults_dir = DEFAULTS;
const context = "https://researchobject.github.io/ro-crate/1.0/context.jsonld";
const context = ["https://researchobject.github.io/ro-crate/1.0/context.jsonld", {"@vocab": "http://schema.org/"}];
const default_context = context;
const metadata_template = path.join(DEFAULTS, 'metadata_template.html');
const render_script = "https://code.research.uts.edu.au/eresearch/CalcyteJS/raw/feature/or-crate/lib/render.js";
......
......@@ -40,6 +40,10 @@ module.exports = function() {
function links_to_id(string, collection) {
var links_to = collection.lookup_id(string);
if (!links_to) {
links_to = collection.lookup_id("#" + string)
//console.log("looked up", string, links_to);
}
//console.log("Linksto", string, links_to)
if (!links_to) {
links_to = collection.lookup_name(string)
......@@ -65,17 +69,17 @@ module.exports = function() {
//console.log("Keys at start of output", Object.keys(this.properties));
var id = this.collection.make_id(this.id);
var frag = { "@id": String(id) };
//console.log("Setting id", this.id, this.name, this.nested_items);
//console.log(" NAMELOOKUPS", this.collection.name_lookup);
for (let [key, i] of Object.entries(this.nested_items)) {
frag[key] = i.to_json_ld_fragment();
}
for (let [key, f] of Object.entries(this.properties)) {
if (f.is_type) {
types = f.data; //Don't output now
} else if (f.name != "ID") {
frag[f.name] = [];
if (!Array.isArray(f.data)) {
f.data = [f.data];
......@@ -84,14 +88,12 @@ module.exports = function() {
var link_id = f.links_to
? f.links_to
: links_to_id(f.data[k], this.collection);
//console.log("link_id", link_id, "relational", f.is_relational)
if (f.is_file) {
this.is_file = true;
//types.push("schema:MediaObject");
} else if (f.is_relational && link_id && link_id != id) {
//console.log("Looking for relations", f.data[k], this.collection)
//console.log("GOT A LINK", f.name, f.id);
frag[f.name].push({ "@id": link_id }); //, "@type" : "@id"
} else if (f.is_json) {
frag[f.name] = JSON.parse(f.data[k])
......@@ -105,11 +107,9 @@ module.exports = function() {
}
}
frag["@type"] = this.types;
this.json_ld_fragment = frag;
//console.log(frag);
return frag;
return frag;
},
load_json: function load_json(json_item, collection) {
//console.log("JSON IS: ", json_item);
......
......@@ -76,7 +76,6 @@ module.exports = function() {
this.raw_name = name;
this.name = name;
this.nested_item_json = [];
if (this.name === "ID") {
this.is_id = true;
} else if (this.name === "TYPE:") {
......@@ -120,6 +119,7 @@ module.exports = function() {
this.nested_item_json.push(nested_json);
this.data = "";
}
console.log(name, this.is_repeating, this.is_relational)
this.property_URI = get_RDF_for_column(this.name);
......
......@@ -130,6 +130,24 @@
"resolved": "https://registry.npmjs.org/aws4/-/aws4-1.9.0.tgz",
"integrity": "sha512-Uvq6hVe90D0B2WEnUqtdgY1bATGz3mw33nH9Y+dmA+w5DHvUmBgkr5rM/KCHpCsiFNRUfokW/szpPPgMK2hm4A=="
},
"axios": {
"version": "0.19.2",
"resolved": "https://registry.npmjs.org/axios/-/axios-0.19.2.tgz",
"integrity": "sha512-fjgm5MvRHLhx+osE2xoekY70AhARk3a6hkN+3Io1jc00jtquGvxYlKlsFUhmUET0V5te6CcZI7lcv2Ym61mjHA==",
"requires": {
"follow-redirects": "1.5.10"
},
"dependencies": {
"follow-redirects": {
"version": "1.5.10",
"resolved": "https://registry.npmjs.org/follow-redirects/-/follow-redirects-1.5.10.tgz",
"integrity": "sha512-0V5l4Cizzvqt5D44aTXbFZz+FtyXV1vrDN6qrelxtfYQKW0KO0W2T/hkE8xvGa/540LkZlkaUjO4ailYTFtHVQ==",
"requires": {
"debug": "=3.1.0"
}
}
}
},
"balanced-match": {
"version": "1.0.0",
"resolved": "https://registry.npmjs.org/balanced-match/-/balanced-match-1.0.0.tgz",
......@@ -143,6 +161,14 @@
"tweetnacl": "^0.14.3"
}
},
"bindings": {
"version": "1.5.0",
"resolved": "https://registry.npmjs.org/bindings/-/bindings-1.5.0.tgz",
"integrity": "sha512-p2q/t/mhvuOj/UeLlV6566GD/guowlr0hHxClI0W9m7MWYkL1F0hLo+0Aexs9HSPCtR1SXQ0TD3MMKrXZajbiQ==",
"requires": {
"file-uri-to-path": "1.0.0"
}
},
"bit-mask": {
"version": "1.0.2",
"resolved": "https://registry.npmjs.org/bit-mask/-/bit-mask-1.0.2.tgz",
......@@ -186,11 +212,6 @@
"resolved": "https://registry.npmjs.org/camelcase/-/camelcase-4.1.0.tgz",
"integrity": "sha1-1UVjW+HjPFQmScaRc+Xeas+uNN0="
},
"canonicalize": {
"version": "1.0.1",
"resolved": "https://registry.npmjs.org/canonicalize/-/canonicalize-1.0.1.tgz",
"integrity": "sha512-N3cmB3QLhS5TJ5smKFf1w42rJXWe6C1qP01z4dxJiI5v269buii4fLHWETDyf7yEd0azGLNC63VxNMiPd2u0Cg=="
},
"caseless": {
"version": "0.12.0",
"resolved": "https://registry.npmjs.org/caseless/-/caseless-0.12.0.tgz",
......@@ -418,7 +439,6 @@
"version": "3.1.0",
"resolved": "https://registry.npmjs.org/debug/-/debug-3.1.0.tgz",
"integrity": "sha512-OX8XqP7/1a9cqkxYw2yXss15f26NKWBpDXQd0/uK/KPqdQhxbPa994hnzjcE2VqQpDslf55723cKPUOGSmMY3g==",
"dev": true,
"requires": {
"ms": "2.0.0"
}
......@@ -619,6 +639,11 @@
"resolved": "https://registry.npmjs.org/fast-levenshtein/-/fast-levenshtein-2.0.6.tgz",
"integrity": "sha1-PYpcZog6FqMMqGQ+hR8Zuqd5eRc="
},
"file-uri-to-path": {
"version": "1.0.0",
"resolved": "https://registry.npmjs.org/file-uri-to-path/-/file-uri-to-path-1.0.0.tgz",
"integrity": "sha512-0Zt+s3L7Vf1biwWZ29aARiVYLx7iMGnEUl9x33fbB/j3jR81u/O2LbqK+Bm1CDSNDKVtJ/YjwY7TUd5SkeLQLw=="
},
"filesize": {
"version": "3.6.1",
"resolved": "https://registry.npmjs.org/filesize/-/filesize-3.6.1.tgz",
......@@ -988,14 +1013,13 @@
}
},
"jsonld": {
"version": "1.8.1",
"resolved": "https://registry.npmjs.org/jsonld/-/jsonld-1.8.1.tgz",
"integrity": "sha512-f0rusl5v8aPKS3jApT5fhYsdTC/JpyK1PoJ+ZtYYtZXoyb1J0Z///mJqLwrfL/g4NueFSqPymDYIi1CcSk7b8Q==",
"requires": {
"canonicalize": "^1.0.1",
"rdf-canonize": "^1.0.2",
"request": "^2.88.0",
"semver": "^5.6.0",
"version": "1.0.4",
"resolved": "https://registry.npmjs.org/jsonld/-/jsonld-1.0.4.tgz",
"integrity": "sha512-Kh1f4biEp72ZO7QUTQpc5BQYdE0C/mARzds0MUy+BEqQ4dDM0wYyoeuw4WacAMDzQ6wp3zmMvUvRlITxlRe5xw==",
"requires": {
"rdf-canonize": "^0.2.1",
"request": "^2.83.0",
"semver": "^5.5.0",
"xmldom": "0.1.19"
}
},
......@@ -1143,15 +1167,20 @@
"resolved": "https://registry.npmjs.org/ms/-/ms-2.0.0.tgz",
"integrity": "sha1-VgiurfwAvmwpAd9fmGF4jeDVl8g="
},
"nan": {
"version": "2.14.0",
"resolved": "https://registry.npmjs.org/nan/-/nan-2.14.0.tgz",
"integrity": "sha512-INOFj37C7k3AfaNTtX8RhsTw7qRy7eLET14cROi9+5HAVbbHuIWUHEauBv5qT4Av2tWasiTY1Jw6puUNqRJXQg=="
},
"ncp": {
"version": "2.0.0",
"resolved": "https://registry.npmjs.org/ncp/-/ncp-2.0.0.tgz",
"integrity": "sha1-GVoh1sRuNh0vsSgbo4uR6d9727M="
},
"node-forge": {
"version": "0.8.5",
"resolved": "https://registry.npmjs.org/node-forge/-/node-forge-0.8.5.tgz",
"integrity": "sha512-vFMQIWt+J/7FLNyKouZ9TazT74PRV3wgv9UT4cRjC8BffxFbKXkgIWR42URCPSnHm/QDz6BOlb2Q0U4+VQT67Q=="
"version": "0.7.6",
"resolved": "https://registry.npmjs.org/node-forge/-/node-forge-0.7.6.tgz",
"integrity": "sha512-sol30LUpz1jQFBjOKwbjxijiE3b6pjd74YwfD0fJOKPjF+fONKb2Yg8rYgS6+bK6VDl+/wfr4IYpC7jDzLUIfw=="
},
"node-json2html": {
"version": "1.3.0",
......@@ -1377,12 +1406,14 @@
"integrity": "sha512-N5ZAX4/LxJmF+7wN74pUD6qAh9/wnvdQcjq9TZjevvXzSUo7bfmw91saqMjzGS2xq91/odN2dW/WOl7qQHNDGA=="
},
"rdf-canonize": {
"version": "1.0.3",
"resolved": "https://registry.npmjs.org/rdf-canonize/-/rdf-canonize-1.0.3.tgz",
"integrity": "sha512-piLMOB5Q6LJSVx2XzmdpHktYVb8TmVTy8coXJBFtdkcMC96DknZOuzpAYqCWx2ERZX7xEW+mMi8/wDuMJS/95w==",
"version": "0.2.5",
"resolved": "https://registry.npmjs.org/rdf-canonize/-/rdf-canonize-0.2.5.tgz",
"integrity": "sha512-ZSOcoziIkics9lZvFRoqRHUWoITLbXeKqXNxTuvchTf9c74/yOzzZCKxS+aTCGQp81fQZhnKUM/NsgyiBS0Mig==",
"requires": {
"node-forge": "^0.8.1",
"semver": "^5.6.0"
"bindings": "^1.3.0",
"nan": "^2.10.0",
"node-forge": "^0.7.1",
"semver": "^5.4.1"
}
},
"readable-stream": {
......@@ -1525,10 +1556,11 @@
}
},
"ro-crate": {
"version": "1.2.21",
"resolved": "https://registry.npmjs.org/ro-crate/-/ro-crate-1.2.21.tgz",
"integrity": "sha512-gHrX3a96tlO8mNlbSaXgb9GgSZZHq37XmRG75Xk9tOJUVd66Gxullc4oKFD64Fllbil0rMbaHUGgDJhSE4LhOA==",
"version": "1.3.0",
"resolved": "https://registry.npmjs.org/ro-crate/-/ro-crate-1.3.0.tgz",
"integrity": "sha512-qJ9StOsZBM+VBlg2G6fpFV5r0bGd1LPll5VRFe0RrNiF/JuhEutUAgRetcRNDvRsIfQm2LJhuBOkp5zHqgBBqw==",
"requires": {
"axios": "^0.19.2",
"cheerio": "^1.0.0-rc.3",
"commander": "^4.0.1",
"ejs": "^2.7.1",
......@@ -1538,9 +1570,9 @@
},
"dependencies": {
"commander": {
"version": "4.1.0",
"resolved": "https://registry.npmjs.org/commander/-/commander-4.1.0.tgz",
"integrity": "sha512-NIQrwvv9V39FHgGFm36+U9SMQzbiHvU79k+iADraJTpmrFFfx7Ds0IvDoAdZsDrknlkRk14OYoWXb57uTh7/sw=="
"version": "4.1.1",
"resolved": "https://registry.npmjs.org/commander/-/commander-4.1.1.tgz",
"integrity": "sha512-NOKm8xhkzAjzFx8B2v5OAHT+u5pRQc2UCa2Vq9jYL/31o2wi9mxBA7LIFs3sV5VSC49z6pEhfbMULvShKj26WA=="
}
}
},
......
......@@ -16,6 +16,7 @@
"mocha": "^4.1.0"
},
"dependencies": {
"axios": "^0.19.2",
"chai": "^4.2.0",
"chai-fs": "^2.0.0",
"cheerio": "^1.0.0-rc.3",
......@@ -32,7 +33,7 @@
"json": "^9.0.6",
"jsonld": "^1.8.1",
"node-json2html": "^1.3.0",
"ro-crate": "^1.2.20",
"ro-crate": "^1.3.0",
"sha1": "^1.1.1",
"shelljs": "^0.8.3",
"tmp": "0.0.33",
......
{
"@context": "https://researchobject.github.io/ro-crate/1.0/context.jsonld",
"@context": [
"https://researchobject.github.io/ro-crate/1.0/context.jsonld",
{
"@vocab": "http://schema.org/"
}
],
"@graph": [
{
"@id": "#EPL1",
......@@ -30,8 +35,12 @@
"description": "Photo snapped on a photo walk on a misty day",
"endTime": "2017:06:11T12:56:14+10:00",
"instrument": [
"EPL1",
"Panny20mm"
{
"@id": "#EPL1"
},
{
"@id": "#Panny20mm"
}
],
"name": "Took dog picture",
"object": {
......@@ -61,7 +70,7 @@
}
},
{
"@id": "#cfd6609e-a69f-4ec5-93cc-3162e86d5e49",
"@id": "#d2c5b5e0-a720-4b21-ad3a-f44ad89488e7",
"@type": "GeoCoordinates",
"latitude": "-33.7152",
"longitude": "150.30119",
......@@ -113,16 +122,11 @@
"license": {
"@id": "https://creativecommons.org/licenses/by-nc-sa/3.0/au/"
},
"name": "Sample dataset for RO-Crate v0.2",
"name": "Sample dataset for RO-Crate v1.0",
"publisher": {
"@id": "https://ror.org/0384j8v12"
},
"temporalCoverage": "2017",
"distribution": [
{
"@id": "http://something/"
}
]
"temporalCoverage": "2017"
},
{
"@id": "_:b0",
......@@ -2626,7 +2630,7 @@
"address": "Katoomba, NSW",
"description": "Catalina Park is a disused motor racing venue, located at Katoomba, in the Blue Mountains, New South Wales, Australia, and is recognised as an Aboriginal Place due to the long association of the local Gundungarra and Darug clans to the area.",
"geo": {
"@id": "#cfd6609e-a69f-4ec5-93cc-3162e86d5e49"
"@id": "#d2c5b5e0-a720-4b21-ad3a-f44ad89488e7"
},
"name": "Catalina Park"
},
......@@ -3318,6 +3322,7 @@
}
],
"fileFormat": "http://www.nationalarchives.gov.uk/PRONOM/fmt/645",
"filename": [],
"name": "pics/2017-06-11 12.56.14.jpg",
"thumbnail": {
"@id": "pics/thumbs/2017-06-11 12.56.14.png"
......@@ -3950,6 +3955,7 @@
}
],
"fileFormat": "http://www.nationalarchives.gov.uk/PRONOM/fmt/43",
"filename": [],
"name": "pics/sepia_fence.jpg",
"thumbnail": {
"@id": "pics/thumbs/sepia_fence.png"
......@@ -3974,6 +3980,7 @@
"contentSize": "20594",
"encodingFormat": "Portable Network Graphics",
"fileFormat": "http://www.nationalarchives.gov.uk/PRONOM/fmt/11",
"filename": [],
"name": "pics/thumbs/2017-06-11 12.56.14.png"
},
{
......@@ -3982,6 +3989,7 @@
"contentSize": "20524",
"encodingFormat": "Portable Network Graphics",
"fileFormat": "http://www.nationalarchives.gov.uk/PRONOM/fmt/11",
"filename": [],
"name": "pics/thumbs/sepia_fence.png"
},
{
......@@ -3991,12 +3999,6 @@
"@id": "./"
},
"identifier": "ro-crate-metadata.jsonld"
},
{
"@id": "http://something/",
"contentUrl": "http://something/",
"@type": "DataDownload",
"encodingFormat": "zip"
}
]
}
\ No newline at end of file
This diff is collapsed.
Markdown is supported
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