-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTweetProcessor.scala
222 lines (202 loc) · 8.58 KB
/
TweetProcessor.scala
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
/******************************************************/
/* Spark Streaming with Scala */
/* Listening on 5678 for data from Java server */
/******************************************************/
import org.apache.spark.SparkConf
import org.apache.spark.SparkContext
import org.apache.spark.SparkContext._
import org.apache.spark.storage._
import org.apache.spark.HashPartitioner
import org.apache.spark.streaming.StreamingContext
import org.apache.spark.streaming.StreamingContext._
import org.apache.spark.streaming.dstream.DStream
import org.apache.spark.streaming.Duration
import scredis._
import scala.util._
import scala._
object TweetProcessor
{
val oneSecond = 1000;
val fiveSeconds = 5000;
def main(args: Array[String])
{
val conf = new SparkConf().setMaster("local[4]").setAppName("Tweet Processing")
val ssc = new StreamingContext(conf, new Duration(oneSecond))
val lines = ssc.socketTextStream("localhost", 5678)
val negativeSentiment = lines.filter
{
line => line.contains("caused my liver to be damaged") ||
line.contains("caused liver damage") ||
line.contains("caused my liver damage") ||
line.contains("caused breathing problems") ||
line.contains("have breathing problems") ||
line.contains("have breathing trouble") ||
line.contains("have kidney problems") ||
line.contains("trouble breathing") ||
line.contains("breathing problems") ||
line.contains("heart palpitations") ||
line.contains("irregular heart beat") ||
line.contains("I have kidney problems") ||
line.contains("I have kidney damage") ||
line.contains("caused kidney problems") ||
line.contains("caused kidney damage") ||
line.contains("caused cancer") ||
line.contains("have cancer") ||
line.contains("now has cancer") ||
line.contains("developed cancer") ||
line.contains("had a stroke") ||
line.contains("caused a stroke") ||
line.contains("caused neurological problems") ||
line.contains("developed neurological problems") ||
line.contains("now I have neurological problems") ||
line.contains("I have really low blood pressure") ||
line.contains("I have really high blood pressure") ||
line.contains("I now have low blood pressure") ||
line.contains("I now have high blood pressure") ||
line.contains("caused my blood pressure") ||
line.contains("made my blood pressure") ||
line.contains("blood pressure went through the roof") ||
line.contains("vomit") ||
line.contains("died from taking") ||
line.contains("died after taking")
}
val negativeSentimentNoKidding = negativeSentiment.filter
{
line => ! line.contains("kidding") &&
! line.contains("I kid you") &&
! line.contains("psych") &&
! line.contains("joking") &&
! line.contains("jest") &&
! line.contains("josh") &&
! line.contains("trick") &&
! line.contains("spoof") &&
! line.contains("dupe") &&
! line.contains("hoax") &&
! line.contains("tease") &&
! line.contains("joke")
}
val aconiteFilter = negativeSentimentNoKidding.filter
{
line => line.contains("aconite")
}
val bitterOrangeFilter = negativeSentimentNoKidding.filter
{
line => line.contains("bitter orange")
}
val chaparralFilter = negativeSentimentNoKidding.filter
{
line => line.contains("chaparral")
}
val colloidalFilter = negativeSentimentNoKidding.filter
{
line => line.contains("colloidal")
}
val coltsfootFilter = negativeSentimentNoKidding.filter
{
line => line.contains("coltsfoot")
}
val comfreyFilter = negativeSentimentNoKidding.filter
{
line => line.contains("comfrey")
}
val countryMallowFilter = negativeSentimentNoKidding.filter
{
line => line.contains("country mallow")
}
val germaniumFilter = negativeSentimentNoKidding.filter
{
line => line.contains("germanium")
}
val kavaFilter = negativeSentimentNoKidding.filter
{
line => line.contains("kava")
}
val lobeliaFilter = negativeSentimentNoKidding.filter
{
line => line.contains("lobelia")
}
val yohimbeFilter = negativeSentimentNoKidding.filter
{
line => line.contains("yohimbe")
}
aconiteFilter.foreachRDD
{ rdd => rdd.foreachPartition
{ partition =>
val client = Client()
partition.foreach { item => client.incr("aconite") }
}
}
bitterOrangeFilter.foreachRDD
{ rdd => rdd.foreachPartition
{ partition =>
val client = Client()
partition.foreach { item => client.incr("bitter orange") }
}
}
chaparralFilter.foreachRDD
{ rdd => rdd.foreachPartition
{ partition =>
val client = Client()
partition.foreach { item => client.incr("chaparral") }
}
}
colloidalFilter.foreachRDD
{ rdd => rdd.foreachPartition
{ partition =>
val client = Client()
partition.foreach { item => client.incr("colloidal") }
}
}
coltsfootFilter.foreachRDD
{ rdd => rdd.foreachPartition
{ partition =>
val client = Client()
partition.foreach { item => client.incr("coltsfoot") }
}
}
comfreyFilter.foreachRDD
{ rdd => rdd.foreachPartition
{ partition =>
val client = Client()
partition.foreach { item => client.incr("comfrey") }
}
}
countryMallowFilter.foreachRDD
{ rdd => rdd.foreachPartition
{ partition =>
val client = Client()
partition.foreach { item => client.incr("country mallow") }
}
}
germaniumFilter.foreachRDD
{ rdd => rdd.foreachPartition
{ partition =>
val client = Client()
partition.foreach { item => client.incr("germanium") }
}
}
kavaFilter.foreachRDD
{ rdd => rdd.foreachPartition
{ partition =>
val client = Client()
partition.foreach { item => client.incr("kava") }
}
}
lobeliaFilter.foreachRDD
{ rdd => rdd.foreachPartition
{ partition =>
val client = Client()
partition.foreach { item => client.incr("lobelia") }
}
}
yohimbeFilter.foreachRDD
{ rdd => rdd.foreachPartition
{ partition =>
val client = Client()
partition.foreach { item => client.incr("yohimbe") }
}
}
ssc.start()
ssc.awaitTermination()
}
}