forked from snakeztc/SimDial
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathcombine_domain.py
74 lines (56 loc) · 2.3 KB
/
combine_domain.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
64
65
66
67
68
69
70
71
72
73
74
#!/usr/bin/env python3
#
import sys, os
import pdb
import json
import argparse
def combine_log():
pass
def combine_db():
pass
def combine_otgy(source_domain, target_domain, datasize, data_path):
all_slots = {'informable':{}}
combined_otgy_name = []
# # # source domain
for dom in source_domain:
# pdb.set_trace()
with open(os.path.join(data_path, dom+'-MixSpec-1500-OTGY.json'), 'r', encoding='utf-8') as otgy:
slots = json.loads(otgy.read().lower())
for slot_type in slots['informable']:
# pdb.set_trace()
if slot_type in all_slots['informable']:
all_slots['informable'][slot_type] += slots['informable'][slot_type]
else:
all_slots['informable'][slot_type] = slots['informable'][slot_type]
combined_otgy_name.append(dom[0])
# # # target domain
if target_domain != '':
with open(os.path.join(data_path, target_domain+'-MixSpec-'+str(datasize)+'-OTGY.json'), 'r', encoding='utf-8') as otgy:
slots = json.loads(otgy.read().lower())
for slot_type in slots['informable']:
if slot_type in all_slots['informable']:
all_slots['informable'][slot_type] += slots['informable'][slot_type]
else:
all_slots['informable'][slot_type] = slots['informable'][slot_type]
combined_otgy_name.append(str(datasize) + target_domain[0])
combined_otgy_path = os.path.join(data_path, '_'.join(combined_otgy_name)+'-OTGY.json')
with open(combined_otgy_path, 'w') as co:
json.dump(all_slots, co, indent=2)
def main():
parser = argparse.ArgumentParser()
parser.add_argument('-log', default=True)
parser.add_argument('-db', default=True)
parser.add_argument('-otgy', default=True)
parser.add_argument('-source_domain', default=['restaurant', 'weather', 'bus'])
parser.add_argument('-target_domain', default='movie')
parser.add_argument('-data_path', default='./1500_data_fixed_0/')
parser.add_argument('-datasize', default=15)
args = parser.parse_args()
if args.log:
combine_log()
if args.db:
combine_db()
if args.otgy:
combine_otgy(args.source_domain, args.target_domain, args.datasize, args.data_path)
if __name__ == "__main__":
main()