forked from petros-ioannidis/twitter_crawler
-
Notifications
You must be signed in to change notification settings - Fork 0
/
converter.py
executable file
·63 lines (44 loc) · 1.95 KB
/
converter.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
#===============================================================================
# def LenError():
# len(tweet)<=17
#===============================================================================
def convert(his_list):
f=open('myfinal.arff','w')
f.write("@RELATION tweety\n\n\
@ATTRIBUTE tweet_id NUMERIC\n\
@ATTRIBUTE user_id NUMERIC\n\
@ATTRIBUTE followers NUMERIC\n\
@ATTRIBUTE following NUMERIC\n\
@ATTRIBUTE timestamp DATE \"yyyy-MM-dd HH:mm:ss\"\n\
@ATTRIBUTE references NUMERIC\n\
@ATTRIBUTE hyperlinks NUMERIC\n\
@ATTRIBUTE positive_words NUMERIC\n\
@ATTRIBUTE negative_words NUMERIC\n\
@ATTRIBUTE number_of_negations NUMERIC\n\
@ATTRIBUTE number_of_exclamations NUMERIC\n\
@ATTRIBUTE number_of_quotes NUMERIC\n\
@ATTRIBUTE retweeting NUMERIC\n\
@ATTRIBUTE number_of_upper_case NUMERIC\n\
@ATTRIBUTE number_of_lower_case NUMERIC\n\
@ATTRIBUTE number_of_positive_emoticons NUMERIC\n\
@ATTRIBUTE number_of_negative_emoticons NUMERIC\n\
@ATTRIBUTE class {Negative,Neutral,Positive}\n\n")
sentiment = { -1:"Negative", 0:"Neutral", 1:"Positive" }
f.write("@DATA\n")
for tweet in his_list:
for attr in tweet[:-1]:
f.write(str(attr)+',')
try:
if(tweet[-1] in sentiment.keys()):
f.write(sentiment[tweet[-1]]+'\n')
else:
raise ValueError
except ValueError:
print 'Value not in sentiment dictionary'
exit(-1)
#=======================================================================
# try:
# LenError()
# print 'Attribute missing'
# exit(-1)
#=======================================================================