Skip to content

Commit

Permalink
Fix issue with nltk data not downloading
Browse files Browse the repository at this point in the history
  • Loading branch information
gunthercox committed Nov 26, 2016
1 parent 86cbe18 commit 9bc2e90
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 13 deletions.
15 changes: 2 additions & 13 deletions chatterbot/utils.py
Expand Up @@ -94,26 +94,15 @@ def nltk_download_corpus(corpus_name):
"""
from nltk.data import find
from nltk import download
import os

# Download the wordnet data only if it is not already downloaded
zip_file = '{}.zip'.format(corpus_name)
downloaded = False
wordnet_path = None
if os.name == 'nt':
wordnet_path = os.path.join(
os.getenv('APPDATA'), 'nltk_data', 'corpora', zip_file
)
else:
wordnet_path = os.path.join(
os.path.expanduser('~'), 'nltk_data', 'corpora', zip_file
)

try:
if not os.path.isfile(wordnet_path):
find(zip_file)
find(zip_file)
except LookupError:
download('wordnet')
download(corpus_name)
downloaded = True

return downloaded
Expand Down
3 changes: 3 additions & 0 deletions tests/logic_adapter_tests/test_closest_meaning.py
Expand Up @@ -20,6 +20,9 @@ def setUp(self):
self.adapter.set_chatbot(MockChatBot())

def test_no_choices(self):
"""
An exception should be raised if there is no data in the database.
"""
self.adapter.chatbot.storage.filter = MagicMock(return_value=[])
statement = Statement('Hello')

Expand Down
1 change: 1 addition & 0 deletions tests/test_utils.py
Expand Up @@ -17,6 +17,7 @@ def test_remove_stop_words(self):
from chatterbot.utils import nltk_download_corpus

nltk_download_corpus('stopwords')

tokens = ['this', 'is', 'a', 'test', 'string']
words = utils.remove_stopwords(tokens, 'english')

Expand Down

0 comments on commit 9bc2e90

Please sign in to comment.