-
Notifications
You must be signed in to change notification settings - Fork 0
/
getQueries.js
53 lines (43 loc) · 1.45 KB
/
getQueries.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
import rdfParser from "rdf-parse";
import fs from "fs";
import { stringify } from 'csv-stringify';
const path = './input/input.nt';
const inputStream = fs.createReadStream(path);
const queriesOutputStream = fs.createWriteStream('./output/queries.csv');
const parser = rdfParser.default;
const queryMap = {};
var queryCount = 0;
const stringifier = stringify({
delimiter: ','
});
stringifier.on('readable', function(){
let row;
while((row = stringifier.read()) !== null){
queriesOutputStream.write(row);
}
});
const prefixLength = 'http://lsq.aksw.org/lsqQuery-'.length;
parser.parse(inputStream, {path})
.on('data', (quad) => {
// console.log(quad._predicate);
if (quad._predicate.id === 'http://lsq.aksw.org/vocab#text') {
// console.log(stringify({
// id: quad._subject.id,
// query: quad._object
// }));
const id = quad._subject.id.substr(prefixLength);
const query = quad._object.value;
if (!(id in queryMap)) {
stringifier.write([quad._subject.id.substr(prefixLength), quad._object.value]);
queryMap[id] = true;
queryCount++;
}
// console.log(quad);
}
})
.on('error', (error) => console.error(error))
.on('end', () => {
stringifier.end();
console.log('All done!');
console.log('# of queries: ' + queryCount);
});