【发布时间】:2012-09-24 01:08:07
【问题描述】:
我想删除停用词。这是我的代码
import nltk
from nltk.corpus import stopwords
import string
u="The apple is the pomaceous fruit of the apple tree, species Malus domestica in the rose family (Rosaceae). It is one of the most widely cultivated tree fruits, and the most widely known of the many members of genus Malus that are used by humans."
v="An orange is a fruit of the orangle tree. it is the most cultivated tree fruits"
u=u.lower()
v=v.lower()
u_list=nltk.word_tokenize(u)
v_list=nltk.word_tokenize(v)
for word in u_list:
if word in stopwords.words('english'):
u_list.remove(word)
for word in v_list:
if word in stopwords.words('english'):
v_list.remove(word)
print u_list
print "\n\n\n\n"
print v_list
但只删除了一些停用词。请帮我解决这个问题
【问题讨论】:
-
定义
u时缺少引号" -
仍然无法正常工作。 'the' 'a' 之类的停用词不会被删除。
标签: python nltk stop-words