From d81b086fe329fa69891eba0a4b1f73e44183620d Mon Sep 17 00:00:00 2001 From: RncLsn Date: Wed, 20 May 2015 18:52:47 +0100 Subject: Added more tests. Querying of the upper bound is currently unstable. --- scripts/PagodaOutputJsonConverter.py | 57 ++++++++++++++++++++++++++++++++++++ 1 file changed, 57 insertions(+) create mode 100644 scripts/PagodaOutputJsonConverter.py (limited to 'scripts') 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 @@ +import sys +import re +import json + + +queryID_regex = '^\s*-+\s*[qQ]uery\s*(\d+)\s*-+\s*$' + + +def main(args): + records = [] + + query_found = text_found = variables_found = answers_found = False + cur_record = {} + answers = [] + with open(args[0], 'r') as input_file: + for line in input_file: + if not query_found: + match = re.search(queryID_regex, line) + if not match: + continue + query_found = True + # print 'query found' + cur_record['queryID'] = int(match.group(1)) + continue + if not text_found: + # print 'text found' + cur_record['queryText'] = line.strip() + text_found = True + continue + if not variables_found: + # print 'vars found' + cur_record['answerVariables'] = line.strip().split() + variables_found = True + continue + if not answers_found: + # print 'answers found' + answers_found = True + continue + + if len(line.strip()) > 0: + answers.append(line.strip()) + else: + cur_record['answers'] = answers + records.append(cur_record) + print '\rParsed ' + str(len(records)) + ' query records', + + query_found = text_found = variables_found = answers_found = False + cur_record = {} + answers = [] + print + + with open(args[1], 'w') as output_file: + output_file.write(json.dumps(records, indent=2)) + + +if __name__ == '__main__': + main(sys.argv[1:]) \ No newline at end of file -- cgit v1.2.3