我想使用python 2实现一个分类应用程序,在进行分类之前,应该对文本进行预处理。分类器和预处理器在不同的包中。然后在分类包中在类中创建了一个preprocessing class
对象。
这是我的项目探险家
preprocessing class
类预处理: def预处理(self,file):inputFile = "text“outputFile = "plainText.txt”# infile = io.open(inputFile,"r",编码=‘utf-8’).read() outfile = io.open(outputFile,"w",编码=‘utf-8’) text = unnecessaryCharsObj.removeChars(file) text = stopWrdsObj.removeStopwords( text ) text= text.lower()平原= text.split() stemmObj.stemminig(平原) for x in纯文本: outfile.write(x) outfile.write(u'\u0020') #明文= ".join(str(x) for x in平原)#outfile.write(明文)返回输出文件outfile.close()
预处理在分类包中创建的类对象,
def分类(自):dao = DAO();procc =预处理();#获取uncatNewsList uncatNewsList =dao.selectUncategerizedNews()的未变化新闻ID;关于uncatNewsList中的新闻: description =dao.getDescriptionById(新闻) wf = io.open('news.txt','w',编码=‘utf-8’)x= description wf.write(x) rf = io.open('news.txt','r',编码=‘utf-8’).read() txt = procc.preprocess(rf)分类= MultinomialNBClassifier().classifier(txt) dao.updateNews(新闻,类别)
但是在预处理类中,它使用同一个预处理包中的文本文件。所以我不能按我的意愿去做,因为它返回了错误"No such file or directory: 'stopWordList.txt'"
我能做些什么来解决这个问题?
发布于 2016-09-02 19:52:58
请检查该文件是否与当前执行的文件的路径相同。以下是idea:How do I get the path of the current executed file in Python?
https://stackoverflow.com/questions/39299593
复制相似问题