我正在准备使用 Python 进行自然语言处理这本书。
第 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