spaCy/spacy/en/download.py

57 lines
1.6 KiB
Python
Raw Normal View History

2015-01-02 13:44:41 +03:00
from os import path
import os
import tarfile
import shutil
import requests
PARSER_URL = 'http://s3-us-west-1.amazonaws.com/media.spacynlp.com/en.tgz'
2015-01-02 13:44:41 +03:00
DEP_VECTORS_URL = 'http://u.cs.biu.ac.il/~yogo/data/syntemb/deps.words.bz2'
DEST_DIR = path.join(path.dirname(__file__), 'data')
2015-01-02 13:44:41 +03:00
def download_file(url):
local_filename = url.split('/')[-1]
return path.join(DEST_DIR, local_filename)
2015-01-02 13:44:41 +03:00
# NOTE the stream=True parameter
r = requests.get(url, stream=True)
print "Download %s" % url
i = 0
2015-01-02 13:44:41 +03:00
with open(local_filename, 'wb') as f:
for chunk in r.iter_content(chunk_size=1024):
if chunk: # filter out keep-alive new chunks
f.write(chunk)
f.flush()
print i
i += 1
2015-01-02 13:44:41 +03:00
return local_filename
def install_parser_model(url, dest_dir):
if not os.path.exists(dest_dir):
os.mkdir(dest_dir)
assert not path.exists(path.join(dest_dir, 'en'))
2015-01-02 13:44:41 +03:00
filename = download_file(url)
2015-01-02 13:44:41 +03:00
t = tarfile.open(filename, mode=":gz")
t.extractall(dest_dir)
shutil.move(path.join(dest_dir, 'en', 'deps', 'model'), dest_dir)
shutil.move(path.join(dest_dir, 'en', 'deps', 'config.json'), dest_dir)
shutil.rmtree(path.join(dest_dir, 'en'))
def install_dep_vectors(url, dest_dir):
if not os.path.exists(dest_dir):
os.mkdir(dest_dir)
filename = download_file(url)
shutil.move(filename, path.join(dest_dir, 'vec.bz2'))
def main():
#install_parser_model(PARSER_URL, path.join(DEST_DIR, 'deps'))
install_dep_vectors(DEP_VECTORS_URL, path.join(DEST_DIR, 'vocab'))
2015-01-02 13:44:41 +03:00
if __name__ == '__main__':
main()