-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathcreatingTrainingDataSet.py
executable file
·312 lines (293 loc) · 8.4 KB
/
creatingTrainingDataSet.py
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
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
import pymongo
import csv
from pymongo import Connection
import nltk
import string
import os
from nltk.tokenize import RegexpTokenizer
from nltk.tokenize import RegexpTokenizer
from nltk.corpus import PlaintextCorpusReader
from nltk.corpus import brown
from nltk.corpus import stopwords
import sys
import re
from itertools import groupby
#from stemming.porter2 import stem
from nltk.stem.wordnet import WordNetLemmatizer
lmtzr = WordNetLemmatizer()
noOfConversation=0
noOfFamily=0
noOfTime=0
noOfWork=0
noOfGames=0
noOfInternet=0
noOfLocation=0
noOfFun=0
noOfFood=0
noOfClothes=0
noOfHealth=0
noOfBooks_Movies=0
noOfReligion=0
noOfRomance=0
noOfSwearing=0
noOfPolitics=0
noOfMusic=0
noOfSchool=0
noOfFeeling=0
noOfBusiness=0
noOfAdjective=0
noOfFollow=0
noOfPositive=0
noOfnegative=0
noOfArticle=0
noOfPersonal_pronoun=0
noOfConjunction=0
noOfPreposition=0
noOfAux_Verbs=0
Conversation=[]
Family=[]
Time=[]
Work=[]
Games=[]
Internet=[]
Location=[]
Fun=[]
Food=[]
Clothes=[]
Health=[]
Books_Movies=[]
Religion=[]
Romance=[]
Swearing=[]
Politics=[]
Music=[]
School=[]
Feeling=[]
Business=[]
Adjective=[]
Follow=[]
Positive=[]
negative=[]
Article=[]
Personal_pronoun=[]
Conjunction=[]
Preposition=[]
Aux_Verbs=[]
spamreader=csv.reader(open('Topics.csv', 'rU'), delimiter=',', dialect=csv.excel_tab)
for row in spamreader:
if(row[0]!=''):
Conversation.append(row[0])
#print Conversation
if(row[1]!=''):
Family.append(lmtzr.lemmatize(row[1].lower()))
if(row[2]!=''):
Time.append(lmtzr.lemmatize(row[2].lower()))
if(row[3]!=''):
Work.append(lmtzr.lemmatize(row[3].lower()))
if(row[4]!=''):
Games.append(lmtzr.lemmatize(row[4].lower()))
if(row[5]!=''):
Internet.append(lmtzr.lemmatize(row[5].lower()))
if(row[6]!=''):
Location.append(lmtzr.lemmatize(row[6].lower()))
if(row[7]!=''):
Fun.append(lmtzr.lemmatize(row[7].lower()))
if(row[8]!=''):
Food.append(lmtzr.lemmatize(row[8].lower()))
if(row[9]!=''):
Clothes.append(lmtzr.lemmatize(row[9].lower()))
if(row[10]!=''):
Health.append(lmtzr.lemmatize(row[10].lower()))
if(row[11]!=''):
Books_Movies.append(lmtzr.lemmatize(row[11].lower()))
if(row[12]!=''):
Religion.append(lmtzr.lemmatize(row[12].lower()))
if(row[13]!=''):
Romance.append(lmtzr.lemmatize(row[13].lower()))
if(row[14]!=''):
Swearing.append(lmtzr.lemmatize(row[14].lower()))
if(row[15]!=''):
Politics.append(lmtzr.lemmatize(row[15].lower()))
if(row[16]!=''):
Music.append(lmtzr.lemmatize(row[16].lower()))
if(row[17]!=''):
School.append(lmtzr.lemmatize(row[17].lower()))
if(row[18]!=''):
Feeling.append(lmtzr.lemmatize(row[18].lower()))
if(row[19]!=''):
Business.append(lmtzr.lemmatize(row[19].lower()))
if(row[20]!=''):
Adjective.append(lmtzr.lemmatize(row[20].lower()))
if(row[21]!=''):
Follow.append(lmtzr.lemmatize(row[21].lower()))
if(row[22]!=''):
Positive.append(lmtzr.lemmatize(row[22].lower()))
if(row[23]!=''):
negative.append(lmtzr.lemmatize(row[23].lower()))
if(row[24]!=''):
Article.append(lmtzr.lemmatize(row[24].lower()))
if(row[25]!=''):
Personal_pronoun.append(lmtzr.lemmatize(row[25].lower()))
if(row[26]!=''):
Aux_Verbs.append(lmtzr.lemmatize(row[26].lower()))
if(row[27]!=''):
Conjunction.append(lmtzr.lemmatize(row[27].lower()))
if(row[28]!=''):
Preposition.append(lmtzr.lemmatize(row[28].lower()))
#print Preposition
allWordsofTweetAndDescription=[]
allUniqueWords=[]
UniqueWordCount=0
word_tokenizer = RegexpTokenizer(r'\w+')
noOfHitWords=0
age=''
with open('trainingDataForAge.csv', 'wb') as csvfile:
spamwriter = csv.writer(csvfile, delimiter=',')
spamwriter.writerow(["Conversation","Family","Time","Work","Games","Internet","Location","Fun","Food","Clothes","Health","Books_Movies","Religion","Romance","Swearing","Politics","Music","School","Feeling","Business","Adjective","Follow","Positive","negative","Article","Personal_pronoun","Auxiliary_Verb","Conjunction","Preposition","Age_Class"])
spamreader=csv.reader(open('tweetOut2.csv', 'rU'), delimiter=',', dialect=csv.excel_tab)
for row in spamreader:
for row in spamreader:
allWordsofTweetAndDescription=[]
allUniqueWords=[]
noOfHitWords=0
UniqueWordCount=0
noOfConversation=0
noOfFamily=0
noOfTime=0
noOfWork=0
noOfGames=0
noOfInternet=0
noOfLocation=0
noOfFun=0
noOfFood=0
noOfClothes=0
noOfHealth=0
noOfBooks_Movies=0
noOfReligion=0
noOfRomance=0
noOfSwearing=0
noOfPolitics=0
noOfMusic=0
noOfSchool=0
noOfFeeling=0
noOfBusiness=0
noOfAdjective=0
noOfFollow=0
noOfPositive=0
noOfnegative=0
noOfArticle=0
noOfPersonal_pronoun=0
noOfConjunction=0
noOfPreposition=0
noOfAux_Verbs=0
tokenized_words1 = word_tokenizer.tokenize(row[3])
for word in tokenized_words1:
allWordsofTweetAndDescription.append(word.lower())
tokenized_words1 = word_tokenizer.tokenize(row[4])
for word in tokenized_words1:
allWordsofTweetAndDescription.append(word.lower())
for word in allWordsofTweetAndDescription:
#print word
stemword=lmtzr.lemmatize(word)
if stemword not in allUniqueWords:
allUniqueWords.append(stemword)
UniqueWordCount+=1
#print UniqueWordCount
if stemword in Conversation:
noOfConversation+=1
noOfHitWords+=1
if stemword in Family:
noOfFamily+=1
noOfHitWords+=1
if stemword in Time:
noOfTime+=1
noOfHitWords+=1
if stemword in Work:
noOfWork+=1
noOfHitWords+=1
if stemword in Games:
noOfGames+=1
noOfHitWords+=1
if stemword in Internet:
noOfInternet+=1
noOfHitWords+=1
if stemword in Location:
noOfLocation+=1
noOfHitWords+=1
if stemword in Fun:
noOfFun+=1
noOfHitWords+=1
if stemword in Food:
noOfFood+=1
noOfHitWords+=1
if stemword in Clothes:
noOfClothes+=1
noOfHitWords+=1
if stemword in Health:
noOfHealth+=1
noOfHitWords+=1
if stemword in Books_Movies:
noOfBooks_Movies+=1
noOfHitWords+=1
if stemword in Religion:
noOfReligion+=1
noOfHitWords+=1
if stemword in Romance:
noOfRomance+=1
noOfHitWords+=1
if stemword in Swearing:
noOfSwearing+=1
noOfHitWords+=1
if stemword in Politics:
noOfPolitics+=1
noOfHitWords+=1
if stemword in Music:
noOfMusic+=1
noOfHitWords+=1
if stemword in School:
noOfSchool+=1
noOfHitWords+=1
if stemword in Feeling:
noOfSchool+=1
noOfHitWords+=1
if stemword in Business:
noOfBusiness+=1
noOfHitWords+=1
if stemword in Adjective:
noOfAdjective+=1
noOfHitWords+=1
if stemword in Follow:
noOfFollow+=1
noOfHitWords+=1
if stemword in Positive:
noOfPositive+=1
noOfHitWords+=1
if stemword in negative:
noOfnegative+=1
noOfHitWords+=1
if stemword in Article:
noOfArticle+=1
noOfHitWords+=1
if stemword in Personal_pronoun:
noOfPersonal_pronoun+=1
noOfHitWords+=1
if stemword in Aux_Verbs:
noOfAux_Verbs+=1
noOfHitWords+=1
if stemword in Conjunction:
noOfConjunction+=1
noOfHitWords+=1
if stemword in Preposition:
noOfPreposition+=1
noOfHitWords+=1
if int(row[2]) == 10:
age='a'
if int(row[2]) == 20:
age='b'
if int(row[2]) == 30:
age='c'
#print row[1]
#print str(age)
print noOfHitWords
#if(noOfHitWords>=100):
spamwriter.writerow([float(noOfConversation)/float(noOfHitWords),float(noOfFamily)/float(noOfHitWords),float(noOfTime)/float(noOfHitWords),float(noOfWork)/float(noOfHitWords),float(noOfGames)/float(noOfHitWords),float(noOfInternet)/float(noOfHitWords),float(noOfLocation)/float(noOfHitWords),float(noOfFun)/float(noOfHitWords),float(noOfFood)/float(noOfHitWords),float(noOfClothes)/float(noOfHitWords),float(noOfHealth)/float(noOfHitWords),float(noOfBooks_Movies)/float(noOfHitWords),float(noOfReligion)/float(noOfHitWords),float(noOfRomance)/float(noOfHitWords),float(noOfSwearing)/float(noOfHitWords),float(noOfPolitics)/float(noOfHitWords),float(noOfMusic)/float(noOfHitWords),float(noOfSchool)/float(noOfHitWords),float(noOfFeeling)/float(noOfHitWords),float(noOfBusiness)/float(noOfHitWords),float(noOfAdjective)/float(noOfHitWords),float(noOfFollow)/float(noOfHitWords),float(noOfPositive)/float(noOfHitWords),float(noOfnegative)/float(noOfHitWords),float(noOfArticle)/float(noOfHitWords),float(noOfPersonal_pronoun)/float(noOfHitWords),float(noOfAux_Verbs)/float(noOfHitWords),float(noOfConjunction)/float(noOfHitWords),float(noOfPreposition)/float(noOfHitWords),age])