generated from tulane-cmps6730/sample-project
-
Notifications
You must be signed in to change notification settings - Fork 0
/
__init__.py
46 lines (37 loc) · 1.14 KB
/
__init__.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
# -*- coding: utf-8 -*-
"""Top-level package for nlp."""
__author__ = """A Student"""
__email__ = '[email protected]'
__version__ = '0.1.0'
# -*- coding: utf-8 -*-
import configparser
import os
# ~/.nlp/nlp.cfg will contain configuration information for the project,
# such as where data will be downloaded from.
# here is an example.
def write_default_config(path):
w = open(path, 'wt')
w.write('[data]\n')
w.write('url = https://www.dropbox.com/s/o0nxd8pnwy809u2/headlines.csv?dl=1\n')
w.write('file = %s%s%s\n' % (nlp_path, os.path.sep, 'headlines.csv'))
w.close()
# Find NLP_HOME path
if 'NLP_HOME' in os.environ:
nlp_path = os.environ['NLP_HOME']
else:
nlp_path = os.environ['HOME'] + os.path.sep + '.nlp' + os.path.sep
# Make nlp directory if not present
try:
os.makedirs(nlp_path)
except:
pass
# main config file.
config_path = nlp_path + 'nlp.cfg'
# classifier
clf_path = nlp_path + 'clf.pkl'
# write default config if not present.
if not os.path.isfile(config_path):
write_default_config(config_path)
# config variable now accessible throughout project.
config = configparser.RawConfigParser()
config.read(config_path)