-
Notifications
You must be signed in to change notification settings - Fork 0
/
getSomeQueries.js
58 lines (47 loc) · 1.63 KB
/
getSomeQueries.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
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 pattern = 'GRAPH bio2rdf:bioportal_resource:bio2rdf.dataset.bioportal.R3';
const pattern = '?mesh';
const queriesOutputStream = fs.createWriteStream('./output/meshQueries.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)) {
if (query.indexOf(pattern) !== -1) {
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);
});