Repository: nltk/nltk

Issue:
ImportError: cannot import name MaxentClassifier
When running

```
>>> nltk.ne_chunker("This is a sentence about A Bug.")
```



Discussion:
Are you using the latest source checkout from github? The old MaxentClassifier used a deprecated function in Scipy.

I use Python 2.7.3, and get the same error, then tried your suggestion of installing nltk from source (at 3f0c8c97a0e9784086963a94670347d22d6b001a), but now  I get a new error:

```
>>> entities = nltk.chunk.ne_chunk(tagged)
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
  File "/usr/local/lib/python2.7/dist-packages/nltk/data.py", line 605, in load
ImportError: No module named named_entity
```

Actually, I tried to start over.
I restarted the Python interpreter after installing nltk from source (after removing the previous one I installed with pip), and:

```
>>> import nltk
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "nltk.py", line 4, in <module>
    tokens = nltk.word_tokenize(sentence)
AttributeError: 'module' object has no attribute 'word_tokenize'
```

I do apologise: I had a scratch file called `nltk.py` in my current directory, and this seemed to confuse the import. It all works now, thank you.

This question refers to that error:

http://stackoverflow.com/questions/15320894/python-importerror-maxentclassifier/15321784#15321784

It would be good to know that numpy should be installed in some cases.

I do not know of wether you resolved it. Just for information.

It is the pattern of conditional imports (based e.g. on numpy or svmlight presence) that causes troubles. Since  `nltk.classify.maxent`, `nltk.classify.svm` and `nltk.classify.scikitlearn`  are all now importable without dependencies installed, we should probably just make imports unconditional.


Resolving patch:
diff --git a/nltk/classify/__init__.py b/nltk/classify/__init__.py
--- a/nltk/classify/__init__.py
+++ b/nltk/classify/__init__.py
@@ -91,24 +91,8 @@
 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)
-except ImportError:
-    pass
-
-try:
-    import svmlight
-    from nltk.classify.svm import SvmClassifier
-except ImportError:
-    pass
+from nltk.classify.scikitlearn import SklearnClassifier
+from nltk.classify.maxent import (MaxentClassifier, BinaryMaxentFeatureEncoding,
+                                  TypedMaxentFeatureEncoding,
+                                  ConditionalExponentialClassifier)
+from nltk.classify.svm import SvmClassifier
diff --git a/nltk/tag/__init__.py b/nltk/tag/__init__.py
--- a/nltk/tag/__init__.py
+++ b/nltk/tag/__init__.py
@@ -74,15 +74,10 @@
 from nltk.tag.hunpos     import HunposTagger
 from nltk.tag.stanford   import StanfordTagger
 from nltk.tag.crf        import MalletCRF
+from nltk.tag.hmm        import HiddenMarkovModelTagger, HiddenMarkovModelTrainer
 
-from nltk.data      import load
+from nltk.data import load
 
-# Import hmm module if numpy is installed
-try:
-    import numpy
-    from nltk.tag.hmm import HiddenMarkovModelTagger, HiddenMarkovModelTrainer
-except ImportError:
-    pass
 
 # Standard treebank POS tagger
 _POS_TAGGER = 'taggers/maxent_treebank_pos_tagger/english.pickle'
diff --git a/nltk/tokenize/__init__.py b/nltk/tokenize/__init__.py
--- a/nltk/tokenize/__init__.py
+++ b/nltk/tokenize/__init__.py
@@ -57,13 +57,7 @@
 from nltk.tokenize.punkt    import PunktSentenceTokenizer, PunktWordTokenizer
 from nltk.tokenize.sexpr    import SExprTokenizer, sexpr_tokenize
 from nltk.tokenize.treebank import TreebankWordTokenizer
-
-try:
-    import numpy
-except ImportError:
-    pass
-else:
-    from nltk.tokenize.texttiling import TextTilingTokenizer
+from nltk.tokenize.texttiling import TextTilingTokenizer
 
 # Standard sentence tokenizer.
 def sent_tokenize(text):


Test patch: