我尝试了两种方法来删除停止语,但都遇到了问题:
方法1:
cachedStopWords = stopwords.words("english")
words_to_remove = """with some your just have from it's /via & that they your there this into providing would can't"""
remove = tu.removal_set(words_to_remove, query)
remove2 = tu.removal_set(cachedStopWords, query)
在这种情况下,只有第一个remove函数起作用。remove2不工作。
方法2:
lines = tu.lines_cleanup([sentence for sentence in sentence_list], remove=remove)
words = '\n'.join(lines).split()
print words # list of words
输出如下["Hello", "Good", "day"]
我试着把停止语从单词中去掉。这是我的代码:
for word in words:
if word in cachedStopwords:
continue
else:
new_words='\n'.join(word)
print new_words
输出如下:
H
e
l
l
o
不知道以上两种方法有什么问题。请指教。
使用此选项可增加停止字列表:
输出:
179
184
我认为您想要实现的是扩展NLTK的stopwords列表。由于NLTK中的stopwords保存在一个列表中,您只需执行以下操作:
您可以更改方法2:
致:
相关问题 更多 >
编程相关推荐