您的位置:首页 > 其它

使用nltk.pos出现IndexError: string index out of range

2018-02-12 15:02 786 查看
问题重现:# -*- encoding:utf-8 -*-
import sys
reload(sys)
sys.setdefaultencoding('utf-8')
import nltk
from nltk.corpus import stopwords
text="I've got a very big apple "
text=text.split(" ")
# text.remove('')
text = list(set(text))
print text
text_list=nltk.pos_tag(text)
print text_list

for item in text_list:
if item[1]=='JJ':#如果该英文单词是形容词
print"item[0]=",item[0]
解决方案如下:# -*- encoding:utf-8 -*-
import sys
reload(sys)
sys.setdefaultencoding('utf-8')
import nltk
from nltk.corpus import stopwords
text="I've got a very big apple "
text=text.split(" ")
text.remove('')
text = list(set(text))
print text
text_list=nltk.pos_tag(text)
print text_list

for item in text_list:
if item[1]=='JJ':#如果该英文单词是形容词
print"item[0]=",item[0]
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐