加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 编程开发 > Python > 正文

Python NLTK’LazyCorpusLoader’对象不可调用

发布时间:2020-12-20 11:37:52 所属栏目:Python 来源:网络整理
导读:我正在寻求帮助,以了解我如何解决这个问题: import nltkfrom nltk.corpus import stopwordsfrom nltk.tag.stanford import POSTaggerst = POSTagger('C:Python27stanford-postagger/models/english-bidirectional-distsim.tagger','C:Python27stanford-
我正在寻求帮助,以了解我如何解决这个问题:

import nltk
from nltk.corpus import stopwords
from nltk.tag.stanford import POSTagger

st = POSTagger('C:Python27stanford-postagger/models/english-bidirectional-distsim.tagger','C:Python27stanford-postagger/stanford-postagger.jar')

def FindBigrams(concept):                                                                
    sentence = st.tag(nltk.word_tokenize(concept))        
    print sentence
    Bigrams = []                                        
    for i in range(len(sentence) - 1):
        if ( sentence[i][1] == "JJ"  and sentence[i+1][0] in stopwords('english') ):
            return concept

print FindBigrams("a very beautiful christmas gift")

错误:

[(u'a',u'DT'),(u'very',u'RB'),(u'beautiful',u'JJ'),(u'christmas',u'NNS'),(u'gift',u'NN')]   

print FindBigrams("a very beautiful christmas gift")
File "C:Python27python_projectsparserParseBigrams.py",line 15,in FindBigrams
if ( sentence[i][1] == "JJ"  and sentence[i+1][0] in stopwords('english') ):
TypeError: 'LazyCorpusLoader' object is not callable

解决方法

您使用停用词作为函数而不是stopwords.words

用stopwords.words(‘english’)替换停用词(‘english’)

for i in range(len(sentence) - 1):
        if ( sentence[i][1] == "JJ"  and sentence[i+1][0] in stopwords.words('english') ):
            return concept

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读