Commit 73906dcc by Steven Bird

protect all numpy imports with a try-except block; so that NLTK can be imported…

protect all numpy imports with a try-except block; so that NLTK can be imported when numpy is not installed (i.e. missing numpy should only generate errors at runtime
parent bbee3018
...@@ -53,7 +53,11 @@ interface. ...@@ -53,7 +53,11 @@ interface.
""" """
__docformat__ = 'epytext en' __docformat__ = 'epytext en'
import numpy try:
import numpy
except ImportError:
pass
import time import time
import tempfile import tempfile
import os import os
......
...@@ -35,10 +35,12 @@ chi-square feature selection: ...@@ -35,10 +35,12 @@ chi-square feature selection:
from nltk.classify.api import ClassifierI from nltk.classify.api import ClassifierI
from nltk.probability import DictionaryProbDist from nltk.probability import DictionaryProbDist
import numpy as np
from scipy.sparse import coo_matrix from scipy.sparse import coo_matrix
try:
import numpy as np
except ImportError:
pass
class SklearnClassifier(ClassifierI): class SklearnClassifier(ClassifierI):
"""Wrapper for scikit-learn classifiers.""" """Wrapper for scikit-learn classifiers."""
......
...@@ -5,7 +5,10 @@ ...@@ -5,7 +5,10 @@
# URL: <http://www.nltk.org/> # URL: <http://www.nltk.org/>
# For license information, see LICENSE.TXT # For license information, see LICENSE.TXT
import numpy try:
import numpy
except ImportError:
pass
from util import VectorSpaceClusterer from util import VectorSpaceClusterer
......
...@@ -5,9 +5,13 @@ ...@@ -5,9 +5,13 @@
# URL: <http://www.nltk.org/> # URL: <http://www.nltk.org/>
# For license information, see LICENSE.TXT # For license information, see LICENSE.TXT
import numpy
import copy import copy
try:
import numpy
except ImportError:
pass
from nltk.cluster.util import VectorSpaceClusterer, Dendrogram from nltk.cluster.util import VectorSpaceClusterer, Dendrogram
class GAAClusterer(VectorSpaceClusterer): class GAAClusterer(VectorSpaceClusterer):
......
...@@ -6,10 +6,15 @@ ...@@ -6,10 +6,15 @@
# For license information, see LICENSE.TXT # For license information, see LICENSE.TXT
import copy import copy
import numpy
import random import random
import sys import sys
try:
import numpy
except ImportError:
pass
from nltk.cluster.util import VectorSpaceClusterer from nltk.cluster.util import VectorSpaceClusterer
class KMeansClusterer(VectorSpaceClusterer): class KMeansClusterer(VectorSpaceClusterer):
......
...@@ -6,10 +6,14 @@ ...@@ -6,10 +6,14 @@
# For license information, see LICENSE.TXT # For license information, see LICENSE.TXT
import copy import copy
import numpy
from sys import stdout from sys import stdout
from math import sqrt from math import sqrt
try:
import numpy
except ImportError:
pass
from nltk.cluster.api import ClusterI from nltk.cluster.api import ClusterI
class VectorSpaceClusterer(ClusterI): class VectorSpaceClusterer(ClusterI):
......
...@@ -41,7 +41,10 @@ Statistical Models for Text Segmentation ...@@ -41,7 +41,10 @@ Statistical Models for Text Segmentation
Machine Learning, 34, 177-210 Machine Learning, 34, 177-210
""" """
import numpy try:
import numpy
except ImportError:
pass
def windowdiff(seg1, seg2, k, boundary="1"): def windowdiff(seg1, seg2, k, boundary="1"):
""" """
......
...@@ -8,7 +8,11 @@ ...@@ -8,7 +8,11 @@
import re import re
import math import math
import numpy
try:
import numpy
except ImportError:
pass
from nltk.tokenize.api import TokenizerI from nltk.tokenize.api import TokenizerI
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment