-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCounting.py
31 lines (24 loc) · 859 Bytes
/
Counting.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
from Preprocess3 import read_preprocess_files
import os
import pickle
def simple_learner(tweets,lens):
pos_dict={}
if 'pos_dict.pickle' not in os.listdir('.'):
for index in range(max(lens)):
pos_dict[index]={}
for tweet in tweets:
for i,word in enumerate(tweet):
try:
pos_dict[i][tweet[i]]+=1
except KeyError:
pos_dict[i][tweet[i]]=1
except IndexError:
break
with open('pos_dict.pickle', 'wb') as handle:
pickle.dump(pos_dict, handle)
else:
with open('pos_dict.pickle', 'rb') as handle:
pos_dict = pickle.load(handle)
return pos_dict
tw, l = read_preprocess_files()
result= simple_learner(tw,l)