-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathget_sentiment.cpp
103 lines (82 loc) · 1.8 KB
/
get_sentiment.cpp
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
/******************************************************
*
* CS383 Project -- Social Media and Political Mood
* Team Vikings -- Gresham, Serendel, and Ryan
*
* Sentiment analysis powered by AlchemyAPI
* Learn more about this service at www.alchemyapi.com
*
* get_sentiment.cpp
*
******************************************************/
#include <vector>
#include <string>
#include "sentiment/sentiment.h"
#include "tweet/tweet.h"
#include "keywords/keywords.h"
#include "config/config.h"
#include "config/logger.h"
using namespace std;
void print_tweet(tweet t)
{
static vector<string> l_keywords;
if(l_keywords.size() == 0)
{
keywords::load_liberal(l_keywords);
}
bool has_liberal_keyword = false;
for (int i = 0; i < l_keywords.size(); i++)
{
if (string::npos != t.m_text.find(l_keywords[i]))
{
t.m_liberal = t.m_sentiment * t.m_weight;
has_liberal_keyword = true;
break;
}
}
if(!has_liberal_keyword)
{
t.m_conservative = t.m_sentiment * t.m_weight;
}
t.print(tweet::LIBERAL | tweet::CONSERVATIVE);
}
int main(int argc, char **argv)
{
INFO_LOG << "starting get_sentiment process\n";
vector<string> all_keywords;
keywords::load_conservative(all_keywords);
keywords::load_liberal(all_keywords);
string line = "";
sentiment s = sentiment();
tweet t_done;
while(getline(cin, line))
{
tweet t_in = tweet(line.c_str());
for(int i = 0; i < all_keywords.size(); i++)
{
if(string::npos != t_in.m_text.find(all_keywords[i]))
{
s.send_request(t_in, all_keywords[i]);
break;
}
}
s.remaining_requests();
while(s.pop_tweet(t_done))
{
print_tweet(t_done);
}
}
while(s.remaining_requests() > 0)
{
while(s.pop_tweet(t_done))
{
print_tweet(t_done);
}
}
while(s.pop_tweet(t_done))
{
print_tweet(t_done);
}
s.cleanup_requests();
return 0;
}