-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathprocessing.js
30 lines (23 loc) · 858 Bytes
/
processing.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
const fs = require('fs');
const ParserN3 = require('@rdfjs/parser-n3');
const SerializerJsonLd = require('@rdfjs/serializer-jsonld');
const inputTurtle = fs.readFileSync('/Users/sam/Documents/VU/Thesis/Code/data.ttl', 'utf8');
const context = {
'@base': 'http://localhost:8080/',
'@vocab': 'http://localhost:8080/',
};
const parser = new ParserN3();
const serializer = new SerializerJsonLd({ context });
const inputStream = parser.import(inputTurtle);
const outputStream = serializer.import(inputStream);
const jsonLdChunks = [];
outputStream.on('data', (chunk) => {
jsonLdChunks.push(chunk);
});
outputStream.on('end', () => {
const jsonLd = JSON.stringify({ '@graph': jsonLdChunks }, null, 2);
fs.writeFileSync('data.json', jsonLd);
});
outputStream.on('error', (error) => {
console.error('Error converting RDF to JSON-LD:', error);
});