This repository has been archived by the owner on Dec 28, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 5
/
emoji.py
168 lines (156 loc) · 3.39 KB
/
emoji.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
# -*- coding: utf-8 -*-
import re
import nltk
import os
import csv
def get_pos_features(words):
tags=[]
# words=' '.join(i for i in wordsl)
pos_tags ={
'JJ':0,
'JJR':0,
'JJS':0,
'MD':0,
'NN':0,
'NNP':0,
'PR':0,
'RB':0,
'RBR':0,
'RBS':0,
'UH':0,
'V':0,
'W':0,
}
for item in words:
print (item)
print(type(item))
print (item.lower())
print (type(item.lower()))
try:
tokenized = nltk.word_tokenize(item.lower())
print ('ok')
tagged = nltk.pos_tag(tokenized)
print ('here')
print (tagged)
tags.append(tagged[0][1])
except Exception as e:
# print(str(e))
print ('except')
pass
# print (tags)
probs=[]
for i in pos_tags.keys():
pos_tags[i]=tags.count(i)
pos_tags['V']=tags.count('VB')+tags.count('VBD')+tags.count('VBG')+tags.count('VBN')+tags.count('VBP')+tags.count('VBZ')
pos_tags['W']=tags.count('WDT')+tags.count('WP')+tags.count('WP$')+tags.count('WRB')
pos_tags['PR']=tags.count('PRP')+tags.count('PRP$')
w_count=float(len(words))
if w_count!=0:
print (words)
probs=[x/w_count for x in pos_tags.values()]
print (probs)
# print (probs)
else:
probs=[0 for x in pos_tags.values()]
return probs
def get_emoji_Features(raw_tweet):
features=[]
possum=0
posnum=0
negsum=0
negnum=0
emoji={
'😀' : 3,
'😃' : 4,
'😄' : 3,
'😁' : 4,
'😆' : 5,
'😅' : 2,
'😂' : 5,
'😊' : 3,
'☺️' : 3,
'😇' : 2,
'🙂' : 1,
'🙃' : 1,
'😉' : 2,
'😌' : 1,
'😍' : 4,
'😘' : 3,
'😋' : 3,
'😜' : 2,
'😝' : 3,
'😛' : 2,
'😎' : 2,
'😒' : -2,
'😞' : -3,
'😔' : -2,
'😟' : -3,
'😕' : -1,
'🙁' : -2,
'☹️' : -3,
'😣' : -4,
'😖' : -4,
'😦' : -1,
'😧' : -2,
'😰' : -4,
'😢' : -4,
'😥' : -3,
'✌️' : 2,
'👍' : 2,
'👎' : -2,
'❤️' : 5,
'💕' : 4,
'❣️' : 4,
'💔' : -4,
'😭' : -5,
'😓' : -4,
'😪' : -3,
'😠' : -3,
'😡' : -5,
'😣' : -5,
'😖' : -4,
'😫' : -4,
'😩' : -5,
}
punct=['?','!','\"']
for emo in emoji.keys():
#features.append(raw_tweet.count(emo))
if raw_tweet.count(emo)>0:
if emoji[emo]<0:
negnum += raw_tweet.count(emo)
negsum += raw_tweet.count(emo)*emoji[emo]
else:
posnum += raw_tweet.count(emo)
possum += raw_tweet.count(emo)*emoji[emo]
features.extend((possum,negsum))
# print features
temp = re.findall(r"[\w']+", raw_tweet)
print (temp)
print (list(filter(lambda x:x.isupper(),temp)))
pos_features = get_pos_features(list(filter(lambda x:x.isupper(),temp)))
features.append(len(list(filter(lambda x:x.isupper(),temp))))
# print features
features.extend(pos_features)
# print (features)
return features
# get_feature_1_2("/home/ameesha/Documents/data mining/feature1.2/user0.csv")
# get_emoji_Features("Well i just CANT stop singing/watching/HUMMING #IkVaariAa !! ❤️🎤🎧 Its on loop..WOW What about you? 😜😁")
# get_emoji_Features("ARE YOU KIDDING ME?")
def writeFile(folder, csvfile):
f5 = csv.writer(csvfile,delimiter=",")
for f in sorted(os.listdir(folder)):
inputFile = open(os.path.join(folder,f),"r")
# print (inputFile)
reader = list(csv.reader(inputFile))
tweet = reader[1][2]
tweet =tweet.strip()
featurelist=get_emoji_Features(tweet)
f5.writerow(featurelist)
inputFile.close()
pwd = os.getcwd()
norm = pwd + "/normal_with_past"
sarc = pwd + "/sarcastic_with_past"
csvfile = open("feature1_2.csv","w")
writeFile(norm,csvfile)
writeFile(sarc,csvfile)
csvfile.close()