【发布时间】:2016-11-11 11:27:03
【问题描述】:
我正在使用 NLTK 从列表元素中删除停用词。 这是我的代码 sn-p
dict1 = {}
for ctr,row in enumerate(cur.fetchall()):
list1 = [row[0],row[1],row[2],row[3],row[4]]
dict1[row[0]] = list1
print ctr+1,"\n",dict1[row[0]][2]
list2 = [w for w in dict1[row[0]][3] if not w in stopwords.words('english')]
print list2
问题是,这不仅会删除停用词,还会从其他词中删除字符,例如从单词'orientation''i'和更多的停用词将被删除,并且它在list2中存储字符而不是单词。 即['O','r','e','n','n','','f','','3','','r','e','r' , 'e', '', 'p', 'n', '\n', '\n', '\n', 'O', 'r', 'e', 'n', 'n' ,'','f','','n','','r','e','r','e','','r','p','l'.. ..................... 而我想将其存储为 ['Orientation','.......
【问题讨论】:
-
先尝试标记你的话
-
代码中的 cur 是什么?你能发布更多的上下文代码吗?
标签: python nltk stop-words