-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathsocialV2.py
55 lines (42 loc) · 1.03 KB
/
socialV2.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
import glob
import time
import ujson
import nltk
import os
from pathlib import Path
from nltk.corpus import stopwords
from collections import defaultdict
ITERATIONS = 2000
print("Starting Social Program")
sr = stopwords.words('english')
start_time = time.time()
subcnt = defaultdict(int)
tokens = []
print(os.getcwd())
file_to_open = 'data_new/RC_2016-11-08'
print( os.path.isfile(file_to_open))
i = 0
for fn in glob.iglob(file_to_open):
with open(fn) as f:
for line in f:
# print(line)
jo = ujson.loads(line)
body = jo['body']
tokens += [t for t in body.split()]
i += 1
if(i> ITERATIONS):
break
# print(jo['body'])
# subcnt[jo['subreddit']] += 1
clean_tokens = tokens[:]
for token in tokens:
if token in stopwords.words('english'):
clean_tokens.remove(token)
freq = nltk.FreqDist(clean_tokens)
# for key,val in freq.items():
# print(str(key) + ':' + str(val))
freq.plot(30,cumulative = False)
#for k, v in subcnt.items():
# print(v, k)
#print(tokens)
print("--- %s seconds ---" % (time.time() - start_time))