error-handling - Python,导入错误: MaxentClassifier

标签 error-handling python-2.7 nltk

我正在准备《使用 Python 进行自然语言处理》一书。

http://rafale.org/~mattoufoutu/ebooks/Doc_diverse/Cours%20Prog/Python/Books/Natural%20Language%20Processing%20with%20Python%20%282009%29.pdf

第 7.5 段命名实体识别。

我按照这个例子写:

sent = nltk.corpus.treebank.tagged_sents()[22]
print nltk.ne_chunk(sent, binary=True)

我收到以下错误:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/local/lib/python2.7/dist-packages/nltk/chunk/__init__.py", line 176, in ne_chunk
    chunker = load(chunker_pickle)
  File "/usr/local/lib/python2.7/dist-packages/nltk/data.py", line 605, in load
    resource_val = pickle.load(_open(resource_url))
  File "/usr/local/lib/python2.7/dist-packages/nltk/chunk/named_entity.py", line 16, in <module>
    from nltk.classify import MaxentClassifier
ImportError: cannot import name MaxentClassifier

知道为什么它不起作用吗?

谢谢!

编辑:文件内容:/usr/local/lib/python2.7/dist-packages/nltk/classify/init.pyc

from nltk.classify.api import ClassifierI, MultiClassifierI
from nltk.classify.mallet import config_mallet, call_mallet
from nltk.classify.megam import config_megam, call_megam
from nltk.classify.weka import WekaClassifier, config_weka
from nltk.classify.naivebayes import NaiveBayesClassifier
from nltk.classify.positivenaivebayes import PositiveNaiveBayesClassifier
from nltk.classify.decisiontree import DecisionTreeClassifier
from nltk.classify.rte_classify import rte_classifier, rte_features, RTEFeatureExtractor
from nltk.classify.util import accuracy, apply_features, log_likelihood

# Conditional imports

try:
    from scikitlearn import SklearnClassifier
except ImportError:
    pass

try:
    import numpy
    from nltk.classify.maxent import (MaxentClassifier, BinaryMaxentFeatureEncoding,
                                      TypedMaxentFeatureEncoding,
                                      ConditionalExponentialClassifier)
    import svmlight
    from nltk.classify.svm import SvmClassifier
except ImportError:
    pass

最佳答案

您需要安装numpy:

from nltk.classify.maxent import (MaxentClassifier,... 

落后

import numpy 

您应该安装 numpy 并且能够毫无错误地执行 import numpy。

关于error-handling - Python,导入错误: MaxentClassifier,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15320894/

相关文章:

nlp - 韩语、泰语和印尼语 POS 标记器

Python:UnicodeWarning:Unicode 相等比较未能将两个参数转换为 Unicode - 将它们解释为不相等

python - NLTK panlex_lite 给我错误

python - 如何在 python 中迭代跳过 TypeError、AttributeError 和 IndexError?

php - 如何阻止php脚本将错误附加到浏览器?

java - 我不断收到<identifier>预期错误

excel - 运行时错误13类型错误匹配VBA Excel 2010

python - 从 int 派生并在 python 类中使用关键字参数

Python - 从文件中删除一行(使用条目的待办事项列表程序,与其他帖子不同)

Python 脚本可以独立工作,但不能在 crontab 中工作