-
Notifications
You must be signed in to change notification settings - Fork 2
/
setup.py
69 lines (54 loc) · 1.95 KB
/
setup.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
"""
Check and (if necessary) install the correct versions of the word vector model and also of corenlp.
Check versions of LIWC and python and hint possible problems to the user.
This script is to be automatically executed before execution of the pipeline.
"""
import sys
import os
import requests
import zipfile
import io
import nltk
import gdown
import gzip
import shutil
import spacy
from cdcr.config import GLOVE_MAGN_PATH, LOGGER
CORE_NLP = 'http://nlp.stanford.edu/software/stanford-corenlp-full-2018-10-05.zip'
GLOVE_MAGN = "http://magnitude.plasticity.ai/glove/medium/glove.840B.300d.magnitude"
def check_errors():
old_cwd = os.getcwd()
_cwd_to_here()
errors = {
"python": sys.version_info < (3, 6) or sys.version_info >= (3, 8),
"corenlp": not os.path.isdir('./resources/corenlp/stanford-corenlp-full-2018-10-05'),
"evaluation": not os.path.isdir('./resources/evaluation_results'),
"wordvectors": not os.path.isfile(GLOVE_MAGN_PATH)
}
os.chdir(old_cwd)
return errors
def init():
LOGGER.info('Running... (this takes a while, do not abort)')
old_cwd = os.getcwd()
_cwd_to_here()
errors = check_errors()
if errors["python"]:
raise SystemExit('Sorry, this code needs Python 3.6. Please refer to the readme to install.')
if errors["corenlp"]:
LOGGER.info(f"Downloading {CORE_NLP}...")
r = requests.get(CORE_NLP)
z = zipfile.ZipFile(io.BytesIO(r.content))
z.extractall('./resources/corenlp/')
if errors["wordvectors"]:
LOGGER.info(f"Downloading {GLOVE_MAGN}...")
gdown.download(GLOVE_MAGN, GLOVE_MAGN_PATH, quiet=False)
nltk.download('stopwords', quiet=True)
nltk.download('wordnet', quiet=True)
spacy.cli.download('en_core_web_sm')
os.chdir(old_cwd)
LOGGER.info('Setup completed')
def _cwd_to_here():
file_dir = os.path.dirname(os.path.abspath(__file__))
os.chdir(file_dir)
if __name__ == '__main__':
init()