forked from Manis99803/Emotion_Analysis
-
Notifications
You must be signed in to change notification settings - Fork 1
/
files.py
102 lines (89 loc) · 3.21 KB
/
files.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
with open('twe.txt') as f: #File which contains all the tweets
content = f.readlines() # Returns all the lines from file and is appended to content
content = [x.strip('\n') for x in content] #Removes all the \n character
#import hello
c=0
tweets=[] #List which has all the tweets including empty list
final_tweets=[]
Date=[] #List which contains all the dates of tweets
for i in range(len(content)):
k=[]
if '$' in content[i]:
k.append(content[i][3:len(content[i])])
Date.append(content[i][3:len(content[i])]) #returns the date of tweets
for j in range((i+1),len(content)):
if '$' not in content[j] and len(content[j])>0:
k.append(content[j])
if '$' in content[j] :
break
tweets.append(k)
for i in range(len(tweets)):
if not tweets[i]:
pass
else:
final_tweets.append(tweets[i])
''' #Final list which has all the tweets date wise excluding the empty list
for i in range(len(final_tweets)):
print(final_tweets[i])
'''
'''
for i in range(len(final_tweets)):
for j in range(1,len(final_tweets[i])):
print(final_tweets[i])
'''
import presentation #Program for classification of tweets
classified_list=[] #List which will contain the results(both the class and confidence) after classification
for i in range(len(final_tweets)):
classified_list.append([])
for j in range(1,len(final_tweets[i])):
classified_list[i].append(presentation.classify(final_tweets[i][j]))
#for i in range(len(classified_list)):
# print(classified_list[i])
'''
c=0
z=[]
j=1
o=[]
y=[]
Frequency=[]
for i in range(len(classified_list)):
y.append([])
for j in range(len(classified_list[i])):
o.append([])
if (type(classified_list[i][j])!=type(None)):
o[i].append(classified_list[i][j][0]) #List which has only the classification result(only class)
for i in range(len(o)):
Frequency.append([]) #List which will contain the classification result(only class) with date
d=dict() #Dictionary which will have no. of tweets that belong to some class everday
if(o[i]!=[]):
for j in range(len(o[i])):
c=0
for k in range(len(o[i])):
if(o[i][j]==o[i][k]):
c+=1
d.update({o[i][j]:c})
Frequency[i].append(d)
#print(Frequency)
w=0
some=[]
for i in range(len(Frequency)):
if(Frequency[i][0]!={}):
Frequency[i].append(Date[w])
w+=1
#print(Frequency[i])
#print('___________________________________')
#for i in range(len(Frequency)):
# print(Frequency[i])
w+=1
Max_tweet=[]
for i in range(len(Date)):
if(Date[i]!=[]):
Max_tweet.append([])
Max_tweet[i].append(Date[i])
for i in range(len(Frequency)):
if(Frequency[i][0]!={}):
Max_tweet[i].append((max(Frequency[i][0].keys(), key=(lambda k: Frequency[i][0][k]))))
for i in range(len(Max_tweet)):
if(len(Max_tweet[i])>1):
print(Max_tweet[i]) #List which has the class to which maximum of the tweets belonged on some date
'''