import json | |
def load_line_json_data(filename): | |
data = [] | |
with open(filename, 'r', encoding='utf-8') as f: | |
for line in f.read().strip().split('\n'): | |
unit = json.loads(line) | |
data.append(unit) | |
return data | |
def save_file(data, path): | |
with open(path,'w',encoding='utf-8') as w: | |
for unit in data: | |
output = json.dumps(unit) | |
w.write(output + "\n") | |
w.close() | |
data = load_line_json_data('/home/xj/toolAugEnv/code/toolConstraint/data/query/zk.jsonl') | |
query_output = open('/home/xj/toolAugEnv/code/toolConstraint/data/api_request/zk_hard_regen.txt','r').read().strip().split('\n') | |
# assert len(data) == len(query_output) | |
for unit, output in zip(data[24:], query_output): | |
# unit['local_constraint']['transportation'] = None | |
unit['query'] = " ".join(x for x in output.split('\t')[1:]) | |
# for unit in data: | |
# unit['local_constraint']['transportation'] = None | |
save_file(data,'/home/xj/toolAugEnv/code/toolConstraint/data/query/zk.jsonl') |