-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcomunica-query.ts
More file actions
165 lines (145 loc) · 6.67 KB
/
Copy pathcomunica-query.ts
File metadata and controls
165 lines (145 loc) · 6.67 KB
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
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
import { RSPQLParser, R2ROperator, QuadContainer, RSPEngine } from "rsp-js";
const N3 = require('n3');
import { Quad } from 'n3';
const { DataFactory } = N3;
const { namedNode, quad, literal, defaultGraph } = DataFactory;
const ldes_acc_x = "http://n078-03.wall1.ilabt.imec.be:3000/pod1/acc-x/";
const ldes_acc_y = "http://n078-03.wall1.ilabt.imec.be:3000/pod1/acc-y/";
const ldes_acc_z = "http://n078-03.wall1.ilabt.imec.be:3000/pod1/acc-z/";
async function main() {
``
const query = `
PREFIX saref: <https://saref.etsi.org/core/>
PREFIX func: <http://extension.org/functions#>
PREFIX dahccsensors: <https://dahcc.idlab.ugent.be/Homelab/SensorsAndActuators/>
PREFIX podx: <http://n078-03.wall1.ilabt.imec.be:3000/pod1/acc-x/>
PREFIX pody: <http://n078-03.wall1.ilabt.imec.be:3000/pod1/acc-y/>
PREFIX podz: <http://n078-03.wall1.ilabt.imec.be:3000/pod1/acc-z/>
PREFIX : <https://rsp.js/>
REGISTER RStream <output> AS
SELECT *
FROM NAMED WINDOW podx: ON STREAM <${ldes_acc_x}> [RANGE 6 STEP 3]
FROM NAMED WINDOW pody: ON STREAM <${ldes_acc_y}> [RANGE 6 STEP 3]
FROM NAMED WINDOW podz: ON STREAM <${ldes_acc_z}> [RANGE 6 STEP 3]
WHERE {
WINDOW podx: {
?s saref:hasValue ?o .
?s saref:relatesToProperty dahccsensors:wearable.acceleration.x .
}
}
`;
let rspql_parser = new RSPQLParser();
let parsed_query = rspql_parser.parse(query);
console.log(parsed_query.sparql);
let r2r = new R2ROperator(parsed_query.sparql);
let quad_set = new Set<Quad>();
let number_of_quads = 100 / 3;
let rsp_engine = new RSPEngine(query);
let rsp_emitter = rsp_engine.register();
let stream_one = rsp_engine.getStream(ldes_acc_x);
let stream_two = rsp_engine.getStream(ldes_acc_y);
let stream_three = rsp_engine.getStream(ldes_acc_z);
if (stream_one && stream_two && stream_three) {
const stream_element_one = quad(
namedNode('https://rsp.js/test_subject_1'),
namedNode('https://saref.etsi.org/core/hasValue'),
literal(`${Math.random() * 10
} `, namedNode('http://www.w3.org/2001/XMLSchema#integer')),
defaultGraph()
// namedNode('http://n078-03.wall1.ilabt.imec.be:3000/pod1/acc-x/'),
);
const stream_element_two = quad(
namedNode('https://rsp.js/test_subject_1'),
namedNode('https://saref.etsi.org/core/relatesToProperty'),
namedNode('https://dahcc.idlab.ugent.be/Homelab/SensorsAndActuators/wearable.acceleration.x'),
defaultGraph()
// namedNode('http://n078-03.wall1.ilabt.imec.be:3000/pod1/acc-x/'),
);
stream_one.add(stream_element_one, 0);
stream_one.add(stream_element_two, 0);
stream_one.add(stream_element_one, 1);
stream_one.add(stream_element_two, 1);
stream_one.add(stream_element_one, 2);
stream_one.add(stream_element_two, 2);
stream_one.add(stream_element_one, 3);
stream_one.add(stream_element_two, 3);
stream_one.add(stream_element_one, 4);
stream_one.add(stream_element_two, 4);
stream_one.add(stream_element_one, 5);
stream_one.add(stream_element_two, 5);
stream_one.add(stream_element_one, 6);
stream_one.add(stream_element_two, 6);
stream_one.add(stream_element_one, 7);
stream_one
}
rsp_emitter.on('RStream', (data: any) => {
console.log(data.bindings.toString());
});
for (let i = 0; i < number_of_quads; i++) {
const stream_element = quad(
namedNode('https://rsp.js/test_subject_' + i),
namedNode('https://saref.etsi.org/core/hasValue'),
literal(`${Math.random() * 10
} `, namedNode('http://www.w3.org/2001/XMLSchema#integer')),
// defaultGraph()
namedNode('http://n078-03.wall1.ilabt.imec.be:3000/pod1/acc-x/'),
);
const stream_element2 = quad(
namedNode('https://rsp.js/test_subject_' + i),
namedNode('https://saref.etsi.org/core/relatesToProperty'),
namedNode('https://dahcc.idlab.ugent.be/Homelab/SensorsAndActuators/wearable.acceleration.x'),
// defaultGraph()
namedNode('http://n078-03.wall1.ilabt.imec.be:3000/pod1/acc-x/'),
);
quad_set.add(stream_element);
quad_set.add(stream_element2);
}
for (let i = 0; i < number_of_quads; i++) {
const stream_element = quad(
namedNode('https://rsp.js/test_subject_' + i),
namedNode('https://saref.etsi.org/core/hasValue'),
literal(`${Math.random() * 10} `, namedNode('http://www.w3.org/2001/XMLSchema#integer')),
// defaultGraph()
namedNode('http://n078-03.wall1.ilabt.imec.be:3000/pod1/acc-y/'),
);
const stream_element2 = quad(
namedNode('https://rsp.js/test_subject_' + i),
namedNode('https://saref.etsi.org/core/relatesToProperty'),
namedNode('https://dahcc.idlab.ugent.be/Homelab/SensorsAndActuators/wearable.acceleration.x'),
// defaultGraph()
namedNode('http://n078-03.wall1.ilabt.imec.be:3000/pod1/acc-y/'),
);
quad_set.add(stream_element);
quad_set.add(stream_element2);
}
for (let i = 0; i < number_of_quads; i++) {
const stream_element = quad(
namedNode('https://rsp.js/test_subject_' + i),
namedNode('https://saref.etsi.org/core/hasValue'),
literal(`${Math.random() * 10} `, namedNode('http://www.w3.org/2001/XMLSchema#integer')),
// defaultGraph()
namedNode('http://n078-03.wall1.ilabt.imec.be:3000/pod1/acc-z/'),
);
const stream_element2 = quad(
namedNode('https://rsp.js/test_subject_' + i),
namedNode('https://saref.etsi.org/core/relatesToProperty'),
namedNode('https://dahcc.idlab.ugent.be/Homelab/SensorsAndActuators/wearable.acceleration.x'),
// defaultGraph()
namedNode('http://n078-03.wall1.ilabt.imec.be:3000/pod1/acc-z/'),
);
quad_set.add(stream_element);
quad_set.add(stream_element2);
}
let quad_container = new QuadContainer(quad_set, 0);
let time = new Date().getTime();
let cpu_now = process.cpuUsage();
console.log('CPU usage: ', cpu_now);
// let bindings_stream = await r2r.execute(quad_container);
let cpu_then = process.cpuUsage(cpu_now);
let cpu_without_diff = process.cpuUsage();
console.log('CPU without diff: ', cpu_without_diff);
console.log('CPU diff: ', cpu_then);
console.log('Execution time: ', new Date().getTime() - time);
let count = 0;
}
main();