资源简介

无监督情感分析,包括文档和源代码,其中有128_hidden_then_softmax.py,Seq_CNN.py

资源截图

代码片段和文件信息

#!/usr/bin/env python
# -*- coding: utf-8  -*-
#将原始数据合并到一个txt文件

import logging
import osos.path
import codecssys

#读取文件内容
def getContent(fullname):
    f = codecs.open(fullname ‘r‘)
    content = f.readline()
    f.close()
    return content
    

if __name__ == ‘__main__‘:
    program = os.path.basename(sys.argv[0])#得到文件名
    logger = logging.getLogger(program)
    logging.basicConfig(format=‘%(asctime)s: %(levelname)s: %(message)s‘)
    logging.root.setLevel(level=logging.INFO)
    
    #输入文件目录
    inp = ‘data\ChnSentiCorp_htl_ba_2000‘ 
    folders = [‘neg‘‘pos‘]

    for foldername in folders:
        logger.info(“running “+ foldername +“ files.“)
        
        outp = ‘2000_‘ + foldername +‘.txt‘ #输出文件
        output = codecs.open(outp ‘w‘)
        i = 0
        
        rootdir = inp + ‘\\‘ + foldername
        #三个参数:分别返回1.父目录 2.所有文件夹名字(不含路径) 3.所有文件名字
        for parentdirnamesfilenames in os.walk(rootdir):
            for filename in filenames:
                content = getContent(rootdir + ‘\\‘ + filename)
                output.writelines(content)
                i = i+1
                
        output.close()
        logger.info(“Saved “+str(i)+“ files.“)
                
                
    
    
    

 属性            大小     日期    时间   名称
----------- ---------  ---------- -----  ----
     目录           0  2017-11-29 01:12  senti_analysis-master\
     文件        1418  2017-11-29 01:12  senti_analysis-master\1_process.py
     文件        1922  2017-11-29 01:12  senti_analysis-master\2_cutsentence.py
     文件        1427  2017-11-29 01:12  senti_analysis-master\3_stopword.py
     文件        2363  2017-11-29 01:12  senti_analysis-master\4_getwordvecs.py
     文件        1343  2017-11-29 01:12  senti_analysis-master\5_pca_svm.py
     文件       10403  2017-11-29 01:12  senti_analysis-master\README.md
     目录           0  2017-11-29 01:12  senti_analysis-master\data\
     目录           0  2017-11-29 01:12  senti_analysis-master\data\ChnSentiCorp_htl_ba_2000\
     目录           0  2017-11-29 01:12  senti_analysis-master\data\ChnSentiCorp_htl_ba_2000\neg\
     文件          80  2017-11-29 01:12  senti_analysis-master\data\ChnSentiCorp_htl_ba_2000\neg\neg.0.txt
     文件         204  2017-11-29 01:12  senti_analysis-master\data\ChnSentiCorp_htl_ba_2000\neg\neg.1.txt
     文件         239  2017-11-29 01:12  senti_analysis-master\data\ChnSentiCorp_htl_ba_2000\neg\neg.10.txt
     文件         382  2017-11-29 01:12  senti_analysis-master\data\ChnSentiCorp_htl_ba_2000\neg\neg.100.txt
     文件         382  2017-11-29 01:12  senti_analysis-master\data\ChnSentiCorp_htl_ba_2000\neg\neg.101.txt
     文件         117  2017-11-29 01:12  senti_analysis-master\data\ChnSentiCorp_htl_ba_2000\neg\neg.102.txt
     文件         677  2017-11-29 01:12  senti_analysis-master\data\ChnSentiCorp_htl_ba_2000\neg\neg.103.txt
     文件         152  2017-11-29 01:12  senti_analysis-master\data\ChnSentiCorp_htl_ba_2000\neg\neg.104.txt
     文件         246  2017-11-29 01:12  senti_analysis-master\data\ChnSentiCorp_htl_ba_2000\neg\neg.105.txt
     文件         100  2017-11-29 01:12  senti_analysis-master\data\ChnSentiCorp_htl_ba_2000\neg\neg.106.txt
     文件         580  2017-11-29 01:12  senti_analysis-master\data\ChnSentiCorp_htl_ba_2000\neg\neg.107.txt
     文件         106  2017-11-29 01:12  senti_analysis-master\data\ChnSentiCorp_htl_ba_2000\neg\neg.108.txt
     文件         155  2017-11-29 01:12  senti_analysis-master\data\ChnSentiCorp_htl_ba_2000\neg\neg.109.txt
     文件         995  2017-11-29 01:12  senti_analysis-master\data\ChnSentiCorp_htl_ba_2000\neg\neg.11.txt
     文件         129  2017-11-29 01:12  senti_analysis-master\data\ChnSentiCorp_htl_ba_2000\neg\neg.110.txt
     文件         229  2017-11-29 01:12  senti_analysis-master\data\ChnSentiCorp_htl_ba_2000\neg\neg.111.txt
     文件          85  2017-11-29 01:12  senti_analysis-master\data\ChnSentiCorp_htl_ba_2000\neg\neg.112.txt
     文件         239  2017-11-29 01:12  senti_analysis-master\data\ChnSentiCorp_htl_ba_2000\neg\neg.113.txt
     文件          53  2017-11-29 01:12  senti_analysis-master\data\ChnSentiCorp_htl_ba_2000\neg\neg.114.txt
     文件         264  2017-11-29 01:12  senti_analysis-master\data\ChnSentiCorp_htl_ba_2000\neg\neg.115.txt
     文件         239  2017-11-29 01:12  senti_analysis-master\data\ChnSentiCorp_htl_ba_2000\neg\neg.116.txt
............此处省略1981个文件信息

评论

共有 条评论