【发布时间】:2018-04-20 06:39:52
【问题描述】:
这里我使用了一个包含停用词列表的文件。我想从文本中删除所有停用词。
def print_stopWords(self):
#infile = open("D:\Komal\MyPrograms\Pkg\PkgSubfolder\StopWords.txt", 'r')
stopwords = ()
print '\nstopwords are-'
for line in open('D:\Komal\MyPrograms\Pkg\PkgSubfolder\StopWords.txt'):
stopwords += (line,)
print stopwords
return stopwords
def strip_stopwords(self,text,stopword):
print '\n Text after removing all stopwords is --'
words = text.split()
text = []
for word in words:
if word.lower() not in stopword:
text.append(word)
print u' '.join(text) #'u' prefix allows you to write a unicode string literal
return text
【问题讨论】:
-
你的问题不清楚。
-
您的问题不清楚。有什么问题?无论如何,对于性能
stopwords应该是一个集合,而不是一个列表/元组。
标签: python stop-words