2015-10-25 15:15:51 +03:00
|
|
|
from __future__ import print_function
|
|
|
|
|
2015-07-26 23:40:04 +03:00
|
|
|
from fabric.api import local, lcd, env, settings, prefix
|
2015-01-03 13:02:21 +03:00
|
|
|
from os.path import exists as file_exists
|
2015-01-04 21:30:24 +03:00
|
|
|
from fabtools.python import virtualenv
|
2015-01-03 13:02:21 +03:00
|
|
|
from os import path
|
2015-07-26 23:40:04 +03:00
|
|
|
import os
|
|
|
|
import shutil
|
2015-10-25 15:15:51 +03:00
|
|
|
from pathlib import Path
|
2014-09-11 14:28:38 +04:00
|
|
|
|
2015-01-03 13:02:21 +03:00
|
|
|
|
|
|
|
PWD = path.dirname(__file__)
|
|
|
|
VENV_DIR = path.join(PWD, '.env')
|
|
|
|
|
|
|
|
|
2015-07-26 23:40:04 +03:00
|
|
|
def counts():
|
|
|
|
pass
|
|
|
|
# Tokenize the corpus
|
|
|
|
# tokenize()
|
|
|
|
# get_freqs()
|
|
|
|
# Collate the counts
|
|
|
|
# cat freqs | sort -k2 | gather_freqs()
|
|
|
|
# gather_freqs()
|
|
|
|
# smooth()
|
|
|
|
|
|
|
|
|
|
|
|
# clean, make, sdist
|
|
|
|
# cd to new env, install from sdist,
|
|
|
|
# Push changes to server
|
|
|
|
# Pull changes on server
|
|
|
|
# clean make init model
|
|
|
|
# test --vectors --slow
|
|
|
|
# train
|
|
|
|
# test --vectors --slow --models
|
|
|
|
# sdist
|
|
|
|
# upload data to server
|
|
|
|
# change to clean venv
|
|
|
|
# py2: install from sdist, test --slow, download data, test --models --vectors
|
|
|
|
# py3: install from sdist, test --slow, download data, test --models --vectors
|
|
|
|
|
|
|
|
|
|
|
|
def prebuild(build_dir='/tmp/build_spacy'):
|
|
|
|
if file_exists(build_dir):
|
|
|
|
shutil.rmtree(build_dir)
|
|
|
|
os.mkdir(build_dir)
|
|
|
|
spacy_dir = path.dirname(__file__)
|
|
|
|
wn_url = 'http://wordnetcode.princeton.edu/3.0/WordNet-3.0.tar.gz'
|
|
|
|
build_venv = path.join(build_dir, '.env')
|
|
|
|
with lcd(build_dir):
|
|
|
|
local('git clone %s .' % spacy_dir)
|
|
|
|
local('virtualenv ' + build_venv)
|
2015-07-27 02:52:04 +03:00
|
|
|
with prefix('cd %s && PYTHONPATH=`pwd` && . %s/bin/activate' % (build_dir, build_venv)):
|
2015-10-09 12:57:47 +03:00
|
|
|
local('pip install cython fabric fabtools pytest')
|
2015-10-19 08:47:14 +03:00
|
|
|
local('pip install --no-cache-dir -r requirements.txt')
|
2015-07-26 23:40:04 +03:00
|
|
|
local('fab clean make')
|
|
|
|
local('cp -r %s/corpora/en/wordnet corpora/en/' % spacy_dir)
|
2015-09-13 02:27:49 +03:00
|
|
|
local('PYTHONPATH=`pwd` python bin/init_model.py en lang_data corpora spacy/en/data')
|
2015-07-26 23:40:04 +03:00
|
|
|
local('fab test')
|
2015-11-03 09:21:03 +03:00
|
|
|
local('PYTHONPATH=`pwd` python -m spacy.en.download --force all')
|
2015-11-03 09:11:59 +03:00
|
|
|
local('py.test --models spacy/tests/')
|
2015-01-03 13:02:21 +03:00
|
|
|
|
2015-10-25 15:15:51 +03:00
|
|
|
|
2015-11-24 16:46:48 +03:00
|
|
|
def web():
|
2015-10-25 15:15:51 +03:00
|
|
|
def jade(source_name, out_dir):
|
|
|
|
pwd = path.join(path.dirname(__file__), 'website')
|
|
|
|
jade_loc = path.join(pwd, 'src', 'jade', source_name)
|
|
|
|
out_loc = path.join(pwd, 'site', out_dir)
|
|
|
|
local('jade -P %s --out %s' % (jade_loc, out_loc))
|
|
|
|
|
2015-10-25 15:27:37 +03:00
|
|
|
with virtualenv(VENV_DIR):
|
2015-11-19 15:22:56 +03:00
|
|
|
local('./website/create_code_samples spacy/tests/website/ website/src/code/')
|
2015-10-25 15:27:37 +03:00
|
|
|
|
2015-11-26 11:27:04 +03:00
|
|
|
jade('404.jade', '')
|
2015-10-25 15:15:51 +03:00
|
|
|
jade('home/index.jade', '')
|
|
|
|
jade('docs/index.jade', 'docs/')
|
|
|
|
jade('blog/index.jade', 'blog/')
|
|
|
|
|
2015-11-26 11:15:43 +03:00
|
|
|
for collection in ('blog', 'tutorials'):
|
|
|
|
for post_dir in (Path(__file__).parent / 'website' / 'src' / 'jade' / collection).iterdir():
|
|
|
|
if post_dir.is_dir() \
|
|
|
|
and (post_dir / 'index.jade').exists() \
|
|
|
|
and (post_dir / 'meta.jade').exists():
|
|
|
|
jade(str(post_dir / 'index.jade'), path.join(collection, post_dir.parts[-1]))
|
2015-11-19 15:22:56 +03:00
|
|
|
|
|
|
|
|
2015-11-24 16:46:48 +03:00
|
|
|
def web_publish(assets_path):
|
2015-12-03 21:47:55 +03:00
|
|
|
from boto.s3.connection import S3Connection, OrdinaryCallingFormat
|
|
|
|
|
|
|
|
site_path = 'website/site'
|
|
|
|
|
|
|
|
os.environ['S3_USE_SIGV4'] = 'True'
|
|
|
|
conn = S3Connection(host='s3.eu-central-1.amazonaws.com',
|
|
|
|
calling_format=OrdinaryCallingFormat())
|
|
|
|
bucket = conn.get_bucket('spacy.io', validate=False)
|
|
|
|
|
|
|
|
keys_left = set([k.name for k in bucket.list()
|
|
|
|
if not k.name.startswith('resources')])
|
|
|
|
|
|
|
|
for root, dirnames, filenames in os.walk(site_path):
|
|
|
|
for filename in filenames:
|
|
|
|
source = os.path.join(root, filename)
|
|
|
|
|
|
|
|
target = os.path.relpath(root, site_path)
|
|
|
|
if target == '.':
|
|
|
|
target = filename
|
|
|
|
elif filename != 'index.html':
|
|
|
|
target = os.path.join(target, filename)
|
|
|
|
|
|
|
|
key = bucket.new_key(target)
|
|
|
|
key.set_metadata('Content-Type', 'text/html')
|
|
|
|
key.set_contents_from_filename(source)
|
|
|
|
print('uploading %s' % target)
|
|
|
|
|
|
|
|
keys_left.remove(target)
|
|
|
|
|
|
|
|
for key_name in keys_left:
|
|
|
|
print('deleting %s' % key_name)
|
|
|
|
bucket.delete_key(key_name)
|
|
|
|
|
2015-11-24 16:46:48 +03:00
|
|
|
local('aws s3 sync --delete %s s3://spacy.io/resources' % assets_path)
|
|
|
|
|
|
|
|
|
2015-09-22 03:26:10 +03:00
|
|
|
def publish(version):
|
2015-01-03 13:02:21 +03:00
|
|
|
with virtualenv(VENV_DIR):
|
2015-01-05 09:55:51 +03:00
|
|
|
local('git push origin master')
|
2015-09-22 03:26:10 +03:00
|
|
|
local('git tag -a %s' % version)
|
|
|
|
local('git push origin %s' % version)
|
|
|
|
local('python setup.py sdist')
|
|
|
|
local('python setup.py register')
|
2015-10-25 15:15:51 +03:00
|
|
|
local('twine upload dist/spacy-%s.tar.gz' % version)
|
2015-01-03 13:02:21 +03:00
|
|
|
|
|
|
|
|
2015-01-05 19:24:27 +03:00
|
|
|
def env(lang="python2.7"):
|
2015-01-03 13:02:21 +03:00
|
|
|
if file_exists('.env'):
|
|
|
|
local('rm -rf .env')
|
2015-01-05 19:24:27 +03:00
|
|
|
local('virtualenv -p %s .env' % lang)
|
2015-01-03 13:02:21 +03:00
|
|
|
|
|
|
|
|
|
|
|
def install():
|
|
|
|
with virtualenv(VENV_DIR):
|
2015-01-04 21:30:24 +03:00
|
|
|
local('pip install --upgrade setuptools')
|
2015-01-03 13:02:21 +03:00
|
|
|
local('pip install dist/*.tar.gz')
|
|
|
|
local('pip install pytest')
|
|
|
|
|
2014-07-05 22:49:34 +04:00
|
|
|
|
|
|
|
def make():
|
2015-01-05 19:24:27 +03:00
|
|
|
with virtualenv(VENV_DIR):
|
2015-01-03 13:02:21 +03:00
|
|
|
with lcd(path.dirname(__file__)):
|
2015-01-05 19:24:27 +03:00
|
|
|
local('pip install cython')
|
|
|
|
local('pip install murmurhash')
|
|
|
|
local('pip install -r requirements.txt')
|
2015-01-04 21:30:24 +03:00
|
|
|
local('python setup.py build_ext --inplace')
|
2015-01-03 13:02:21 +03:00
|
|
|
|
|
|
|
|
|
|
|
def clean():
|
|
|
|
with lcd(path.dirname(__file__)):
|
2015-01-25 06:49:29 +03:00
|
|
|
local('python setup.py clean --all')
|
2015-01-03 13:02:21 +03:00
|
|
|
|
2014-07-05 22:49:34 +04:00
|
|
|
|
2015-01-03 13:02:21 +03:00
|
|
|
def test():
|
|
|
|
with virtualenv(VENV_DIR):
|
|
|
|
with lcd(path.dirname(__file__)):
|
2015-11-03 08:39:30 +03:00
|
|
|
local('py.test -x spacy/tests')
|
2014-09-11 14:28:38 +04:00
|
|
|
|
2014-11-05 12:46:29 +03:00
|
|
|
|
2015-05-12 23:34:07 +03:00
|
|
|
def train(json_dir=None, dev_loc=None, model_dir=None):
|
|
|
|
if json_dir is None:
|
|
|
|
json_dir = 'corpora/en/json'
|
2015-04-08 23:47:59 +03:00
|
|
|
if model_dir is None:
|
|
|
|
model_dir = 'models/en/'
|
|
|
|
with virtualenv(VENV_DIR):
|
|
|
|
with lcd(path.dirname(__file__)):
|
2015-11-18 20:28:28 +03:00
|
|
|
local('python bin/init_model.py en lang_data/ corpora/ ' + model_dir)
|
2015-05-12 23:34:07 +03:00
|
|
|
local('python bin/parser/train.py %s %s' % (json_dir, model_dir))
|
2015-04-08 23:47:59 +03:00
|
|
|
|
|
|
|
|
2015-01-04 21:30:24 +03:00
|
|
|
def travis():
|
|
|
|
local('open https://travis-ci.org/honnibal/thinc')
|
2014-08-20 19:02:32 +04:00
|
|
|
|
2014-09-11 14:28:38 +04:00
|
|
|
|
2014-11-05 12:46:29 +03:00
|
|
|
def pos():
|
2015-01-17 08:20:03 +03:00
|
|
|
with virtualenv(VENV_DIR):
|
|
|
|
local('python tools/train.py ~/work_data/docparse/wsj02-21.conll ~/work_data/docparse/wsj22.conll spacy/en/data')
|
|
|
|
local('python tools/tag.py ~/work_data/docparse/wsj22.raw /tmp/tmp')
|
|
|
|
local('python tools/eval_pos.py ~/work_data/docparse/wsj22.conll /tmp/tmp')
|
2014-11-05 12:46:29 +03:00
|
|
|
|
|
|
|
|
|
|
|
def ner():
|
|
|
|
local('rm -rf data/en/ner')
|
2014-11-11 13:10:40 +03:00
|
|
|
local('python tools/train_ner.py ~/work_data/docparse/wsj02-21.conll data/en/ner')
|
|
|
|
local('python tools/tag_ner.py ~/work_data/docparse/wsj22.raw /tmp/tmp')
|
2014-11-06 20:44:14 +03:00
|
|
|
local('python tools/eval_ner.py ~/work_data/docparse/wsj22.conll /tmp/tmp | tail')
|
2014-11-12 15:22:05 +03:00
|
|
|
|
|
|
|
|
|
|
|
def conll():
|
|
|
|
local('rm -rf data/en/ner')
|
|
|
|
local('python tools/conll03_train.py ~/work_data/ner/conll2003/eng.train data/en/ner/')
|
|
|
|
local('python tools/conll03_eval.py ~/work_data/ner/conll2003/eng.testa')
|