Python NLTK 'LazyCorpusLoader' 对象不可调用

标签 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

最佳答案

您正在使用 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

关于Python NLTK 'LazyCorpusLoader' 对象不可调用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25910257/

相关文章:

python - 如何计算(正态)分布上的点的 p 值?

python - 将 django-cms 集成到现有项目中 - 错误 : TemplateDoesNotExist at/news/cms_wizard/create/

python - 通过删除 Python 中的子集来折叠短语列表

python - 如何分批训练 NLTK PunktSentenceTokenizer?

python - nltk:如何将周围的单词融入上下文中进行词形还原?

python - 在一个简单的python代码块中获取 "ValueError: concat() expects at least one object!"

python - 使用NLTK摆脱停用词和文档标记化

python - Pandas head 命令没有给出预期的结果

python - 使用 Flask 对每个请求运行 jinja2 template_filter

python - 如何在不使用 pip 的情况下在 Linux 终端中查看 pysnmp 版本