-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathluigi_tasks.py
152 lines (112 loc) · 4.05 KB
/
luigi_tasks.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
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
import luigi
import glob
import os
from tasks.parse_tasks import ParseTask, IdentifyTask
from tasks.text_tasks import TextPreprocessingTask
from tasks.eda_tasks import IdentityEDATask
from tasks.task_helpers import parse_yaml, extract_task_config
from tasks.task_helpers import run_init
class ParseWorkflow(luigi.Task):
doc_dir = luigi.Parameter()
yaml_file = luigi.Parameter()
def requires(self):
return [ParseTask(input_file=f, yaml_file=self.yaml_file) for f in self._iterator()]
def output(self):
return luigi.LocalTarget('log.txt')
def run(self):
self._configure()
print 'running'
def _configure(self):
config = parse_yaml(self.yaml_file)
run_init(config)
def _iterator(self):
for f in glob.glob(os.path.join(self.doc_dir, '*.json'))[0:2]:
yield f
class BowWorkflow(luigi.Task):
doc_dir = luigi.Parameter()
yaml_file = luigi.Parameter()
def requires(self):
return [ParseTask(input_path=f, yaml_file=self.yaml_file) for f in self._iterator()]
def output(self):
return luigi.LocalTarget('log.txt')
def run(self):
print 'running'
def _iterator(self):
for f in glob.glob(os.path.join(self.doc_dir, '*.json'))[0:10]:
yield f
class TripleWorkflow(luigi.Task):
'''
get, clean, identify, parse, detect language,
normalize keywords, generate triples, push to
triplestore
'''
yaml_file = luigi.Parameter()
doc_dir = luigi.Parameter()
def requires(self):
return [
TextPreprocessingTask(
input_file=f, yaml_file=self.yaml_file
) for f in self._iterator()
]
def output(self):
return luigi.LocalTarget('log.txt')
def run(self):
self._configure()
print 'running'
def _configure(self):
config = parse_yaml(self.yaml_file)
run_init(config)
def _iterator(self):
for f in glob.glob(os.path.join(self.doc_dir, '*.json'))[0:10]:
yield f
class IdentifyWorkflow(luigi.Task):
doc_dir = luigi.Parameter()
yaml_file = luigi.Parameter()
start_index = luigi.Parameter(default=0)
end_index = luigi.Parameter(default=1000)
def requires(self):
return [IdentifyTask(input_file=f, yaml_file=self.yaml_file) for f in self._iterator()]
def output(self):
return luigi.LocalTarget('log.txt')
def run(self):
self._configure()
print 'running'
def _configure(self):
config = parse_yaml(self.yaml_file)
run_init(config)
def _iterator(self):
for f in glob.glob(os.path.join(self.doc_dir, '*.json'))[self.start_index:self.end_index]:
yield f
class IdentifyEDAWorkflow(luigi.Task):
'''
'''
yaml_file = luigi.Parameter()
def requires(self):
return IdentityEDATask(yaml_file=self.yaml_file)
def output(self):
return luigi.LocalTarget('log.txt')
def run(self):
self._configure()
print 'running'
def _configure(self):
config = parse_yaml(self.yaml_file)
run_init(config)
if __name__ == '__main__':
# yaml_file = the configuration yaml for all tasks
# this is quite unfortunate
# w = ParseWorkflow(doc_dir='testdata/docs/', yaml_file='tasks/test_config.yaml')
# w = TripleWorkflow(doc_dir='testdata/docs/', yaml_file='tasks/test_config.yaml')
w = IdentifyEDAWorkflow(yaml_file='tasks/identity_eda.yaml')
luigi.build([w], local_scheduler=True)
# for i in xrange(200, 26000, 2000):
# w = IdentifyWorkflow(
# doc_dir='testdata/solr_20150320/docs/',
# yaml_file='tasks/identity_20150320.yaml',
# start_index=i,
# end_index=(i + 2000)
# )
# luigi.build([w], local_scheduler=True)
# for the response only: python luigi_tasks.py ResponseTask
# --input-path 'testdata/docs/response_0a80f182ed59a834572e2c594aacfe29.json'
# --output-path 'testdata/luigi/0a80f182ed59a834572e2c594aacfe29_response.json'
# --local-scheduler