-
Notifications
You must be signed in to change notification settings - Fork 3
/
rdf2hk.js
70 lines (50 loc) · 1.4 KB
/
rdf2hk.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
/*
* Copyright (c) 2016-present, IBM Research
* Licensed under The MIT License [see LICENSE for details]
*/
"use strict";
let parser = require("./parser");
let GraphFactory = require("./graphfactory");
const Timer = require("ninja-util/timer");
let fs = require("fs");
let outFile = null;
let mimeType = "text/turtle";
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];
console.log("Mime type", mimeType);
}
let inputData = fs.readFileSync(inputPath, "utf-8");
let t = new Timer();
GraphFactory.parseGraph(inputData, mimeType, (err, graph) =>
{
if(err)
{
console.log(err);
console.log("Could not load input data");
return;
}
t.tick("Parsing rdf time");
let options = {};
let hkentities = parser.parseGraph(graph, options);
t.tick("Conversion done");
if(!outFile)
{
console.log(JSON.stringify(Object.values(hkentities), null, " "));
}
else
{
fs.writeFileSync(outFile, JSON.stringify(Object.values(hkentities), null, " "), {encoding: "utf-8"})
console.log("Written");
}
});
}
// console.log(out);
// console.log(JSON.stringify(Object.values(triples), null, " "));