简介
学习需要记录一下自己调通的代码,所以简要记录一下。
数据介绍
输入文本为一段话分别为一个文件,eg:neg.0.txt,neg.29.txt。
输出结果示例:酒店,门面,很小,不像,三星级,酒店,入住率,好像,反正,房间,大小,标准,光线,网络,奇差,无比,连不上,服务,
代码
# -*- coding:utf-8 -*-
import codecs
import os
import shutil
import jieba
import jieba.analyse
#Read file and cut
def read_file_cut(file_path, num_recs):
#create path
respath = "C:\\Users\\Administrator\\PycharmProjects\\M_H_Attention\\neg0_99\\result_test"
if os.path.isdir(respath):
shutil.rmtree(respath, True)
os.makedirs(respath)
# jieba.load_userdict('THUOCL_food.txt')#导入用户自定义词典
num = 0
while num< num_recs:
name = "%d" % num
print(name)
fileName = file_path + str(name) + ".txt"
resName = respath + str(name) + ".txt"
source = codecs.open(fileName, 'r'