forked from shahenak/feedback-analysis
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserver.js
146 lines (112 loc) · 3.7 KB
/
server.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
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
// Get dependencies
const express = require('express');
const path = require('path');
const http = require('http');
const bodyParser = require('body-parser');
const firebase = require('firebase-admin');
const indico = require('indico.io')
// Get API routes from api file in routes folder
const api = require('./server/routes/api');
const app = express();
// Parsers for POST data
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({ extended: false }));
// Point static path to dist so compiled files moved to dist folder on app build
app.use(express.static(path.join(__dirname, 'dist')));
// Set our api routes
app.use('/api', api);
// Catch all other routes and return the index file; invalid urls redirected to homepage
app.get('*', (req, res) => {
res.sendFile(path.join(__dirname, 'dist/index.html'));
});
/**
* Get port from environment and store in Express.
*/
const port = process.env.PORT || '3000';
app.set('port', port);
/**
* Create HTTP server.
*/
const server = http.createServer(app);
/**
* Listen on provided port, on all network interfaces.
*/
server.listen(port, () => console.log(`API running on localhost:${port}`));
var settings = {"api_key": "70fa9c87529dc0cd4e5dc150938f744e"};
const json = require('./feedback.json');
var comments = new Map();
var batchInput = [];
for (var i in json) {
if (json[i].comments.toString().length > 0) {
comments[json[i]["responseId"]] = json[i].comments;
batchInput.push(json[i].comments)
}
}
// var batchInput = [
// "This app is so shit",
// "I can't pay my bill",
// "I can't login since new update",
// "Keeps crashing everytime I try to pay bills",
// "Great app! Best out of most telecoms",
// "keeps showing an error on offers page"
// ];
console.log(batchInput);
const appSectionsDict = [
"bill", "billing", "login", "usage", "data",
"top-up", "android", "site", "mobile", "offers",
"iphone", "travelpass", "travel", "plan", "plans",
"device", "overage", "surcharge", "overcharged",
];
const negativeKeywordsDict = [
"expensive", "crash", "crashes", "crashed", "crashing",
"pricey", "fuck", "shit", "error", "bugs",
"bug", "outages", "outage", "slow", "glitchy"
]
var sentimentResponse = function(res) {
for (var i = 0; i < res.length; i++) {
console.log(res[i]);
if (res[i] > 0.7) {
console.log("positive")
// write to json with positive sentiment tag
}
else if (res[i] > 0.4 && res[i] < 0.7) {
console.log("neutral")
// write to json with neutral sentiment tag
}
else {
console.log("negative")
// write to json with negative sentiment tag
}
}
}
var keywordsResponse = function (res) {
for (var i = 0; i < res.length; i++) {
let keys = Object.keys(res[i]);
for (var j = 0 ; j < keys.length; j++) {
let key = keys[j];
// filter by negative words
if (negativeKeywordsDict.indexOf(key.toString()) > -1) {
console.log("keyword found: " + key);
// write to json with negative keyword tag
}
// filter by app sections
if (appSectionsDict.indexOf(key.toString()) > -1) {
console.log("section found: " + key)
}
// write to json with section tag
}
}
}
var logError = function(err) {
console.log(err);
}
//
indico.sentiment(batchInput, settings)
.then(sentimentResponse)
.catch(logError);
// indico.emotion(batchInput, settings)
// .then(emotionResponse)
// .catch(logError);
// indico.keywords(batchInput, settings)
// .then(keywordsResponse)
// .catch(logError);