-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsentiment-analysis.js
More file actions
42 lines (39 loc) · 931 Bytes
/
sentiment-analysis.js
File metadata and controls
42 lines (39 loc) · 931 Bytes
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
const Promise = require('bluebird');
const request = require('request-promise');
const tweetAnalysis = require('./tweet-analysis');
let api = {
getSentiment(tweet) {
let newTweetText = tweetAnalysis.removeRT(tweet.text);
let options = {
method: 'POST',
uri: 'http://text-processing.com/api/sentiment/',
form: {
text: newTweetText
}
};
return request(options)
.then((body) => {
let sentiment = JSON.parse(body);
return sentiment.label;
})
.catch((err) => console.error(err));
}
};
exports.addSentiment = function(tweet) {
return new Promise((resolve, reject) => {
api.getSentiment(tweet)
.then((label) => {
tweet.sentiment = label
resolve(tweet);
})
.catch((err) => {
reject(err);
});
});
}
exports.shouldBuy = function(sentiment) {
if (sentiment === 'pos') {
return true;
}
return false;
}