在我的脚本中,我计算每个文本文件的某些特征。然后我将结果写入 CSV 文件。但是,我似乎无法将它们放入列表中,我最终得到了字符串。我省略了特征计算,只是发布了我用来写入 CSV 文件的代码。我是初学者:)
fnew = open('results.csv', 'w+')
fnew.write('fileid,feature,resultaat\n')
......计算特征。
fnew.write(cat+','+sentstr+',perplexity (bigram),'+str(lmbi.perplexity(sent))+'\n')
fnew.write(cat+','+sentstr+',perplexity (trigram),'+str(lmtr.perplexity(sent))+'\n')
fnew.write(cat+','+sentstr+',word_senses,'+str(aver_senses)+'\n')
fnew.write(cat+','+sentstr+',polarity,'+str(polarity(sent))+'\n')
fnew.write(cat+','+sentstr+',modality,'+str(modality(Sentence(parse(joined, chunks=False, lemmata=True))))+'\n')
fnew.write(cat+','+sentstr+',subjectivity,'+str(subjectivity(sent))+'\n')
fnew.close()