-
Notifications
You must be signed in to change notification settings - Fork 3
/
hk2rdf.js
93 lines (65 loc) · 1.74 KB
/
hk2rdf.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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
/*
* Copyright (c) 2016-present, IBM Research
* Licensed under The MIT License [see LICENSE for details]
*/
"use strict";
let Serializer = require("./serializer");
let GraphFactory = require("./graphfactory");
let fs = require("fs");
let mimeType = "application/rdf+xml";
const Timer = require("ninja-util/timer");
let outFile = null;
let SUPPORTED_MIME_TYPES = new Set();
SUPPORTED_MIME_TYPES.add("application/n-quads");
SUPPORTED_MIME_TYPES.add("application/json");
SUPPORTED_MIME_TYPES.add("text/turtle");
SUPPORTED_MIME_TYPES.add("application/turtle");
SUPPORTED_MIME_TYPES.add("application/trig");
SUPPORTED_MIME_TYPES.add("application/n-triples");
// const Timer = require("ninja-util/timer");
if(process.argv.length > 2)
{
let inputPath = process.argv[2];
if(process.argv.length > 3)
{
outFile = process.argv[3];
}
if(process.argv.length > 4)
{
mimeType = process.argv[4];
}
if(!SUPPORTED_MIME_TYPES.has(mimeType))
{
console.log(`Mimetype "${mimeType}" not supported`);
return;
}
let inputData = fs.readFileSync(inputPath, "utf-8");
// let options = {convertHK: false,
// convertNumber: true,
// compressReification: true,};
// let options = {convertHK: true};
let options = {};
let entities = JSON.parse(inputData);
let t = new Timer();
let graph = GraphFactory.createGraph(mimeType);
Serializer.serialize(entities, options, graph);
t.tick("Conversion done");
GraphFactory.serializeGraph(graph, (err, data) =>
{
if(!err)
{
if(outFile)
{
fs.writeFileSync(outFile, data, {encoding: "utf-8"});
}
else
{
console.log(JSON.stringify(triples, null, " "));
}
}
else
{
console.error(err);
}
});
}