-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathusergroupsToRDF.js
56 lines (51 loc) · 1.36 KB
/
usergroupsToRDF.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
var ndjson = require('ldjson-stream');
var fs = require('fs');
const prefixes = `
@prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> .
@prefix swV: <http://rdf.slidewiki.org/vocab/> .
@prefix swR: <https://slidewiki.org/usergroup/> .
@prefix swUserR: <https://slidewiki.org/user/> .
@prefix prv: <http://purl.org/net/provenance/ns#> .
`;
//write prefixes
console.log(prefixes);
fs.createReadStream('data/usergroups.txt')
.pipe(ndjson.parse({strict: false}))
.on('data', function(obj) {
convertToRDF(obj);
})
.on('error', function(obj) {
console.log('#######Error#########');
});
//list of selected properties
const selected = [
'_id',
'name',
'description',
'isActive',
'timestamp',
'members',
'creator'
];
const idField = '_id';
function convertToRDF(obj) {
//print turtle
let id = obj[idField];
console.log(`swR:${id} a swV:UserGroup .`);
for(let prop in obj){
if(selected.indexOf(prop) !== -1){
if(prop === 'creator'){
console.log(`swR:${id} prv:createdBy swUserR:${obj[prop].userid} .`);
continue;
}
if(prop === 'members'){
obj[prop].forEach((item)=>{
console.log(`swR:${id} swV:hasMember swUserR:${item.userid} .`);
});
continue;
}
console.log(`swR:${id} swV:${prop} """${obj[prop] ? obj[prop] : '-'}""" .`);
}
}
console.log('################');
}