有什么方法可以过滤掉python中的单词吗?
有没有办法过滤掉python中的冠词(the、a、an)、代词、conventions(and、but)和其他非主题词?或者是否有一个python包可以提供帮助 我知道我可以使用过滤器之类的东西,但我需要一个长长的单词列表。有没有已经包含这些单词的软件包?我需要去掉这些单词,这样消耗的内存将能够处理删除这些单词后的列表,从而使其更轻有什么方法可以过滤掉python中的单词吗?,python,stop-words,Python,Stop Words,有没有办法过滤掉python中的冠词(the、a、an)、代词、conventions(and、but)和其他非主题词?或者是否有一个python包可以提供帮助 我知道我可以使用过滤器之类的东西,但我需要一个长长的单词列表。有没有已经包含这些单词的软件包?我需要去掉这些单词,这样消耗的内存将能够处理删除这些单词后的列表,从而使其更轻 谢谢您正在寻找的术语叫做停止单词删除 实现这一点的强大库是 它可以处理更复杂的输入文本标记化,轻松删除停止词等: import nltk from nltk.cor
谢谢您正在寻找的术语叫做停止单词删除 实现这一点的强大库是 它可以处理更复杂的输入文本标记化,轻松删除停止词等:
import nltk
from nltk.corpus import stopwords
sentence = """At eight o'clock on Thursday morning ... Arthur didn't feel very good."""
tokens = nltk.word_tokenize(sentence)
filtered_tokens = [w for w in tokens if not w.lower() in stopwords.words('english')]
print tokens
print filtered_tokens
这将打印:
['At', 'eight', "o'clock", 'on', 'Thursday', 'morning', '...', 'Arthur', 'did', "n't", 'feel', 'very', 'good', '.']
['eight', "o'clock", 'Thursday', 'morning', '...', 'Arthur', "n't", 'feel', 'good', '.']