Create your Gitee Account
Explore and code with more than 12 million developers,Free private repositories !:)
Sign up
文件
This repository doesn't specify license. Please pay attention to the specific project description and its upstream code dependency when using it.
Clone or Download
word_segment.py 786 Bytes
Copy Edit Raw Blame History
lichuang authored 2016-10-16 17:36 . add gensim word2vec
# coding:utf-8
import sys
reload(sys)
sys.setdefaultencoding( "utf-8" )
import jieba
from jieba import analyse
def segment(input, output):
input_file = open(input, "r")
output_file = open(output, "w")
while True:
line = input_file.readline()
if line:
line = line.strip()
seg_list = jieba.cut(line)
segments = ""
for str in seg_list:
segments = segments + " " + str
segments = segments + "\n"
output_file.write(segments)
else:
break
input_file.close()
output_file.close()
if __name__ == '__main__':
if 3 != len(sys.argv):
print "Usage: ", sys.argv[0], "input output"
sys.exit(-1)
segment(sys.argv[1], sys.argv[2]);
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化