-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathserver.js
223 lines (169 loc) · 6.72 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
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
// 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();
const negativeBill = [];
const negativeLogin = [];
const negativeUsagePlan = [];
const negativeNativeDevice =[];
const positive = [];
// 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"
// ];
var batchInput = [
"This app is not that great. Billing crashes sometimes",
"Telus does listen, the issue from previous release was quickly fixed.",
"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",
"bill expensive crash android"
];
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];
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)
// put NEGATIVE stuff into right department array
if(key == "bill" || key == "billing" || key == "overcharged" || key == "surcharge")
{
negativeBill.push(batchInput[i]);
}
else if(key == "login" )
{
negativeLogin.push(batchInput[i]);
}
else if(key == "usage" || key == "data" || key == "plan" || key == "plans" || key == "overage"
|| key == "offers" || key == "top-up" || key == "travel" || key == "travelpass" )
{
negativeUsagePlan.push(batchInput[i]);
}
else if(key == "android" || key == "iphone" || key == "device")
{
negativeNativeDevice.push(batchInput[i]);
}
}
}
}
}
var superResponse = function(res) {
for (var i = 0; i < res.length; i++) {
// console.log(res[i]);
if (res[i] < 0.4) {
//console.log(batchInput[i]);
// console.log("negative");
// write to json with positive sentiment tag
// get keywords
console.log("less than 0.4");
indico.keywords(batchInput, settings)
.then(keywordsResponse);
}
else if (res[i] > 0.4 && res[i] < 0.7) {
//console.log(batchInput[i]);
//console.log("neutral");
// write to json with neutral sentiment tag
// get keywords
console.log("greater than 0.4");
indico.keywords(batchInput, settings)
.then(keywordsResponse);
}
else {
//console.log(batchInput[i]);
//console.log("positive");
positive.push(batchInput[i]);
// console.log(positive);
}
}
console.log("Negative feedbacks for billing: " + negativeBill);
console.log("Negative feedbacks for login: " + negativeLogin);
console.log("Negative feedbacks for usage or plans: " + negativeUsagePlan);
console.log("Negative feedbacks for native devices: " + negativeNativeDevice);
console.log("Postive feedbacks: " + positive);
}
var logError = function(err) {
console.log(err);
}
indico.sentiment(batchInput, settings)
.then(superResponse)
.catch(logError);