-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcut.py
More file actions
37 lines (34 loc) · 984 Bytes
/
cut.py
File metadata and controls
37 lines (34 loc) · 984 Bytes
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
import sys
import os
import re
import jieba
import codecs
import json
from sklearn.datasets.base import Bunch
from sklearn.feature_extraction.text import TfidfVectorizer
from sklearn.naive_bayes import MultinomialNB
import pickle as pickle
def change(input_file, output_file):
fin = open(input_file, "r")
fout = open(output_file, "w")
tmp = fin.readlines()
for i in range(len(tmp)):
if i % 100 == 0 :
print("dealing %d..."%i)
text_prepared = []
tem = json.loads(tmp[i])
ce = re.compile(u'[^\u4E00-\u9FA5]+')
text_content = tem["content"]
text_content = re.sub(ce, "", text_content, 0)
cut = jieba.cut(text_content)
fout.write(" ".join(cut) + "\n")
fout.close()
print("Cutting train:")
input_file = "train.json"
output_file = "train_cut"
change(input_file, output_file)
'''print("Cutting test:")
input_file = "test10.json"
output_file = "test_cut10"
change(input_file, output_file)
'''