-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
executable file
·72 lines (66 loc) · 1.92 KB
/
index.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
71
72
var request = require('request');
var https = require('https');
var fs = require('fs');
var io = require('socket.io');
if(!process.env.HTTPS){
io = io.listen(process.env.SOCKET_PORT);
}else{
var pkey = fs.readFileSync('key.pem');
var pcert = fs.readFileSync('cert.pem');
var options = {
key: pkey,
cert: pcert
};
var app = https.createServer(options, function(req, res){
res.writeHead(200);
res.end("welcome to vardot!\n");
});
io = io.listen(app);
app.listen(process.env.SOCKET_PORT);
}
var proccessData = function(data){
var tags = {}
var groupedTags = {}
if(data && data["@graph"]){
for(id in data["@graph"]){
var graph = data["@graph"][id];
if(graph && graph["enhancer:entity-label"]){
var tag = graph["enhancer:entity-label"]["@value"];
var stripedTag = tag.toLowerCase().replace(/[\s\+\=\_\(\)\[\]\<\>\@\?]/ig,"-");
tags[stripedTag] = tag;
if(graph["enhancer:entity-type"]){
for(var gid in graph["enhancer:entity-type"]){
var group = graph["enhancer:entity-type"][gid];
if(group.indexOf("dbp-ont:") > -1){
var groupName = group.replace(/dbp-ont\:/, "")
groupedTags[groupName] = groupedTags[groupName] || {};
groupedTags[groupName][stripedTag] = tag;
}
}
}
}
}
}
return {tags: tags, groupedTags: groupedTags};
}
io.on('connection', function (socket) {
socket.on("stanbol", function(data, callback){
var options = {
url: process.env.STANBOL_URL,
headers: {
'Accept': 'application/json',
'Content-type': 'text/plain'
},
body: data.text
};
request.post(options,function (error, response, body) {
if (!error && response.statusCode == 200) {
var info = JSON.parse(body);
var data = proccessData(info);
callback(data);
}else{
console.log({error: error});
}
});
});
});