使用nltk.pos出现IndexError: string index out of range
生活随笔
收集整理的這篇文章主要介紹了
使用nltk.pos出现IndexError: string index out of range
小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.
問題重現(xiàn):
# -*- 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_listfor 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_listfor item in text_list:if item[1]=='JJ':#如果該英文單詞是形容詞print"item[0]=",item[0]總結
以上是生活随笔為你收集整理的使用nltk.pos出现IndexError: string index out of range的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: python的sorted函数对字典按k
- 下一篇: 在线nltk分词和词性标注