aboutsummaryrefslogtreecommitdiff
path: root/scripts
diff options
context:
space:
mode:
authorRncLsn <rnc.lsn@gmail.com>2015-05-20 18:52:47 +0100
committerRncLsn <rnc.lsn@gmail.com>2015-05-20 18:52:47 +0100
commitd81b086fe329fa69891eba0a4b1f73e44183620d (patch)
tree7c55c80678660cdbd3dae18e94c4baf5b0680e11 /scripts
parent7a68441a541b12b22587fb53072193e1130049ff (diff)
downloadACQuA-d81b086fe329fa69891eba0a4b1f73e44183620d.tar.gz
ACQuA-d81b086fe329fa69891eba0a4b1f73e44183620d.zip
Added more tests.
Querying of the upper bound is currently unstable.
Diffstat (limited to 'scripts')
-rw-r--r--scripts/PagodaOutputJsonConverter.py57
1 files changed, 57 insertions, 0 deletions
diff --git a/scripts/PagodaOutputJsonConverter.py b/scripts/PagodaOutputJsonConverter.py
new file mode 100644
index 0000000..65c6df2
--- /dev/null
+++ b/scripts/PagodaOutputJsonConverter.py
@@ -0,0 +1,57 @@
1import sys
2import re
3import json
4
5
6queryID_regex = '^\s*-+\s*[qQ]uery\s*(\d+)\s*-+\s*$'
7
8
9def main(args):
10 records = []
11
12 query_found = text_found = variables_found = answers_found = False
13 cur_record = {}
14 answers = []
15 with open(args[0], 'r') as input_file:
16 for line in input_file:
17 if not query_found:
18 match = re.search(queryID_regex, line)
19 if not match:
20 continue
21 query_found = True
22 # print 'query found'
23 cur_record['queryID'] = int(match.group(1))
24 continue
25 if not text_found:
26 # print 'text found'
27 cur_record['queryText'] = line.strip()
28 text_found = True
29 continue
30 if not variables_found:
31 # print 'vars found'
32 cur_record['answerVariables'] = line.strip().split()
33 variables_found = True
34 continue
35 if not answers_found:
36 # print 'answers found'
37 answers_found = True
38 continue
39
40 if len(line.strip()) > 0:
41 answers.append(line.strip())
42 else:
43 cur_record['answers'] = answers
44 records.append(cur_record)
45 print '\rParsed ' + str(len(records)) + ' query records',
46
47 query_found = text_found = variables_found = answers_found = False
48 cur_record = {}
49 answers = []
50 print
51
52 with open(args[1], 'w') as output_file:
53 output_file.write(json.dumps(records, indent=2))
54
55
56if __name__ == '__main__':
57 main(sys.argv[1:]) \ No newline at end of file