-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathsampleTrump.py
48 lines (38 loc) · 1.63 KB
/
sampleTrump.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
__author__ = 'Isabelle Augenstein'
#from tokenize_tweets import FILE, FILETRUMP
import json
#from twokenize_wrapper import tokenize
import io
def readToks():
FILE = '/Users/Isabelle/Documents/TextualEntailment/SemEvalStance/stanceDetection.json'
FILETRUMP = '/Users/Isabelle/Documents/TextualEntailment/SemEvalStance/USFD-StanceDetection/data/semeval/downloaded_Donald_Trump.txt'
tweets = []
print "Reading official trump data"
for line in io.open(FILETRUMP, encoding='utf-8', mode='r'):
if line.startswith('ID\t'):
continue
tweet = line.split("\t")[1].replace("\n", "").lower()
if "#makeamericagreatagain" in tweet or '#votetrump2016' in tweet:
tweets.append(tweet)
if '#trumpistoxic' in tweet or '#trumpno' in tweet or '#bantrump' in tweet:
print tweet
#for token in tokenize(tweet):
# if token == "#makeamericagreatagain":
# print line
# elif token == '#trumpisdisqualifiedparty':
# print line
print "\nReading general tweets"
for line in open(FILE, 'r'):
tweet = json.loads(line)['text'].lower().replace("\n", "")
if "#makeamericagreatagain" in tweet or '#votetrump2016' in tweet:
tweets.append(tweet)
if '#trumpistoxic' in tweet or '#trumpno' in tweet or '#bantrump' in tweet:
print tweet
print tweets.__len__()
#f = open("trump_autolabelled.txt", "wb")
#for i, tw in enumerate(tweets):
# f.write(str(i))
# f.write(("\tDonald Trump\t" + tw + "\tFAVOR\n").encode('utf8'))
#f.close()
if __name__ == '__main__':
readToks()