Commit 5657e8dd authored by PTSEFTON's avatar PTSEFTON
Browse files

Started on ro-crate-checking and reporting

parent 609db04e
......@@ -80,10 +80,13 @@ class jsonldHelper {
this.item_by_type = {}; // dict of arrays
this.items_by_new_id = {}
this.graph = this.json_ld["@graph"];
/*
USed to do this -
if (!this.json_ld["@context"]) {
this.json_ld["@context"] = defaults.default_context;
}
this.graph = this.json_ld["@graph"];
*/
this.graph = this.json_ld["@graph"] ? this.json_ld["@graph"] : [];
for (let i = 0; i < this.graph.length; i++) {
var item = this.graph[i];
if (item["@id"]) {
......@@ -103,7 +106,7 @@ class jsonldHelper {
}
}
this.root_node = this.item_by_url["./"];
this.rootId = this.root_node['@id'];
this.rootId = this.root_node ? this.root_node['@id'] : undefined;
}
update_id(item, new_id){
item["@id"] = new_id
......
/* This is part of Calcyte a tool for implementing the DataCrate data packaging
spec. Copyright (C) 2018 University of Technology Sydney
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
const shell = require("shelljs");
const builder = require("xmlbuilder");
const Index = require("../lib/index_html.js");
const default_test_dir = "test_output";
const Datacite = require("../lib/datacite.js");
const text_citation_1 =
"Peter Sefton (2017) Sample dataset for DataCrate v0.2. University of Technology Sydney. Datacrate. http://dx.doi.org/10.5281/zenodo.1009240";
const assert = require("assert");
function set_up_a_dir(test_dir = default_test_dir) {
// Set up a test directory with some files.
shell.rm("-rf", test_dir);
shell.mkdir("-p", test_dir);
return test_dir;
}
describe("Test helper functions", function() {
it("Test for path manipulation", function(done) {
set_up_a_dir();
var index_maker = new Index();
// Single page version
index_maker.init(
"../test_data/sample_CATALOG.json",
"./test/test_output/index.html",
false
);
assert.equal(
index_maker.get_href("http://dx.doi.org/10.5281/zenodo.1009240"),
"#http://dx.doi.org/10.5281/zenodo.1009240"
);
// Multi page version
index_maker.init(
"../test_data/sample_CATALOG.json",
"./test/test_output/index.html",
true
);
assert.equal(
index_maker.get_href("http://dx.doi.org/10.5281/zenodo.1009240", "http://dx.doi.org/10.5281/zenodo.1009240" ),
"CATALOG.html"
);
assert.equal(
index_maker.get_href("http://orcid.org/0000-0002-3545-944X", "http://dx.doi.org/10.5281/zenodo.1009240" ),
"CATALOG_files/8998f8b4/885ba8f4/7d9b9bac/ef466c98/5d56f099/index.html"
);
assert.equal(
index_maker.get_href("http://dx.doi.org/10.5281/zenodo.1009240", "http://orcid.org/0000-0002-3545-944X" ),
"../../../../../../CATALOG.html"
);
assert.equal(
index_maker.get_href("http://orcid.org/0000-0002-3545-944X", "http://n2t.info/urn:nbn:se:kb:repos-1" ),
"../../../../../8998f8b4/885ba8f4/7d9b9bac/ef466c98/5d56f099/index.html"
);
assert.equal(
index_maker.helper.item_by_id["http://orcid.org/0000-0002-3545-944X"][
"@reverse"
]["creator"][0]["@id"],
"http://dx.doi.org/10.5281/zenodo.1009240"
);
index_maker.init({
"@graph": [
{
"@id": "https://dx.doi.org/10.4225/35/555d661071c76",
name: "Farms to Freeways Example Dataset",
path: ["data/"]
}
]
});
/*
citer = new Datacite();
text_citation = citer.make_citation("./test_data/sample_CATALOG.json", "./test/test_output/sample_datacite.xml")
index_maker.make_index_html(
"defaults/catalog_template.html",
text_citation);
*/
//assert(Object.is(c.collection_metadata, {} ));
// TODO - actual tests!!!!
done();
});
});
......@@ -33,96 +33,7 @@ describe("JSON-LD helper simple tests", function () {
it("Test context resolving", function (done) {
// From the spec https://json-ld.org/spec/latest/json-ld/
var json_content = {
"@context": {
"name": "http://schema.org/name",
"image": {
"@id": "http://schema.org/image",
"@type": "@id"
},
"homepage": {
"@id": "http://schema.org/url",
"@type": "@id"
}
},
"@graph": [
{
"name": "Manu Sporny",
"homepage": "http://manu.sporny.org/",
"image": "http://manu.sporny.org/images/manu.png"
}
]
}
const helper = new jsonld()
helper.init(json_content)
assert(helper.get_uri_for_term("name"), "http://schema.org/name")
assert(helper.get_uri_for_term("image"), "http://schema.org/image")
helper.trim_context()
assert.equal(Object.keys(helper.json_ld["@context"]).length, 3)
//from the spec - example 24
json_content = {
"@graph": [
{
"@id": "http://me.markus-lanthaler.com/",
"@type": "foaf:Person",
"foaf:name": "Markus Lanthaler",
"foaf:homepage": "http://www.markus-lanthaler.com/",
"picture": "http://twitter.com/account/profile_image/markuslanthaler"
}],
"@context": {
"@version": 1.1,
"xsd": "http://www.w3.org/2001/XMLSchema#",
"foaf": "http://xmlns.com/foaf/0.1/",
"foaf:homepage": { "@type": "@id" },
"picture": { "@id": "foaf:depiction", "@type": "@id" }
}
}
const helper2 = new jsonld()
helper2.init(json_content)
console.log("Looking up name", helper2.get_uri_for_term("foaf:name"))
assert.equal(helper2.get_uri_for_term("foaf:name"), "http://xmlns.com/foaf/0.1/name")
assert.equal(helper2.get_uri_for_term("picture"), "http://xmlns.com/foaf/0.1/depiction")
assert.equal(helper2.get_uri_for_term("foaf:homepage"), "http://xmlns.com/foaf/0.1/homepage")
assert.equal(helper2.get_uri_for_term("foaf:Person"), "http://xmlns.com/foaf/0.1/Person")
helper2.trim_context()
assert.equal(Object.keys(helper2.json_ld["@context"]).length, 4)
// Try with a real CATALOG
var catalog = path.join(test_path, 'CATALOG.json');
json_content = JSON.parse(fs.readFileSync(catalog));
const helper3 = new jsonld()
helper3.init(json_content)
//assert.equal(helper3.get_uri_for_term("Person"), "http://schema.org/Person")
helper3.trim_context()
assert.equal(Object.keys(helper3.json_ld["@context"]).length, 29)
// Test context trimming
const json4 = {
"@graph": [
{
"@id": "1", "name": "one", "path": "./nothing", "@type": "Dataset",
"distibution": [{ "@id": "2" }]
},
{ "@id": "2", "name": "two", "path": "./something", "@type": "DataDownload" },
]
}
helper.init(json4)
helper.trim_context()
assert.equal(helper.get_uri_for_term("DataDownload"), "http://schema.org/DataDownload");
done();
});
......@@ -183,7 +94,6 @@ describe("JSON-LD helper simple tests", function () {
assert.equal(helper.item_by_id["4"]["isPartOf"][0]["@id"], "1")
assert.equal(helper.item_by_id["2"]["@reverse"]["creator"][0]["@id"], "1")
assert.equal(helper.get_uri_for_term("partOf", "http://schema.org/partOf"))
......
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