-
Notifications
You must be signed in to change notification settings - Fork 225
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
* allow nlg-eval --setup to work from anywhere. Fixes #78 nlg-eval --setup now takes a path as an argument or "default". During setup, - The code location is inferred from the package directory. - The data location is stored in a config file, so that it does not have to be provided again. A common function (`nlgeval.utils.get_data_dir()`) provides (rudimentarily checked) access to the data location via environment variable or config file (in this order). Added some colorful hints as to where data is stored to setup/CLI. * move nltk downloading to setup function, never got this to work * setup: update glove2word2vec download URL after PR merge
- Loading branch information
Showing
9 changed files
with
118 additions
and
49 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
import click | ||
import json | ||
import os | ||
|
||
from xdg import XDG_CONFIG_HOME | ||
|
||
|
||
class InvalidDataDirException(Exception): | ||
pass | ||
|
||
|
||
def get_data_dir(): | ||
if os.environ.get('NLGEVAL_DATA'): | ||
if not os.path.exists(os.environ.get('NLGEVAL_DATA')): | ||
click.secho("NLGEVAL_DATA variable is set but points to non-existent path.", fg='red', err=True) | ||
raise InvalidDataDirException() | ||
return os.environ.get('NLGEVAL_DATA') | ||
else: | ||
try: | ||
cfg_file = os.path.join(XDG_CONFIG_HOME, 'nlgeval', 'rc.json') | ||
with open(cfg_file, 'rt') as f: | ||
rc = json.load(f) | ||
if not os.path.exists(rc['data_path']): | ||
click.secho("Data path found in {} does not exist: {} " % (cfg_file, rc['data_path']), fg='red', err=True) | ||
click.secho("Run `nlg-eval --setup DATA_DIR' to download or set $NLGEVAL_DATA to an existing location", | ||
fg='red', err=True) | ||
raise InvalidDataDirException() | ||
return rc['data_path'] | ||
except: | ||
click.secho("Could not determine location of data.", fg='red', err=True) | ||
click.secho("Run `nlg-eval --setup DATA_DIR' to download or set $NLGEVAL_DATA to an existing location", fg='red', | ||
err=True) | ||
raise InvalidDataDirException() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,3 +9,4 @@ scikit-learn>=0.17 | |
gensim>=3 | ||
Theano>=0.8.1 | ||
tqdm>=4.24 | ||
xdg |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters