Commit 6caac2f2 authored by PTSEFTON's avatar PTSEFTON
Browse files

added support for sameAs URLs in context

parent 13f1c12d
......@@ -76,10 +76,10 @@ if (depth) {
var output_dir = dir;
c.read(dir, "./", undefined, depth);
c.to_json_ld().then(function() {
var text_citation;
var json_helper = new JSON_helper()
json_helper.init(c.json_ld)
var catalog_path = path.join(c.dir, defaults.catalog_json_file_name)
json_helper.trim_context()
fs.writeFileSync(catalog_path, JSON.stringify(json_helper.json_ld, null, 2 ));
generateHTML(catalog_path);
});
......@@ -129,6 +129,8 @@ console.log("Generating html from exsiting " + catalog_path + " file");
"@type": "DataDownload",
"encodingFormat": "zip"
});
json_helper.json_ld["@context"]["DataDownload"] = "https://schema.org/DataDownload"
json_helper.json_ld["@context"]["distribution"] = "https://schema.org/distribution"
json_helper.init(json_helper.json_ld);
}
......
This source diff could not be displayed because it is too large. You can view the blob instead.
......@@ -35,8 +35,8 @@ const builder = require('xmlbuilder');
const Index = require('./index_html.js');
const Datacite = require('./datacite.js')
const DEFAULTS = path.join(__dirname, '../defaults');
const context = require(path.join(DEFAULTS, 'context.json'));
// Copy of default context
var context = JSON.parse(JSON.stringify(defaults.context));
module.exports = function() {
this.collection_metadata = new Item();
......@@ -56,7 +56,6 @@ module.exports = function() {
workbook.Sheets["Collection"]
);
var item_json = {};
for (var i = 0; i < raw_collection_metadata.length; i++) {
var name_value = raw_collection_metadata[i];
if (item_json[name_value["Name"]]) {
......@@ -109,6 +108,7 @@ module.exports = function() {
item_by_path: this.item_by_path,
item_by_id: this.item_by_id,
item_by_type: this.item_by_type,
same_as: this.same_as,
get_unique_catalog_name: function get_unique_catalog_name(
dir,
......@@ -154,13 +154,14 @@ module.exports = function() {
this.root_node = this.item_by_path["./"]
? this.item_by_path["./"]
: this.item_by_path["data/"];
},
},
to_json: function to_json(graph) {
if (!this.collection_metadata) {
this.collection_metadata = new Item();
}
var collection_json = this.collection_metadata.to_json_ld_fragment();
// Need to work out how to do this
......@@ -216,10 +217,13 @@ module.exports = function() {
"@context": context
};
this.to_json(json["@graph"]);
//console.log("JSON", JSON.stringify(json, null, 2));
json = JSON.parse(JSON.stringify(json));
for (var same of this.same_as) {
json["@graph"].push(same)
}
//console.log(JSON.stringify(json, null, 2));
var collection = this;
promise = flattenit(json, this);
......@@ -268,6 +272,7 @@ module.exports = function() {
} else {
this.max_depth = defaults.max_depth;
}
this.same_as = [];
if (parent) {
this.parent = parent;
this.depth = parent.depth + 1;
......@@ -340,6 +345,7 @@ module.exports = function() {
if (catalogs.length > 0) {
if (items.length < defaults.max_files_in_dir) {
try {
this.file_info = JSON.parse(shell.exec('sf -nr -json "' + dir + '"', {silent:true}).stdout);
} catch(e) {
console.error("File identification error: " + e);
......@@ -348,6 +354,7 @@ module.exports = function() {
process.exit(1);
}
this.file_info = JSON.parse(
shell.exec('sf -nr -json "' + dir + '"', { silent: true }).stdout
);
......@@ -364,7 +371,6 @@ module.exports = function() {
sheet_names = this.workbook.SheetNames;
for (var i = 0; i < sheet_names.length; i++) {
sheet_name = sheet_names[i];
//console.log("Processing sheet", sheet_name);
var sheet = this.workbook.Sheets[sheet_name];
//console.log(sheet);
if (sheet_name == "Collection") {
......@@ -412,7 +418,23 @@ module.exports = function() {
// Find subdirs
// Write back
} else {
} else if (sheet_name == "@context") {
extra_context = XLSX.utils.sheet_to_json(
this.workbook.Sheets["@context"]
);
for (var item of extra_context) {
if (item["Key"] && item["Value"]) {
context[item["Key"]] = item["Value"]
if (item["SameAs"]) {
this.same_as.push({"@id": item["Value"], "sameAs": item["SameAs"]})
}
}
}
}
else {
//console.log("getting metaadata", sheet_name)
get_metadata(this.workbook, this, sheet_name);
}
......@@ -455,6 +477,6 @@ module.exports = function() {
//console.log("NAMES HERE", this.name_lookup);
}
}
}
};
}
};
};
......@@ -35,6 +35,9 @@ const DataCrate_Specification_Identifier =
const DataCrate_version = "0.3";
const DataCrate_profile_file = "defaults/profile-datacrate-v" + DataCrate_version + ".json"
const default_context = "defaults/context.json"
const path = require("path")
const DEFAULTS = path.join(__dirname, '../defaults');
const context = require(path.join(DEFAULTS, 'context.json'));
// DataCrate specific terms which have inverses
const back_links = {
......@@ -43,6 +46,8 @@ const back_links = {
hasMember: "memberOf"
};
const back_back_links = new Set(Object.values(back_links))
module.exports = {
......@@ -61,5 +66,6 @@ module.exports = {
DataCrate_version: DataCrate_version,
back_links: back_links,
back_back_links: back_back_links,
DataCrate_profile_file: DataCrate_profile_file
DataCrate_profile_file: DataCrate_profile_file,
context: context
};
......@@ -427,6 +427,9 @@ module.exports = function () {
format_header: function format_header(key) {
el = "";
var term_href = this.helper.get_uri_for_term(key);
if (this.helper.item_by_id[term_href] && this.helper.item_by_id[term_href]["sameAs"]) {
term_href = this.helper.item_by_id[term_href]["sameAs"];
}
if (term_href) {
// TODO deal with more complex case by using JSON-LD library
el += ele("span");
......
......@@ -63,21 +63,17 @@ module.exports = function () {
},
trim_context: function () {
var new_context = {}
for (let term of this.context_keys_used) {
var uri = this.get_uri_for_term(term)
if (!uri) {uri = defaults.context[uri]}
if (uri) new_context[term] = uri
}
for (let type of Object.keys(this.item_by_type)) {
var uri = this.get_uri_for_term(type)
if (uri) new_context[type] = uri
}
for (let back of defaults.back_back_links) {
var uri = this.get_uri_for_term(back)
if (uri) new_context[back] = uri
}
this.json_ld["@context"] = new_context
},
......
......@@ -32,38 +32,16 @@ function lowercase_first(name) {
module.exports = function() {
this.nested_item_json = [];
function get_RDF_for_column(name) {
if (context[name]) {
return context[name]["@id"] ? context[name]["@id"] : context[name];
if (context[name]) {
return context[name];
} else {
return undefined;
}
}
function get_fully_qualified_URI(property_name) {
/*
Look up the data dictionary to get an RDF name for column_name.
*/
property_name = property_name["@id"] ? property_name["@id"] : property_name;
if (context[property_name]) {
property_name = context[property_name]["@id"]
? context[property_name]["@id"]
: context[property_name];
}
if (property_name && property_name.includes(":")) {
split_name = property_name.split(":", 2);
//console.log(split_name);
namespace = split_name[0];
name = split_name[1];
//console.log("Looking up name", namespace, name)
if (namespace in context && name) {
return context[namespace] + name;
}
}
return undefined;
}
return {
// Functions, public so they can be tested
get_fully_qualified_URI: get_fully_qualified_URI,
get_RDF_for_column: get_RDF_for_column,
// Public properties
is_repeating: this.is_repeating,
......@@ -143,17 +121,12 @@ module.exports = function() {
this.data = "";
}
this.property = get_RDF_for_column(this.name);
if (this.property) {
this.property_URI = get_fully_qualified_URI(this.property);
} else {
this.property_URI = undefined;
}
this.property_URI = get_RDF_for_column(this.name);
//console.log("Looking for IDs", this.name, this.property_URI)
if (this.property_URI == "https://schema.org/identifier") {
this.is_id = true;
//console.log("WE GOT AN ID", this.name)
}
if (this.property_URI == "https://schema.org/name") {
......
This diff is collapsed.
<html>
<head>
<style>
table {
width: 90%;
text-align: left;
vertical-align: top;
margin-bottom: 2em;
}
td {
margin-right: 2em;
white-space: normal;
}
details {
margin-left: 2em;
}
.break {
word-break: break-all;
}
div.collection {
margin-left: +1em;
}
</style>
<script type="application/ld+json">
{
"@id": "0d6ab5d0-cacb-4839-8208-a7b99ebdb8a6",
"@type": [
"Person"
],
"affiliation": [
{
"@id": "1"
}
],
"familyName": [
"Cook"
],
"givenName": [
"Janet"
],
"name": [
"Janet Cook"
],
"@reverse": {
"creator": [
{
"@id": "http://doi.org/10.4225/59/59672c09f4a4b"
},
{
"@id": "http://journals.plos.org/plosone/article?id=10.1371/journal.pone.0181020"
}
]
}
}
</script>
<link rel="stylesheet"
href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css"
integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u"
crossorigin="anonymous"/>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css">
<meta charset='utf-8'/>
</head>
<body>
<nav class="navbar navbar-inverse">
<ul class="nav navbar-nav" >
<li >
<a href=../../../../../../../../../../../../../../../../../../../../CATALOG.html><button type="button" class="btn btn-default btn-sm"><span class="glyphicon glyphicon-home"></span>&nbsp;Data files associated with the manuscript:Effects of facilitated family case conferencing for advanced dementia: A cluster randomised clinical trial</button></a> </li>
</ul>
</nav>
<div class="container">
<div class="jumbotron">
<h3>Data files associated with the manuscript:Effects of facilitated family case conferencing for advanced dementia: A cluster randomised clinical trial</h3>
<h4></h4>
</div>
<table class = 'table' id = '0d6ab5d0-cacb-4839-8208-a7b99ebdb8a6'
><hr
><tr
><th style = 'white-space: nowrap; width: 1%;'
>@id</th
><td
>0d6ab5d0-cacb-4839-8208-a7b99ebdb8a6</td
></tr
><tr
><th
><span
>name<sup
><a href = 'http://schema.org/name' title = 'Definition of: name'
>?</a
></sup
></span
></th
><td
><b
>Janet Cook</b
></td
></tr
><tr
><th
>@type</th
><td
><span
>Person<sup
><a href = 'http://schema.org/Person' title = 'Definition of: Person'
>?</a
></sup
></span
></td
></tr
><tr
><th
>Items referencing this:</th
><td
><table class = 'table'
><tr
><th style = 'white-space: nowrap; width: 1%;'
>Relationship</th
><th
>Referenced-by</th
></tr
><tr
><th
>creator</th
><td
><ul
><li
><a href = '../../../../../../../../../../../../../../../../../../../../CATALOG.html'
>Data files associated with the manuscript:Effects of facilitated family case conferencing for advanced dementia: A cluster randomised clinical trial</a
></li
><li
><a href = '../../../../../../../../../../../../../../../../../../ht/tp/+=/=j/ou/rn/al/s,/pl/os/,o/rg/=p/lo/so/ne/=a/rt/ic/le/^3/fi/d^/3d/10/,1/37/1=/jo/ur/na/l,/po/ne/,0/18/10/20/index.html'
>Effects of facilitated family case conferencing for advanced dementia: A cluster randomised clinical trial</a
></li
></ul
></td
></tr
></table
></td
></tr
><tr
><th
><span
>affiliation<sup
><a href = 'http://schema.org/affiliation' title = 'Definition of: affiliation'
>?</a
></sup
></span
></th
><td
><a href = '../../../../../../../../../../../../../../../../../../1/index.html'
>Faculty of Health, University of Technology Sydney</a
></td
></tr
><tr
><th
><span
>familyName<sup
><a href = 'http://schema.org/familyName' title = 'Definition of: familyName'
>?</a
></sup
></span
></th
><td
>Cook</td
></tr
><tr
><th
><span
>givenName<sup
><a href = 'http://schema.org/givenName' title = 'Definition of: givenName'
>?</a
></sup
></span
></th
><td
>Janet</td
></tr
></table
>
<p>This file was created at 2018-09-18T02:50:33.315Z by
<a href='https://code.research.uts.edu.au/eresearch/calcytejs'>
Calcyte</a> which implements the <a href='https://github.com/UTS-eResearch/datacrate/blob/master/spec/0.3/data_crate_specification_v0.3.md'>
Draft DataCrate Packaging format</a>, version 0.3
</p>
</body>
</html>
<html>
<head>
<style>
table {
width: 90%;
text-align: left;
vertical-align: top;
margin-bottom: 2em;
}
td {
margin-right: 2em;
white-space: normal;
}
details {
margin-left: 2em;
}
.break {
word-break: break-all;
}
div.collection {
margin-left: +1em;
}
</style>
<script type="application/ld+json">
{
"@id": "1",
"@type": [
"Organization"
],
"address": [
"Ultimo NSW Australia"
],
"identifier": [
"1"
],
"memberOf": [
{
"@id": "http://uts.edu.au"
}
],
"name": [
"Faculty of Health, University of Technology Sydney"
],
"@reverse": {
"affiliation": [
{
"@id": "0d6ab5d0-cacb-4839-8208-a7b99ebdb8a6"
},
{
"@id": "http://nla.gov.au/nla.party-1509834"
},
{
"@id": "http://orcid.org/0000-0001-6121-5409"
},
{
"@id": "http://orcid.org/0000-0002-3691-8230"
},
{
"@id": "http://orcid.org/0000-0002-6756-6119"
}
]
}
}
</script>
<link rel="stylesheet"
href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css"
integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u"
crossorigin="anonymous"/>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css">
<meta charset='utf-8'/>
</head>
<body>
<nav class="navbar navbar-inverse">
<ul class="nav navbar-nav" >
<li >
<a href=../../../CATALOG.html><button type="button" class="btn btn-default btn-sm"><span class="glyphicon glyphicon-home"></span>&nbsp;Data files associated with the manuscript:Effects of facilitated family case conferencing for advanced dementia: A cluster randomised clinical trial</button></a> </li>
</ul>
</nav>
<div class="container">
<div class="jumbotron">
<h3>Data files associated with the manuscript:Effects of facilitated family case conferencing for advanced dementia: A cluster randomised clinical trial</h3>
<h4></h4>
</div>