-
Notifications
You must be signed in to change notification settings - Fork 0
/
get_data.py
46 lines (31 loc) · 1.12 KB
/
get_data.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
from pyvi import ViTokenizer
from tqdm import tqdm
import gensim
import os
import pickle
HOME = os.path.dirname(__file__)
train_path = os.path.join(HOME, 'dataset\\Train_Full\\')
def get_data(dir_path):
data = []
for file_name in os.listdir(dir_path):
file_path = os.path.join(dir_path, file_name)
with open(file_path, 'r', encoding="utf-16") as f:
lines = f.readlines()
for line in lines:
sentences = line.split('.')
for sentence in sentences:
if len(sentence) > 10:
sentence = gensim.utils.simple_preprocess(sentence)
sentence = ' '.join(sentence)
sentence = ViTokenizer.tokenize(sentence)
data.append(sentence)
return data
sentences = []
directories = []
for path in os.listdir(train_path):
directories.append(os.path.join(train_path, path))
for directory in tqdm(directories):
sens = get_data(directory)
sentences = sentences + sens
print(len(sentences))
pickle.dump(sentences, open('./sentences.pickle', 'wb'))