File size: 1,023 Bytes
9be4956
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
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')