Python NLTK'LazyCorpusLoader'对象不可调用

时间:2014-09-18 10:31:01

标签: python nltk

我正在寻求帮助,以了解我如何解决这个问题:

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

st = POSTagger('C:\Python27\stanford-postagger/models/english-bidirectional-distsim.tagger', 
                        'C:\Python27\stanford-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:\Python27\python_projects\parser\ParseBigrams.py", line 15, in FindBigrams
if ( sentence[i][1] == "JJ"  and sentence[i+1][0] in stopwords('english') ):
TypeError: 'LazyCorpusLoader' object is not callable

2 个答案:

答案 0 :(得分:7)

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

stopwords('english')替换为stopwords.words('english')

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

答案 1 :(得分:0)

我设法通过在项目文件夹中加载整个LazyCorpusLoader.py类来解决此错误。您可以找到它here