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.
"""
__docformat__ = 'epytext en'
import numpy
try:
import numpy
except ImportError:
pass
import time
import tempfile
import os
......
......@@ -35,10 +35,12 @@ chi-square feature selection:
from nltk.classify.api import ClassifierI
from nltk.probability import DictionaryProbDist
import numpy as np
from scipy.sparse import coo_matrix
try:
import numpy as np
except ImportError:
pass
class SklearnClassifier(ClassifierI):
"""Wrapper for scikit-learn classifiers."""
......
......@@ -5,7 +5,10 @@
# URL: <http://www.nltk.org/>
# For license information, see LICENSE.TXT
import numpy
try:
import numpy
except ImportError:
pass
from util import VectorSpaceClusterer
......
......@@ -5,9 +5,13 @@
# URL: <http://www.nltk.org/>
# For license information, see LICENSE.TXT
import numpy
import copy
try:
import numpy
except ImportError:
pass
from nltk.cluster.util import VectorSpaceClusterer, Dendrogram
class GAAClusterer(VectorSpaceClusterer):
......
......@@ -6,10 +6,15 @@
# For license information, see LICENSE.TXT
import copy
import numpy
import random
import sys
try:
import numpy
except ImportError:
pass
from nltk.cluster.util import VectorSpaceClusterer
class KMeansClusterer(VectorSpaceClusterer):
......
......@@ -6,10 +6,14 @@
# For license information, see LICENSE.TXT
import copy
import numpy
from sys import stdout
from math import sqrt
try:
import numpy
except ImportError:
pass
from nltk.cluster.api import ClusterI
class VectorSpaceClusterer(ClusterI):
......
......@@ -41,7 +41,10 @@ Statistical Models for Text Segmentation
Machine Learning, 34, 177-210
"""
import numpy
try:
import numpy
except ImportError:
pass
def windowdiff(seg1, seg2, k, boundary="1"):
"""
......
......@@ -8,7 +8,11 @@
import re
import math
import numpy
try:
import numpy
except ImportError:
pass
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