-
Notifications
You must be signed in to change notification settings - Fork 3
/
random_split_hits.py
64 lines (47 loc) · 1.82 KB
/
random_split_hits.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
import sys
import argparse
import re
import pymongo
from numpy import array, random
import utils
def main():
parser = argparse.ArgumentParser(description = 'Randomly split HIT results for analyzing consistency.')
parser.add_argument('-f', action = 'append', help = 'The mtk data source files.')
parser.add_argument('-m', action = 'append', help = 'The MTurk HIT result files.')
parser.add_argument('-o', help = 'The output file of used data.')
parser.add_argument('-s', help = 'The summary output file.')
parser.add_argument('-t', help = 'The data type.')
args = parser.parse_args()
(data_sources, hits, head_of_hits) = read_data(args)
def read_data(args):
data_sources = []
if (args.f != None):
if not isinstance(args.f, basestring):
parts = []
for afile in args.f:
part_of_data = utils.load_file(afile)
parts.append(part_of_data.tolist())
parts = [item for sublist in parts for item in sublist]
data_sources = array(parts)
else:
data_sources = utils.load_file(args.f)
hits = []
head_of_hits = ''
if (args.m != None):
if not isinstance(args.f, basestring):
parts = []
for afile in args.m:
part_of_data = utils.load_file(afile)
if head_of_hits == '':
head_of_hits = part_of_data[0]
part_of_data = part_of_data[1:len(part_of_data)]
parts.append(part_of_data.tolist())
parts = [item for sublist in parts for item in sublist]
hits = array(parts)
else:
hits = utils.load_file(args.m)
hits = hits[0]
hits = hits[1:len(hits)]
return (data_sources, hits, head_of_hits)
if __name__ == "__main__":
main()