-
Notifications
You must be signed in to change notification settings - Fork 1
/
ldes_v1.js
57 lines (52 loc) · 1.74 KB
/
ldes_v1.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
const fs = require('fs');
exports.generateLDES = function (dir,baseUrl) {
console.log(`generating ldes for ${dir}...`);
fs.readdir(dir, (err,files) => {
if (err)
throw err;
files.forEach( (file) => {
const stats = fs.statSync(`${dir}/${file}`);
if (stats.isDirectory() && file.match(/^[A-Za-z0-9]/)) {
_generateLDES(`${dir}/${file}`,baseUrl);
}
});
});
}
function _generateLDES(dir,baseUrl) {
const path = dir.replace('\/[^\/]+$','');
const subdir = dir.replace(/.*\//g,'');
const id = `${baseUrl}/${subdir}.jsonld`;
const ldes = {
"@context" : {
"ldes" : "https://w3id.org/ldes#",
"tree" : "https://w3id.org/tree#",
"ldp" : "http://www.w3.org/ns/ldp#",
"dc" : "http://purl.org/dc/elements/1.1/",
"ov" : "http://open.vocab.org/terms/",
"tree:member": { "@container": "@list"} ,
"tree:node": { "@type" : "@id" }
} ,
"@id": `${id}#EventStream`,
"@type": [
"ldes:EventStream" ,
"evt:EventLog"
],
"tree:view" : {
"@type": "tree:Node" ,
"tree:viewDescription": {
"@type": "tree:ViewDescription" ,
"ldes:managedBy": {
"@type": "ldes:LDESinLDPClient"
}
},
"tree:relation" : {
"@type": "tree:GreaterThanOrEqualToRelation" ,
"tree:node" : {
"@id" : `${baseUrl}/${subdir}/`
}
}
}
};
console.log(`generating ${path}.jsonld`);
fs.writeFileSync(`${path}.jsonld`,JSON.stringify(ldes,null,2));
}