-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconfig.py
121 lines (89 loc) · 2.68 KB
/
config.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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
import os
from pprint import pprint
class Config(object):
def __init__(self, root_dir='./'):
"""
Configuration.
:param str root_dir: Root directory.
"""
self.root_dir = root_dir
self.k = 2
self.emit_epoch = 5
self.trans_epoch = 5
self.null_mode = 'skip'
self.use_lemma = True
# The lowest word frequency
self.word_freq = 10
self.len_threshold = 5
self.train_method = 'ave'
self.inference_method = 'ave'
self.null_ratio = 0.4
self.slack = 0.0
self.optim_iter = 3
self.lower_ratio = 0.1
self.debug = False
self.use_pr_in_decode = True
self.no_num = False
self.jobs = 4
self.normalized = True
self.filter = None
self.no_delta_match = True
self.double_direction = True
self.init = 'uniform'
self.cont_feature = False
def cache(self, *paths):
"""
Return path of a file stored/to be stored in cache dir.
:param str paths: A possible series of folder names plus a filename (necessity).
:return str: Path.
"""
path = os.path.join(self.root_dir, 'stuff', 'cache', *paths)
if len(paths) > 1:
try:
os.makedirs(os.path.dirname(path))
except OSError:
# Its folder has already created
pass
return path
def data(self, filename):
"""
Return a file stored in data directory.
:param str filename: As its name.
:return str: Path.
"""
return os.path.join(self.root_dir, 'stuff', 'data', filename)
def annotate_file(self, filename):
"""
:param str filename:
:rtype: str
"""
return os.path.join(self.root_dir, 'annotate', 'cache', filename)
def __eq__(self, other):
"""
Whether two configurations same.
:param Config other:
:rtype: bool
"""
return other.__dict__ == self.__dict__
def file_name(self, *args):
"""
Generate file names according to the configuration.
:param str args: Configuration terms.
:rtype: str
"""
ret = list()
for arg in args[:-1]:
ret.append(str(getattr(self, arg)))
ret = '_'.join(ret)
ret += '.' + args[-1]
return ret
def print_info(self):
pprint(self.__dict__)
def copy_from(self, other):
"""
:param Config other:
:rtype: None
"""
for key in self.__dict__.keys():
setattr(self, key, getattr(other, key))
cfg = Config('./')