spaCy/spacy/en/download.py

56 lines
1.5 KiB
Python
Raw Normal View History

2015-02-01 02:22:23 +00:00
from __future__ import print_function
2015-01-02 10:44:41 +00:00
from os import path
import os
import tarfile
import shutil
2015-01-25 12:01:10 +00:00
import wget
2015-01-31 02:51:56 +00:00
import plac
2015-01-02 10:44:41 +00:00
ALL_DATA_DIR_URL = 'http://s3-us-west-1.amazonaws.com/media.spacynlp.com/en_data_all-0.4.tgz'
SM_DATA_DIR_URL = 'http://s3-us-west-1.amazonaws.com/media.spacynlp.com/en_data_sm-0.4.tgz'
PARSER_URL = 'http://s3-us-west-1.amazonaws.com/media.spacynlp.com/en_deps-0.30.tgz'
2015-01-25 12:01:10 +00:00
DEP_VECTORS_URL = 'http://s3-us-west-1.amazonaws.com/media.spacynlp.com/vec.bin'
2015-01-30 07:59:31 +00:00
DEST_DIR = path.join(path.dirname(__file__), 'data')
2015-01-02 10:44:41 +00:00
2015-01-25 12:01:10 +00:00
def download_file(url, out):
wget.download(url, out=out)
2015-01-30 07:36:24 +00:00
return url.rsplit('/', 1)[1]
2015-01-02 10:44:41 +00:00
2015-01-30 09:33:19 +00:00
def install_data(url, dest_dir):
filename = download_file(url, dest_dir)
2015-01-30 08:28:43 +00:00
t = tarfile.open(path.join(dest_dir, filename))
t.extractall(dest_dir)
def install_parser_model(url, dest_dir):
filename = download_file(url, dest_dir)
t = tarfile.open(path.join(dest_dir, filename), mode=":gz")
2015-01-30 08:28:43 +00:00
t.extractall(path.dirname(__file__))
def install_dep_vectors(url, dest_dir):
if not os.path.exists(dest_dir):
os.mkdir(dest_dir)
2015-01-25 12:01:10 +00:00
filename = download_file(url, dest_dir)
2015-01-31 02:51:56 +00:00
def main(data_size='all'):
if data_size == 'all':
data_url = ALL_DATA_DIR_URL
elif data_size == 'small':
data_url = SM_DATA_DIR_URL
2015-02-01 02:22:23 +00:00
if path.exists(DEST_DIR):
print("Moving existing dir %s to /tmp" % DEST_DIR)
shutil.move(DEST_DIR, '/tmp')
2015-01-31 11:48:32 +00:00
install_data(data_url, path.dirname(DEST_DIR))
2015-01-02 10:44:41 +00:00
if __name__ == '__main__':
2015-01-31 02:51:56 +00:00
plac.call(main)