forked from snakeztc/SimDial
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathread_entity.py
53 lines (38 loc) · 1.2 KB
/
read_entity.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
#!/usr/bin/env python
import sys
import json
import pdb
if len(sys.argv) == 1:
sys.argv = ["", "1500_data_fixed/movie-MixSpec-15.json"]
def main():
file_path = sys.argv[1]
json_file = open(file_path)
dials = json.loads(json_file.read())
# entities = {}
# for dial in dials:
# # last_turn = dial['dial'][-1]
# for slu in dial['dial'][-1]['usr']['slu']:
# slot_name = slu['slots'][0][0]
# slot_value = slu['slots'][0][1]
# if slot_name in entities:
# entities[slot_name]['num'] += 1
# if slot_value in entities[slot_name]['val']:
# entities[slot_name]['val'][slot_value] += 1
# else:
# entities[slot_name]['val'][slot_value] = 1
# else:
# entities[slot_name]= {'num':1, 'val':{}}
# for name in entities:
# print(name, entities[name]['num'])
# for val in entities[name]['val']:
# print(' ', val, entities[name]['val'][val])
# # for name in entities:
# # for val in entities[name]['val']:
# # print(val, entities[name]['val'][val])
############# count how many turn in a conversation #################
turn_num = []
for dial in dials:
turn_num.append(dial['dial'][-1]['turn'])
print(turn_num, sum(turn_num[:9]))
if __name__ == "__main__":
main()