Commit 17e1b7be authored by PTSEFTON's avatar PTSEFTON
Browse files

Tidied up table formatting, fixed some bugs

parent 70ffe728
......@@ -33,9 +33,18 @@ module.exports = function(){
var item_json = {}
for (var i=0; i < raw_collection_metadata.length ; i++) {
var name_value = raw_collection_metadata[i];
item_json[name_value['Name']] = name_value['Value'];
if (item_json[name_value['Name']]) {
//console.log("VALUE", name_value['Name'] );
item_json[name_value['Name']].push(name_value['Value']);
}
else {
item_json[name_value['Name']] = [name_value['Value']];
}
}
item_json["TYPE:"] = "Dataset";
item_json["path"] = collection.rel_path;
if (!(collection.rel_path === "./")) {
......@@ -180,7 +189,7 @@ module.exports = function(){
fs.writeFileSync(path.join(collection.dir, "CATALOG.json"), JSON.stringify(flattenated, null, 2),
function(err) {
if(err) {
return console.log(err, "Error wirting in", collection.dir);
return console.log(err, "Error writing in", collection.dir);
}
log("The file was saved!" + path.join(collection.dir, "CATALOG.json"));
});
......
......@@ -61,13 +61,18 @@ module.exports = function(){
if (!Array.isArray(creators)){
creators = [creators]
}
var creators_el = xml.ele('creators');
//console.log(xml.end({ pretty: true }));
for (var i = 0; i < creators.length; i++) {
var found_creator = false;
var creator_names = "";
if (!this.json_by_id[creators[i]["@id"]]) {
creator_el = creators_el.ele("creator").ele("creatorName", creators[i]);
found_creator = true;
creators_strings.push(creators[i]);
}
else {
var creator = this.json_by_id[creators[i]["@id"]];
var creator_el;
//console.log("Looking at creator", creators[i])
......@@ -92,6 +97,7 @@ module.exports = function(){
name_id_el.att("schemeURI","http://orcid.org");
name_id_el.att("nameIdentifierScheme", "ORCID");
}
}
}
}
......@@ -102,13 +108,15 @@ module.exports = function(){
}
if (root["@id"]){
var identifier = root["@id"];
if (identifier.startsWith('http://dx.doi.org/10.')) {
console.log("ID", identifier)
if (identifier.match(/http:\/\/(dx\.)?doi.org\/10\./)) {
//<identifier identifierType="DOI">10.5072/example-full</identifier>
id_el = xml.ele("identifier", identifier.replace("http://dx.doi.org/",""))
id_el. att("identifierType", "DOI");
}
else {
can_cite = false;
report += "Collection needs to have a DOI as an ID";
}
}
else
......@@ -168,7 +176,7 @@ module.exports = function(){
//Creator (PublicationYear): Title. Version. Publisher. ResourceType. Identifier
//console.log(creators_strings);
this.citation += creators_strings.join(", ");
this.citation += creators_strings.join("; ");
this.citation += ` (${published}) `;
this.citation += `${name}. `;
this.citation += `${publisher}. `;
......
{
"name": "schema:name",
"givenName": "schema:givenName",
"familyName": "schema:familyName",
"description": "schema:description",
"file": "schema:mediaObject",
"path": "schema:contentUrl",
"contentSize": "schema:contentSize",
......@@ -9,7 +12,6 @@
"issn": "schema:issn",
"datePublished": "schema:datePublished",
"identifier": "schema:identifier",
"description": "schema:description",
"license": "schema:license",
"creator": "schema:creator",
"contributor": "schema:contributor",
......@@ -36,6 +38,8 @@
"familyName": "schema:familyName",
"Place": "schema:Place",
"Organization": "schema:Organization",
"memberOf": "schema:memberOf",
"member": "schema:hasMember",
"Project": "frapo:Project",
"affiliation": "schema:affiliation",
"Funder": "schema:Funder",
......
const builder = require('xmlbuilder');
var fs = require('fs');
var ejs = require('ejs');
context = require('./defaults/context.json');
module.exports = function(){
return(
......@@ -15,32 +16,50 @@ module.exports = function(){
}
},
sort_keys : function(keys) {
// Sort a set or array of keys to be in the same order as those in context.json
// Returns set
keys = new Set(keys);
return new Set(Object.keys(context).filter(function (k){return keys.has(k)}))
},
items_to_html : function items_to_html(node, html, toc) {
var table_el = html.ele("table");
var table_el = html.ele("table").att("class", "table table-striped");
// Find all the keys
keys = []
keys = [];
for (let [_, f] of Object.entries(node)) {
keys = keys.concat(Object.keys(f));
}
key_set = new Set(keys);
key_set = this.sort_keys(keys);
key_set.delete('@type');
key_set.delete('@id');
key_set.delete('identifier');
key_set.delete('fileFormat');
var header_row_el = table_el.ele("tr");
var thead_l = table_el.ele("thead").att("class","thead-inverse");
var header_row_el = thead_l.ele("tr");
for (let k of key_set) {
header_row_el.ele("th", k[0].toUpperCase() + k.substring(1));
}
for (let [_, f] of Object.entries(node)) {
var row_el = table_el.ele("tr").att("id", f['@id']);
for (let k of key_set) {
body_el = table_el.ele("tbody").att("class","table-striped");
for (let [_, property] of Object.entries(node)) {
var row_el = table_el.ele("tr").att("id", property['@id']);
for (let key of key_set) {
td_ele = row_el.ele("td");
this.format_cell(property, key, td_ele);
}
}
},
format_cell : function(f, k, td_ele) {
var data = f[k];
if (!Array.isArray(data)) {
data = [data];
}
var i = 0;
for (let [_, part] of Object.entries(data)) {
for (let [_, part] of data.entries()) {
//console.log("PART", part)
if (part === undefined) {
......@@ -65,38 +84,32 @@ module.exports = function(){
td_ele.txt(", ");
}
}
}
}
},
dataset_to_html : function dataset_to_html(node, html, toc) {
var table_el = html.ele("table")
var table_el = html.ele("table").att("class", "table")
if (node["@id"]) {
table_el.att("id", node["@id"]);
}
var keys = Object.keys(node).filter(k => !(/HasPart/.test(k)));
var keys = new Set(Object.keys(node).filter(k => !(/hasPart/.test(k))));
keys.delete("@id");
keys.delete("identifier");
keys.delete("@type");
key = this.sort_keys(keys);
for (let key of keys) {
var value = node[key];
var row_el = table_el.ele("tr")
row_el.ele("th", key[0].toUpperCase() + key.substring(1));
if (value['@id']) {
var target_name = this.json_by_id[value['@id']].name ? this.json_by_id[value['@id']].name : value['@id'];
row_el.ele("td").ele('a',target_name).att('href', '#' + value['@id']);
}
else {
row_el.ele("td", value); // TODO look for linking and embedding
}
this.format_cell(node, key, row_el.ele("td"))
}
if (node.HasPart) {
if (!Array.isArray(node.HasPart)) {
node.HasPart = [node.HasPart];
if (node.hasPart) {
if (!Array.isArray(node.hasPart)) {
node.hasPart = [node.hasPart];
}
var files = [];
var datasets = [];
for (let [key, value] of Object.entries(node.HasPart)) {
for (let [key, value] of Object.entries(node.hasPart)) {
if (value["@id"] && this.json_by_id[value["@id"]]) {
var child = this.json_by_id[value["@id"]];
if (child['@type']) {
......
......@@ -15,14 +15,14 @@ module.exports = function(){
this.nested_items = {};
function links_to_id(string, collection) {
var links_to_id = undefined;
var links_to = undefined;
if (collection.id_lookup[string]) {
links_to_id = collection.id_lookup[string].id;
links_to = collection.id_lookup[string].id;
}
else if (collection.name_lookup[string]){
links_to_id = collection.name_lookup[string].id;
links_to = collection.name_lookup[string].id;
}
return links_to_id;
return links_to;
}
function make_link(string, collection, el) {
......@@ -57,7 +57,8 @@ module.exports = function(){
"to_json_ld_fragment" : function to_json_ld_fragment() {
//console.log("Keys at start of output", Object.keys(this.properties));
var frag = {"@id" : this.id};
var frag = {"@id" : String(this.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)) {
......@@ -68,7 +69,7 @@ module.exports = function(){
types = f.data; //Don't output now
} else if (f.name != "ID"){
frag[f.name] = [];
//console.log(f.name);
if (!Array.isArray(f.data)) {f.data=[f.data]}
for (var k = 0; k < f.data.length ; k++){
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)
......
......@@ -63,7 +63,6 @@ module.exports = function(){
if (this.name === "ID"){
this.name = 'identifier';
console.log("GOT ID", this.name)
}
else if (this.name === "TYPE:"){
this.is_type = true;
......@@ -134,7 +133,8 @@ module.exports = function(){
if (this.is_repeating || this.is_type) {
this.data = this.data.replace(/, +/g, ",").split(",");
//console.log("SPLIT", this.type, this.name, this.data)
} else {
} else if(!Array.isArray(this.data)) {
this.data = [this.data];
}
......
......@@ -197,10 +197,7 @@ describe("Sample data details", function(){
assert.equal(c.json_by_id["http://www.geonames.org/8152662/catalina-park.html"].name, 'Catalina Park');
console.log("Place data", c.json_by_id["http://www.geonames.org/8152662/catalina-park.html"])
var catalina_location_id = c.json_by_id["http://www.geonames.org/8152662/catalina-park.html"].geo['@id'];
console.log("CATALINA location", catalina_location_id);
var catalina_geo = c.json_by_id[catalina_location_id];
console.log("CATALINA GEO XXXXXXXXXXXX", catalina_geo);
assert.equal(catalina_geo.latitude, '-33.7152');
assert.equal(catalina_geo.longitude, '150.30119');
......@@ -246,7 +243,7 @@ describe("Datacite", function(){
function () {
citer = new Datacite();
text_citation = citer.make_citation("./test_data/Glop_Pot/CATALOG.json", "./test_data/Glop_pot/datacite.xml")
assert.equal(text_citation, "Maynard, Phil (2017) Glop Pot data. University of Technology Sydney. Datacrate. http://dx.doi.org/10.1016/something");
assert.equal(text_citation, "Lake, Mike; Vaughan-Taylor, Keir; Klocker, Andreas; Maynard, Phil (2017) Glop Pot data. University of Technology Sydney. Datacrate. http://dx.doi.org/10.1016/something");
},
function(err) {
......
......@@ -53,15 +53,7 @@ A machine-readable version of this page is available:
<?xml version="1.0"?>
<div>
<table id="http://dx.doi.org/10.5281/zenodo.1009240">
<tr>
<th>@id</th>
<td>http://dx.doi.org/10.5281/zenodo.1009240</td>
</tr>
<tr>
<th>@type</th>
<td>Dataset</td>
</tr>
<table class="table" id="http://dx.doi.org/10.5281/zenodo.1009240">
<tr>
<th>Contact</th>
<td>
......@@ -76,7 +68,9 @@ A machine-readable version of this page is available:
</tr>
<tr>
<th>Path</th>
<td>./</td>
<td>
<a href="http://dx.doi.org/10.5281/zenodo.1009240">./</a>
</td>
</tr>
<tr>
<th>Contributor</th>
......@@ -98,21 +92,15 @@ A machine-readable version of this page is available:
<th>Description</th>
<td>This is a simple dataset for demonstration purposes it contains just one image and a directory full of useless text files.</td>
</tr>
<tr>
<th>HasPart</th>
<td 0="[object Object]" 1="[object Object]"/>
</tr>
<tr>
<th>Identifier</th>
<td>http://dx.doi.org/10.5281/zenodo.1009240</td>
</tr>
<tr>
<th>Keywords</th>
<td>Dogs, Fences, The Gully</td>
</tr>
<tr>
<th>Name</th>
<td>Sample dataset for DataCrate v0.2</td>
<td>
<a href="http://dx.doi.org/10.5281/zenodo.1009240">Sample dataset for DataCrate v0.2</a>
</td>
</tr>
<tr>
<th>Publisher</th>
......@@ -125,118 +113,90 @@ A machine-readable version of this page is available:
<td>2017</td>
</tr>
</table>
<h1>Contextual info: GeoCoordinates</h1>
<table>
<table class="table" id="lots_of_little_files">
<tr>
<th>@id</th>
<th>Latitude</th>
<th>Longitude</th>
</tr>
<tr id="263e4cc5-37e6-4bee-a8cd-893e42bec48b">
<td>263e4cc5-37e6-4bee-a8cd-893e42bec48b</td>
<td>-33.7152</td>
<td>150.30119</td>
<th>Path</th>
<td>lots_of_little_files</td>
</tr>
</table>
<h1>Contextual info: Organisation</h1>
<table>
<tr>
<th>@id</th>
<th>Name</th>
</tr>
<tr id="http://uts.edu.au">
<td>http://uts.edu.au</td>
<td>
<a href="http://uts.edu.au">University of Technology Sydney</a>
</td>
<th>Description</th>
<td>This directory contains many small files, that we’re not going to describe in detail.</td>
</tr>
</table>
<h1>Contextual info: Person</h1>
<table>
<tr>
<th>@id</th>
<th>Affiliation</th>
<th>Email</th>
<th>Name</th>
</tr>
<tr id="http://orcid.org/0000-0002-3545-944X">
<td>http://orcid.org/0000-0002-3545-944X</td>
<td>
<a href="#http://uts.edu.au">University of Technology Sydney</a>
</td>
<td>pt@ptsefton.com</td>
<td>
<a href="http://orcid.org/0000-0002-3545-944X">Peter Sefton</a>
</td>
<td>Too many files</td>
</tr>
</table>
<h1>Contextual info: Place</h1>
<table>
<tr>
<th>@id</th>
<th>Description</th>
<th>Geo</th>
<th>Name</th>
</tr>
<tr id="http://www.geonames.org/8152662/catalina-park.html">
<td>http://www.geonames.org/8152662/catalina-park.html</td>
<td>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.</td>
<td>
<table id="263e4cc5-37e6-4bee-a8cd-893e42bec48b">
<tr>
<th>@id</th>
<td>263e4cc5-37e6-4bee-a8cd-893e42bec48b</td>
</tr>
<table class="table" id="pics">
<tr>
<th>@type</th>
<td>GeoCoordinates</td>
<th>Path</th>
<td>pics</td>
</tr>
<tr>
<th>Latitude</th>
<td>-33.7152</td>
<th>Description</th>
<td>This directory contains the images for the research project</td>
</tr>
<tr>
<th>Longitude</th>
<td>150.30119</td>
<th>Name</th>
<td>Pictures</td>
</tr>
</table>
</td>
<td>
<a href="http://www.geonames.org/8152662/catalina-park.html">Catalina Park</a>
</td>
</tr>
<h1>Files: </h1>
<table class="table table-striped">
<thead class="thead-inverse">
<tr/>
</thead>
<tbody class="table-striped"/>
<tr id="pics/19093074_10155469333581584_5707039334816454031_o.jpg"/>
<tr id="pics/CATALOG_pics.xlsx"/>
</table>
<h1>Contextual info: GeoCoordinates</h1>
<table class="table table-striped">
<thead class="thead-inverse">
<tr/>
</thead>
<tbody class="table-striped"/>
<tr id="263e4cc5-37e6-4bee-a8cd-893e42bec48b"/>
</table>
<h1>Contextual info: Organisation</h1>
<table class="table table-striped">
<thead class="thead-inverse">
<tr/>
</thead>
<tbody class="table-striped"/>
<tr id="http://uts.edu.au"/>
</table>
<h1>Contextual info: Person</h1>
<table class="table table-striped">
<thead class="thead-inverse">
<tr/>
</thead>
<tbody class="table-striped"/>
<tr id="http://orcid.org/0000-0002-3545-944X"/>
</table>
<h1>Contextual info: Place</h1>
<table class="table table-striped">
<thead class="thead-inverse">
<tr/>
</thead>
<tbody class="table-striped"/>
<tr id="http://www.geonames.org/8152662/catalina-park.html"/>
</table>
<h1>Contextual info: Project</h1>
<table>
<tr>
<th>@id</th>
<th>Description</th>
<th>Funder</th>
<th>Name</th>
</tr>
<tr id="https://github.com/UTS-eResearch/datacrate">
<td>https://github.com/UTS-eResearch/datacrate</td>
<td>The DataCrate project is to write the spec for DataCrate, of which this is an example.</td>
<td>UTS</td>
<td>
<a href="https://github.com/UTS-eResearch/datacrate">DataCrate</a>
</td>
</tr>
<table class="table table-striped">
<thead class="thead-inverse">
<tr/>
</thead>
<tbody class="table-striped"/>
<tr id="https://github.com/UTS-eResearch/datacrate"/>
</table>
<h1>Contextual info: ScholarlyWork</h1>
<table>
<tr>
<th>@id</th>
<th>DC:CREATOR</th>
<th>Name</th>
</tr>
<tr id="http://dx.doi.org/10.1000/123456">
<td>http://dx.doi.org/10.1000/123456</td>
<td>Peter Sefton</td>
<td>
<a href="http://dx.doi.org/10.1000/123456">This is an example publication with a dodgy DOI</a>
</td>
</tr>
<table class="table table-striped">
<thead class="thead-inverse">
<tr/>
</thead>
<tbody class="table-striped"/>
<tr id="http://dx.doi.org/10.1000/123456"/>
</table>
</div>
......
{
"@context": {
"name": "schema:name",
"givenName": "schema:givenName",
"familyName": "schema:familyName",
"description": "schema:description",
"file": "schema:mediaObject",
"path": "schema:contentUrl",
"contentSize": "schema:contentSize",
......@@ -10,7 +13,6 @@
"issn": "schema:issn",
"datePublished": "schema:datePublished",
"identifier": "schema:identifier",
"description": "schema:description",
"license": "schema:license",
"creator": "schema:creator",
"contributor": "schema:contributor",
......@@ -33,10 +35,10 @@
"contentLocation": "schema:contentLocation",
"keywords": "schema:keywords",
"subject": "schema:subject",
"givenName": "schema:givenName",
"familyName": "schema:familyName",
"Place": "schema:Place",
"Organization": "schema:Organization",
"memberOf": "schema:memberOf",
"member": "schema:hasMember",
"Project": "frapo:Project",
"affiliation": "schema:affiliation",
"Funder": "schema:Funder",
......@@ -66,13 +68,7 @@
},
"@graph": [
{
"@id": "07ad1e37-2eda-4f87-9007-d74f0be0af89",
"@type": "GeoCoordinates",
"latitude": "-35.623592",
"longitude": "148.683836"
},
{
"@id": "353df8b0-a2fc-4fd1-a19d-24c034f60186",
"@id": "1cb61b78-b1b9-4744-90e5-71c4cec66783",
"@type": "Format",
"eXTENSION:": ".svx",
"description": "Survex is a multi-platform open-source cave surveying package.",
......@@ -80,11 +76,11 @@
"mIME:": "text/plain"
},
{
"@id": "63ef54a9-e87b-4b9d-9a2f-0f89449f8686",
"@id": "90490bfb-a7ee-4e50-bb25-7db1d6ff3163",
"@type": "Place",
"description": "Located in the Snowy Mountains Region of NSW, nearest town Tumut 2720",
"geo": {
"@id": "07ad1e37-2eda-4f87-9007-d74f0be0af89"
"@id": "f5968c35-9cb0-4bf9-9ef6-7ccede1ea8e6"
},
"name": "Glop Pot"
},
......@@ -107,7 +103,6 @@
"@id": "asf",
"@type": "Dataset",
"path": "asf",
"description": [],
"hasPart": [
{
"@id": "asf/README.txt"
......@@ -298,6 +293,12 @@
"@id": "https://creativecommons.org/licenses/by/3.0/au/"
}
},
{
"@id": "f5968c35-9cb0-4bf9-9ef6-7ccede1ea8e6",
"@type": "GeoCoordinates",
"latitude": "-35.623592",
"longitude": "148.683836"
},
{
"@id": "http://dx.doi.org/10.1016/something",