【发布时间】:2019-12-01 03:38:33
【问题描述】:
我有一个段落列表,我想从所有段落中删除停用词。
我首先拆分单词然后我用停用词检查单词如果不在停用词中附加该单词。它适用于单个段落列表但是当尝试整个段落时它会创建所有单词的列表而不是分组列表
g=[]
h=[]
for i in f[0:2]:
word_token=npl.tokenize.word_tokenize(i)
for j in word_token:
if(j not in z):
g.append(j)
h.append(g)
例子
Y="'Take a low budget, inexperienced actors doubling as production staff\x97 as well as limited facilities\x97and you can\'t expect much more than "Time Chasers" gives you, but you can absolutely expect a lot less. This film represents a bunch of good natured friends and neighbors coming together to collaborate on an interesting project. If your cousin had been one of those involved, you would probably think to yourself, "ok, this movie is terrible... but a really good effort." For all the poorly delivered dialog and ham-fisted editing, "Time Chasers" has great scope and ambition... and one can imagine it was necessary to shoot every scene in only one or two takes. So, I\'m suggesting people cut "Time Chasers" some slack before they cut in the jugular. That said, I\'m not sure I can ever forgive the pseudo-old lady from the grocery store for the worst delivery every wrenched from the jaws of a problematic script.'"
z=set(npl.corpus.stopwords.words("english"))
x=[]
word_token=npl.tokenize.word_tokenize(y)
for i in word_token:
if(i not in z):
x.append(i)
print(np.array(x))
输出
['Take' 'low' 'budget' ',' 'inexperienced' 'actors' 'doubling'
'production' 'staff\x97' 'well' 'limited' 'facilities\x97and' 'ca' "n't"
'expect' 'much' '``' 'Time' 'Chasers' "''" 'gives' ',' 'absolutely'
'expect' 'lot' 'less' '.' 'This' 'film' 'represents' 'bunch' 'good'
'natured' 'friends' 'neighbors' 'coming' 'together' 'collaborate'
'interesting' 'project' '.' 'If' 'cousin' 'one' 'involved' ',' 'would'
'probably' 'think' ',' '``' 'ok' ',' 'movie' 'terrible' '...' 'really'
'good' 'effort' '.' "''" 'For' 'poorly' 'delivered' 'dialog' 'ham-fisted'
'editing' ',' '``' 'Time' 'Chasers' "''" 'great' 'scope' 'ambition' '...'
'one' 'imagine' 'necessary' 'shoot' 'every' 'scene' 'one' 'two' 'takes'
'.' 'So' ',' 'I' "'m" 'suggesting' 'people' 'cut' '``' 'Time' 'Chasers'
"''" 'slack' 'cut' 'jugular' '.' 'That' 'said' ',' 'I' "'m" 'sure' 'I'
'ever' 'forgive' 'pseudo-old' 'lady' 'grocery' 'store' 'worst' 'delivery'
'every' 'wrenched' 'jaws' 'problematic' 'script' '.']
就像那样。我想要段落列表的相同输出
【问题讨论】:
-
您最好在How to create a Minimal, Reproducible Example 之后提供一个最小的、可重现的示例。这样其他人就能更好地提供帮助。
-
如果以下答案之一解决了您的问题,您应该接受它(单击相应答案旁边的复选标记)。这有两件事。它让每个人都知道您的问题已得到您满意的解决,并为帮助您的人提供帮助。 See here 以获得完整的解释。
标签: python nltk data-science