有没有办法过滤掉python中的冠词(the,a,an)、代词、连词(和,但是)和其他非热门词汇?或者,有没有python包可以提供帮助?
我知道我可以使用过滤器和其他东西,但我需要一个包含所有单词的长长列表。已经有包含这些单词的包了吗?我需要删除这些单词,这样消耗的内存才能处理删除了这些单词的列表,这样就会更轻。
谢谢
发布于 2015-03-06 20:42:02
您要查找的术语称为停用词删除。
完成此任务的一个强大的库是NLTK
它可以处理更复杂的输入文本标记化,轻松地允许删除停用词和更多:
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', '.']https://stackoverflow.com/questions/28898539
复制相似问题