-
Notifications
You must be signed in to change notification settings - Fork 0
/
Fugue.py
129 lines (111 loc) · 4.08 KB
/
Fugue.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
122
123
124
125
126
127
128
129
import argparse
import sys
import subprocess
class ProfileParam(object):
def __init__(self):
self._inputFile = 'input.db'
self._modelFile = 'model.db'
self._task = 'train'
self._topics = 100
self._iters = 1000
self._topk = 100000
self._LDASampler = 'binary'
self._random = 'deterministic'
self._exp = 0
self._log = 0
self._saveModel = 1
self._multipleModels = 0
self._start = 0
self._end = -1
def getParams(self):
return_args = []
for key, value in self.__dict__.iteritems():
paramName = key.replace('_', '-')
return_args.append(paramName)
return_args.append(str(value))
return return_args
class ProfileAPTest(ProfileParam, object):
def __init__(self):
super(ProfileAPTest, self).__init__()
self._inputFile = 'examples/data/ap.json'
self._modelFile = 'examples/models/model.ap-200.json'
self._LDASampler = 'binary'
self._random = 'deterministic'
self._task = 'test'
self._multipleModels = 1
self._start = 1909
self._end = -1
class ProfileAPTrain(ProfileParam, object):
def __init__(self):
super(ProfileAPTrain, self).__init__()
self._inputFile = 'examples/data/ap.json'
self._modelFile = 'examples/models/model.ap.json'
self._LDASampler = 'binary'
self._LDAHyperOpt = 'none'
self._random = 'deterministic'
self._task = 'train'
self._start = 0
self._end = 1909
class ProfileAPTrainHyper(ProfileAPTrain, object):
def __init__(self):
super(ProfileAPTrainHyper, self).__init__()
self._modelFile = 'examples/models/model.ap-slice.json'
self._LDAHyperOpt = 'slice'
class cmdBuilder(object):
def __init__(self, profile):
self._profile = profile
self._other_params = []
@classmethod
def execute(cls, all_args):
fugue = subprocess.Popen(all_args, stdout = subprocess.PIPE, stderr = subprocess.STDOUT)
while True:
nextline = fugue.stdout.readline()
line = nextline.decode('ascii').rstrip()
if line == '' and fugue.poll() is not None:
break
sys.stdout.write(line+'\n')
sys.stdout.flush()
output = fugue.communicate()[0]
exit_code = fugue.returncode
if (exit_code == 0):
return output
return
def run(self):
self._other_params.append('java')
self._other_params.append('-Xmx8192m')
self._other_params.append('-jar')
self._other_params.append('build/libs/fugue-topicmodeling-all-0.1.jar')
all_args = self._other_params
all_args.extend(self._profile.getParams())
cmdStr = ' '.join(all_args)
print(cmdStr)
cmdBuilder.execute(all_args)
class cmdCompile(cmdBuilder, object):
def __init__(self):
return
def run(self):
build_cmd = []
build_cmd.append('gradle')
build_cmd.append('build')
print('==================== Build ===================')
cmdBuilder.execute(build_cmd)
build_cmd = []
build_cmd.append('gradle')
build_cmd.append('fatJar')
print('==================== Jar ===================')
cmdBuilder.execute(build_cmd)
if __name__ == '__main__':
parser = argparse.ArgumentParser(description='The Fugue Topic Modeling Package')
parser.add_argument('--profile', help='the profile to launch', default='ProfileAPTrain')
parser.add_argument('--task', help='the task to perform', default='build')
args = parser.parse_args()
get_class = lambda x: globals()[x]
if args.task is not None and args.task != '':
if args.task == 'train' or args.task == 'test':
if args.profile is not None and args.profile != '':
print(args.profile)
runProfile = get_class(args.profile)()
command = cmdBuilder(runProfile)
elif args.task == 'build':
command = cmdCompile()
command.run()