-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathclassify.py
More file actions
264 lines (202 loc) · 8.46 KB
/
classify.py
File metadata and controls
264 lines (202 loc) · 8.46 KB
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
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
import re
import nltk
import pickle
import clog_test
from nltk.corpus import stopwords
stop = set(stopwords.words('english'))
from langdetect import detect
import enchant
english_dict = enchant.Dict("en_US")
with open("pornstars.pickle", "rb") as f:
stars = pickle.load(f)
with open("genres.pickle", "rb") as f:
genres = pickle.load(f)
with open("extra_terms.pickle", "rb") as f:
extra_terms = pickle.load(f)
with open("tvshows.pickle", "rb") as f:
tvshows = pickle.load(f)
with open("english_movies.pickle", "rb") as f:
english_movies = pickle.load(f)
with open("softwares.pickle", "rb") as f:
softwares = pickle.load(f)
with open("games.pickle", "rb") as f:
games = pickle.load(f)
with open("artists.pickle", "rb") as f:
artists = pickle.load(f)
with open("courses.pickle", "rb") as f:
courses = pickle.load(f)
nsfw = stars + genres + extra_terms
nsfw.remove("with")
nsfw.remove("rock")
indiantv_content = []
tvshow_content = []
sports_content = []
explicit_content = []
englishmovie_content = []
indianmovie_content = []
games_content = []
software_content = []
artists_content = []
english_content = []
courses_content = []
hindi_content = []
english_query = 0
trump_counter = 0
# def extract_entities(text):
# for sent in nltk.sent_tokenize(text):
# return nltk.ne_chunk(nltk.pos_tag(nltk.word_tokenize(sent)))
def is_explicit(word):
if word in nsfw and word not in stop:
return True
else:
return False
def is_tvshow(word):
if word in tvshows and word not in stop:
return True
else:
return False
def is_englishmovie(word) :
if word in english_movies and word not in stop:
return True
else:
return False
def is_software(word) :
if word in softwares and word not in stop:
return True
else:
return False
def is_game(word) :
if word in games and word not in stop:
return True
else:
return False
def is_artist(word) :
if word in artists and word not in stop:
return True
else:
return False
def is_course(word) :
if word in courses and word not in stop:
return True
else:
return False
def is_indiantv(word):
if word in ["bigg", "boss", "koffee", "kofee", "coffee", "karan", "kapil", "sharma", "bachao", "comedy", "mahabharat", "aib", "tvf"]:
return True
else:
return False
def is_sport(word):
#not much -- most of sports comes in +uploads
if word in ["match", "football", "cricket", "tennis", "champions", "t20", "odi", "match.of.the.day", "test", "poker", "wsop", "wwe", "ufc", "badminton", "basketball", "volleyball", "f1", "wrestlemania", "smackdown", "highlights"]:
return True
else:
return False
def is_indianmovie(word):
if word in ["dhoni", "ms", "shivaay", "shivay", "rock", "force", "dil", "mushkil", "rockstar", "hindi", "bollywood", "gangs", "wasseypur"]:
return True
else:
return False
filtered_queries = 0
with open('log.csv') as log:
for line in log:
# timestamp = line[:line.find("\t")]
search_query = line[line.rfind(":")+1:].lower().rstrip()
# ip_add = line[:line.rfind(":")]
# print line
sq_split = search_query.lower().split()
if len(set(["trump", "melania", "donald", "ivanka", "tiffany"]).intersection(sq_split)) > 0:
trump_counter += 1
continue
for i in sq_split:
if is_explicit(i):
explicit_content.append(search_query)
clog_test.log(line, 1)
break
else:
for i in sq_split:
if is_indiantv(i):
indiantv_content.append(search_query)
clog_test.log(line, 2)
break
else:
for i in sq_split:
if is_sport(i):
sports_content.append(search_query)
clog_test.log(line, 3)
break
else:
for i in sq_split:
if is_indianmovie(i):
indianmovie_content.append(search_query)
clog_test.log(line, 4)
break
else:
search_query_tv = re.sub(r"s(\d{1,2})e(\d{1,2})", "", search_query)
search_query_tv = re.sub(r"s(\d{1,2})", "", search_query_tv)
search_query_tv = re.sub(r"e(\d{1,2})", "", search_query_tv)
search_query_tv = search_query_tv.rstrip()
for i in search_query_tv.split(" "):
if is_tvshow(i):
tvshow_content.append(search_query)
clog_test.log(line, 5)
break
else:
for i in sq_split:
if is_englishmovie(i):
englishmovie_content.append(search_query)
clog_test.log(line, 7)
break
else:
for i in sq_split:
if is_artist(i):
artists_content.append(search_query)
clog_test.log(line, 6)
break
else:
for i in sq_split:
if is_software(i):
software_content.append(search_query)
clog_test.log(line, 10)
break
else:
for i in sq_split:
if is_course(i):
courses_content.append(search_query)
clog_test.log(line, 8)
break
else:
if len(search_query) < 4:
filtered_queries += 1
continue
for i in sq_split:
if is_game(i):
games_content.append(search_query)
clog_test.log(line, 9)
break
else:
for i in sq_split:
if english_dict.check(i):# or detect(i) == "en":
print search_query
input = int(raw_input())
clog_test.log(line, input)
english_content.append(search_query)
break
else:
clog_test.log(line, 11)
hindi_content.append(search_query)
print
print "Explicit:", len(explicit_content) #1
print "Indian TV:", len(indiantv_content) #2
print "Sports:", len(sports_content) #3
print "Indian movies:", len(indianmovie_content) #4
print "English TV:", len(tvshow_content) #5
print "Artists/Songs:", len(artists_content) #6
print "English movies:", len(englishmovie_content) #7
print "Academics:", len(courses_content) #8
print "Games:", len(games_content) #9
print "Software:", len(software_content) #10
print "Hindi/Telugu/Spelling Mistakes:", len(hindi_content) #11
print "English:", len(english_content)
print "Filtered Queries:", filtered_queries
print "Trump Counter:", trump_counter
print