Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

nltk_data download loop #369

Merged
merged 2 commits into from
Oct 30, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ venv
*.pyc
*.swp
*.egg-info
*.egg/*

# Database files
*.sqlite3
Expand Down
11 changes: 10 additions & 1 deletion chatterbot/utils/stop_words.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,19 @@ class StopWordsManager(object):
def __init__(self):
from nltk.data import find
from nltk import download
import os

# Download the stopwords data only if it is not already downloaded
stopwords_path = None
if os.name == 'nt':
stopwords_path = os.path.join(os.getenv('APPDATA'), 'nltk_data',
'corpora', 'stopwords.zip')
else:
stopwords_path = os.path.join(os.path.expanduser('~'), 'nltk_data',
'corpora', 'stopwords.zip')
try:
find('stopwords.zip')
if not os.path.isfile(stopwords_path):
find('stopwords.zip')
except LookupError:
download('stopwords')

Expand Down
11 changes: 10 additions & 1 deletion chatterbot/utils/tokenizer.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,19 @@ class Tokenizer(object):
def __init__(self):
from nltk.data import find
from nltk import download
import os

# Download the punkt data only if it is not already downloaded
punkt_path = None
if os.name == 'nt':
punkt_path = os.path.join(os.getenv('APPDATA'), 'nltk_data',
'tokenizers', 'punkt.zip')
else:
punkt_path = os.path.join(os.path.expanduser('~'), 'nltk_data',
'tokenizers', 'punkt.zip')
try:
find('punkt.zip')
if not os.path.isfile(punkt_path):
find('punkt.zip')
except LookupError:
download('punkt')

Expand Down
14 changes: 12 additions & 2 deletions chatterbot/utils/wordnet.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,19 @@ class Wordnet(object):
def __init__(self):
from nltk.data import find
from nltk import download

import os

# Download the wordnet data only if it is not already downloaded
wordnet_path = None
if os.name == 'nt':
wordnet_path = os.path.join(os.getenv('APPDATA'), 'nltk_data',
'corpora', 'wordnet.zip')
else:
wordnet_path = os.path.join(os.path.expanduser('~'), 'nltk_data',
'corpora', 'wordnet.zip')
try:
find('wordnet.zip')
if not os.path.isfile(wordnet_path):
find('wordnet.zip')
except LookupError:
download('wordnet')

Expand Down