2

我正在准备使用 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
4

2 回答 2

4

您需要安装numpy

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

落后

import numpy 

您应该安装 numpy 并能够毫无错误地导入 numpy。

于 2013-03-10T11:38:11.433 回答
0

在文件 /usr/local/lib/python2.7/dist-packages/nltk/chunk/named_entity.py 更改

from nltk.classify import MaxentClassifier

from nltk.classify.maxent import MaxentClassifier
于 2014-07-15T10:31:44.550 回答