Commit 34ec105a authored by PTSEFTON's avatar PTSEFTON
Browse files

Fixing additional context handling

parent 9b840c17
......@@ -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) {
......
......@@ -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,7 @@ module.exports = function() {
this.field_names_by_type = {};
this.existing_metadatas = [];
this.root_node = {};
this.extraContext = {};
function get_collection_metadata(workbook, collection) {
// TODO - make the collection just another kind of item object
......@@ -85,14 +85,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)
console.log(defaults.context)
var promise = promises.flatten(json, defaults.context);
return promise;
}
return {
extraContext: this.extraContext,
collection_metadata: this.collection_metadata,
children: this.children,
rel_path: this.rel_path,
......@@ -233,11 +238,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 +326,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 +384,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) {
......@@ -436,9 +442,9 @@ module.exports = function() {
);
for (var item of extra_context) {
if (item["Key"] && item["Value"]) {
context[item["Key"]] = item["Value"]
this.extraContext[item["Key"]] = item["Value"]
if (item["SameAs"]) {
this.same_as.push({"@id": item["Value"], "sameAs": item["SameAs"]})
this.same_as.push({"@id": item["Value"], "sameAs": item["SameAs"], "@type": "Thing"})
}
}
}
......
......@@ -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";
......
......@@ -105,8 +105,6 @@ module.exports = function() {
}
}
frag["@type"] = this.types;
this.json_ld_fragment = frag;
//console.log(frag);
return frag;
......
......@@ -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.20",
"resolved": "https://registry.npmjs.org/ro-crate/-/ro-crate-1.2.20.tgz",
"integrity": "sha512-MeWO1axgM7OW5v5/elt12d2pFroxnSyDGQrNQg5VBFu1WV3O4do5pQhtf1eFwnFsDG27JtwKKskyy7PWRqfLDg==",
"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",
......@@ -30,9 +31,9 @@
"jquery": "^3.4.1",
"jsdom": "^11.12.0",
"json": "^9.0.6",
"jsonld": "^1.8.1",
"jsonld": "^1.0.4",
"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",
......@@ -61,7 +66,11 @@
}
},
{
"@id": "#cfd6609e-a69f-4ec5-93cc-3162e86d5e49",
"@id": "#ba671201-2b5c-4c90-9a72-1f8aa710e6eb",
"*MISSING-FILE": "1"
},
{
"@id": "#ea0e7767-c702-4403-b815-2aefbe07d45c",
"@type": "GeoCoordinates",
"latitude": "-33.7152",
"longitude": "150.30119",
......@@ -117,12 +126,7 @@
"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": "#ea0e7767-c702-4403-b815-2aefbe07d45c"
},
"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