forked from zake7749/word2vec-tutorial
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsegment.py
executable file
·36 lines (27 loc) · 974 Bytes
/
segment.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
# -*- coding: utf-8 -*-
import jieba
import logging
def main():
logging.basicConfig(format='%(asctime)s : %(levelname)s : %(message)s', level=logging.INFO)
# jieba custom setting.
jieba.set_dictionary('jieba_dict/dict.txt.big')
# load stopwords set
stopwordset = set()
with open('jieba_dict/stopwords.txt','r',encoding='utf-8') as sw:
for line in sw:
stopwordset.add(line.strip('\n'))
texts_num = 0
output = open('wiki_seg.txt','w')
with open('wiki_zh_tw.txt','r') as content :
for line in content:
line = line.strip('\n')
words = jieba.cut(line, cut_all=False)
for word in words:
if word not in stopwordset:
output.write(word +' ')
texts_num += 1
if texts_num % 10000 == 0:
logging.info("已完成前 %d 行的斷詞" % texts_num)
output.close()
if __name__ == '__main__':
main()