spaCy/spacy/en/download.py

49 lines
1.2 KiB
Python
Raw Normal View History

2015-01-02 13:44:41 +03:00
from os import path
import os
import tarfile
import shutil
2015-01-25 15:01:10 +03:00
import wget
2015-01-02 13:44:41 +03:00
DATA_DIR_URL = 'http://s3-us-west-1.amazonaws.com/media.spacynlp.com/en_data_all-0.4.tgz'
PARSER_URL = 'http://s3-us-west-1.amazonaws.com/media.spacynlp.com/en_deps-0.30.tgz'
2015-01-25 15:01:10 +03:00
DEP_VECTORS_URL = 'http://s3-us-west-1.amazonaws.com/media.spacynlp.com/vec.bin'
2015-01-30 10:59:31 +03:00
DEST_DIR = path.join(path.dirname(__file__), 'data')
2015-01-02 13:44:41 +03:00
2015-01-25 15:01:10 +03:00
def download_file(url, out):
wget.download(url, out=out)
2015-01-30 10:36:24 +03:00
return url.rsplit('/', 1)[1]
2015-01-02 13:44:41 +03:00
def install_all_data(url, dest_dir):
filename = download_file(url, dest_dir)
2015-01-30 11:28:43 +03: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 11:28:43 +03: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 15:01:10 +03:00
filename = download_file(url, dest_dir)
def main():
if not path.exists(DEST_DIR):
2015-01-30 11:28:43 +03:00
install_all_data(DATA_DIR_URL, path.dirname(DEST_DIR))
else:
install_parser_model(PARSER_URL, DEST_DIR)
install_dep_vectors(DEP_VECTORS_URL, path.join(DEST_DIR, 'vocab'))
2015-01-02 13:44:41 +03:00
if __name__ == '__main__':
main()