user425727
user425727

Reputation:

Python NLTK 'LazyCorpusLoader' object is not callable

I am looking for help to understand how I can fix this:

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")

Error:

[(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

Upvotes: 3

Views: 12275

Answers (2)

Salva Castro
Salva Castro

Reputation: 1

I managed to fix this error by loading the whole LazyCorpusLoader.py class in my project folder. You can find it here

Upvotes: 0

Elisha
Elisha

Reputation: 4961

you are using stopwords as a function instead of stopwords.words

replace stopwords('english') with 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

Upvotes: 11

Related Questions