From b82732eae951b3dc957136f40b992a1904c9cbe5 Mon Sep 17 00:00:00 2001 From: zhuqi <zqwerty@users.noreply.github.com> Date: Wed, 2 Sep 2020 15:45:16 +0800 Subject: [PATCH] Add police n hospital (#95) * add back police and hospital goal * update police db:add postcode; update hospital db:add address and postcode; update dbquery: query hospital with department, deepcopy query result --- convlab2/task/multiwoz/goal_generator.py | 24 +-- convlab2/util/multiwoz/dbquery.py | 19 +- data/multiwoz/db/hospital_db.json | 264 +++++++++++++++++------ data/multiwoz/db/police_db.json | 3 +- 4 files changed, 224 insertions(+), 86 deletions(-) diff --git a/convlab2/task/multiwoz/goal_generator.py b/convlab2/task/multiwoz/goal_generator.py index e543818..cdf378b 100755 --- a/convlab2/task/multiwoz/goal_generator.py +++ b/convlab2/task/multiwoz/goal_generator.py @@ -135,14 +135,14 @@ class GoalGenerator: """User goal generator.""" def __init__(self, - goal_model_path=os.path.join(get_root_path(), 'data/multiwoz/goal/new_goal_model_no_police_hospital.pkl'), + goal_model_path=os.path.join(get_root_path(), 'data/multiwoz/goal/new_goal_model.pkl'), corpus_path=None, boldify=False, sample_info_from_trainset=True, sample_reqt_from_trainset=False): """ Args: - goal_model_path: path to a goal model + goal_model_path: path to a goal model corpus_path: path to a dialog corpus to build a goal model boldify: highlight some information in the goal message sample_info_from_trainset: if True, sample info slots combination from train set, else sample each slot independently @@ -163,13 +163,13 @@ class GoalGenerator: self._build_goal_model() print('Building goal model is done') - # remove some slot (now no police and hospital domains) - # del self.ind_slot_dist['police']['reqt']['postcode'] - # del self.ind_slot_value_dist['police']['reqt']['postcode'] - # del self.ind_slot_dist['hospital']['reqt']['postcode'] - # del self.ind_slot_value_dist['hospital']['reqt']['postcode'] - # del self.ind_slot_dist['hospital']['reqt']['address'] - # del self.ind_slot_value_dist['hospital']['reqt']['address'] + # remove some slot + del self.ind_slot_dist['police']['reqt']['postcode'] + del self.ind_slot_value_dist['police']['reqt']['postcode'] + del self.ind_slot_dist['hospital']['reqt']['postcode'] + del self.ind_slot_value_dist['hospital']['reqt']['postcode'] + del self.ind_slot_dist['hospital']['reqt']['address'] + del self.ind_slot_value_dist['hospital']['reqt']['address'] # print(self.slots_combination_dist['police']) # print(self.slots_combination_dist['hospital']) @@ -187,8 +187,6 @@ class GoalGenerator: domain_orderings = [] for d in dialogs: d_domains = _get_dialog_domains(dialogs[d]) - if 'police' in d_domains or 'hospital' in d_domains: - continue first_index = [] for domain in d_domains: message = [dialogs[d]['goal']['message']] if type(dialogs[d]['goal']['message']) == str else \ @@ -211,9 +209,6 @@ class GoalGenerator: self.slots_num_dist = {domain: {} for domain in domains} for d in dialogs: - d_domains = _get_dialog_domains(dialogs[d]) - if 'police' in d_domains or 'hospital' in d_domains: - continue for domain in domains: if dialogs[d]['goal'][domain] != {}: domain_cnt[domain] += 1 @@ -740,5 +735,4 @@ class GoalGenerator: if __name__ == '__main__': goal_generator = GoalGenerator(corpus_path=os.path.join(get_root_path(), 'data/multiwoz/train.json'), sample_reqt_from_trainset=True) - # goal_generator._build_goal_model() pprint(goal_generator.get_user_goal()) diff --git a/convlab2/util/multiwoz/dbquery.py b/convlab2/util/multiwoz/dbquery.py index c3a5c2f..b84bf8a 100755 --- a/convlab2/util/multiwoz/dbquery.py +++ b/convlab2/util/multiwoz/dbquery.py @@ -3,6 +3,7 @@ import json import os import random +from copy import deepcopy class Database(object): @@ -26,9 +27,16 @@ class Database(object): 'taxi_types': random.choice(self.dbs[domain]['taxi_types']), 'taxi_phone': ''.join([str(random.randint(1, 9)) for _ in range(11)])}] if domain == 'police': - return self.dbs['police'] + return deepcopy(self.dbs['police']) if domain == 'hospital': - return self.dbs['hospital'] + department = None + for key, val in constraints: + if key == 'department': + department = val + if not department: + return deepcopy(self.dbs['hospital']) + else: + return [deepcopy(x) for x in self.dbs['hospital'] if x['department'].lower() == department.strip().lower()] for ele in constraints: if ele[0] == 'area' and ele[1] == 'center': ele[1] = 'centre' @@ -62,10 +70,13 @@ class Database(object): except: continue else: - record['Ref'] = '{0:08d}'.format(i) - found.append(record) + res = deepcopy(record) + res['Ref'] = '{0:08d}'.format(i) + found.append(res) return found + + if __name__ == '__main__': db = Database() print(db.query("train", [['departure', 'cambridge'], ['destination','peterborough'], ['day', 'tuesday'], ['arriveBy', '11:15']])) diff --git a/data/multiwoz/db/hospital_db.json b/data/multiwoz/db/hospital_db.json index 82fe62e..f8873e3 100755 --- a/data/multiwoz/db/hospital_db.json +++ b/data/multiwoz/db/hospital_db.json @@ -2,331 +2,463 @@ { "department": "neurosciences critical care unit", "id": 0, - "phone": "01223216297" + "phone": "01223216297", + "address": "hills rd , cambridge", + "postcode": "cb20qq" }, { "department": "trauma high dependency unit", "id": 1, - "phone": "01223216305" + "phone": "01223216305", + "address": "hills rd , cambridge", + "postcode": "cb20qq" }, { "department": "neurology neurosurgery", "id": 2, - "phone": "01223217216" + "phone": "01223217216", + "address": "hills rd , cambridge", + "postcode": "cb20qq" }, { "department": "oncology neurosurgery", "id": 3, - "phone": "01223216314" + "phone": "01223216314", + "address": "hills rd , cambridge", + "postcode": "cb20qq" }, { "department": "children's oncology and haematology", "id": 4, - "phone": "01223217231" + "phone": "01223217231", + "address": "hills rd , cambridge", + "postcode": "cb20qq" }, { "department": "children's surgical and medicine", "id": 5, - "phone": "01223217450" + "phone": "01223217450", + "address": "hills rd , cambridge", + "postcode": "cb20qq" }, { "department": "acute medicine for the elderly", "id": 6, - "phone": "01223217261" + "phone": "01223217261", + "address": "hills rd , cambridge", + "postcode": "cb20qq" }, { "department": "general medicine and nephrology", "id": 7, - "phone": "01223217195" + "phone": "01223217195", + "address": "hills rd , cambridge", + "postcode": "cb20qq" }, { "department": "medicine for the elderly", "id": 8, - "phone": "01223216988" + "phone": "01223216988", + "address": "hills rd , cambridge", + "postcode": "cb20qq" }, { "department": "hepatobillary and gastrointestinal surgery regional referral centre", "id": 9, - "phone": "01223217300" + "phone": "01223217300", + "address": "hills rd , cambridge", + "postcode": "cb20qq" }, { "department": "trauma and orthopaedics", "id": 10, - "phone": "01223217279" + "phone": "01223217279", + "address": "hills rd , cambridge", + "postcode": "cb20qq" }, { "department": "teenage cancer trust unit", "id": 11, - "phone": "01223274222" + "phone": "01223274222", + "address": "hills rd , cambridge", + "postcode": "cb20qq" }, { "department": "haematology and haematological oncology", "id": 12, - "phone": "01223217312" + "phone": "01223217312", + "address": "hills rd , cambridge", + "postcode": "cb20qq" }, { "department": "children's surgical and medicine", "id": 13, - "phone": "01223217250" + "phone": "01223217250", + "address": "hills rd , cambridge", + "postcode": "cb20qq" }, { "department": "intermediate dependancy area", "id": 14, - "phone": "01223348144" + "phone": "01223348144", + "address": "hills rd , cambridge", + "postcode": "cb20qq" }, { "department": "hepatology", "id": 15, - "phone": "01223217712" + "phone": "01223217712", + "address": "hills rd , cambridge", + "postcode": "cb20qq" }, { "department": "haematology", "id": 16, - "phone": "01223274679" + "phone": "01223274679", + "address": "hills rd , cambridge", + "postcode": "cb20qq" }, { "department": "neurology", "id": 17, - "phone": "01223274680" + "phone": "01223274680", + "address": "hills rd , cambridge", + "postcode": "cb20qq" }, { "department": "surgery", "id": 18, - "phone": "01223217303" + "phone": "01223217303", + "address": "hills rd , cambridge", + "postcode": "cb20qq" }, { "department": "trauma and orthopaedics", "id": 19, - "phone": "01223217282" + "phone": "01223217282", + "address": "hills rd , cambridge", + "postcode": "cb20qq" }, { "department": "oncology", "id": 20, - "phone": "01223217708" + "phone": "01223217708", + "address": "hills rd , cambridge", + "postcode": "cb20qq" }, { "department": "infectious diseases", "id": 21, - "phone": "01223217314" + "phone": "01223217314", + "address": "hills rd , cambridge", + "postcode": "cb20qq" }, { "department": "haematology day unit", "id": 22, - "phone": "01223348169" + "phone": "01223348169", + "address": "hills rd , cambridge", + "postcode": "cb20qq" }, { "department": "clinical decisions unit", "id": 23, - "phone": "01223596203" + "phone": "01223596203", + "address": "hills rd , cambridge", + "postcode": "cb20qq" }, { "department": "acute medical assessment unit", "id": 24, - "phone": "01223348314" + "phone": "01223348314", + "address": "hills rd , cambridge", + "postcode": "cb20qq" }, { "department": "medical short stay unit", "id": 25, - "phone": "01223348336" + "phone": "01223348336", + "address": "hills rd , cambridge", + "postcode": "cb20qq" }, { "department": "inpatient occupational therapy", "id": 26, - "phone": "01223216881" + "phone": "01223216881", + "address": "hills rd , cambridge", + "postcode": "cb20qq" }, { "department": "paediatric day unit", "id": 27, - "phone": "01223217567" + "phone": "01223217567", + "address": "hills rd , cambridge", + "postcode": "cb20qq" }, { "department": "paediatric clinic", "id": 28, - "phone": "01223348313" + "phone": "01223348313", + "address": "hills rd , cambridge", + "postcode": "cb20qq" }, { "department": "medicine for the elderly", "id": 29, - "phone": "01223274744" + "phone": "01223274744", + "address": "hills rd , cambridge", + "postcode": "cb20qq" }, { "department": "transplant high dependency unit", "id": 30, - "phone": "01223216811" + "phone": "01223216811", + "address": "hills rd , cambridge", + "postcode": "cb20qq" }, { "department": "diabetes and endocrinology", "id": 31, - "phone": "01223217323" + "phone": "01223217323", + "address": "hills rd , cambridge", + "postcode": "cb20qq" }, { "department": "infusion services", "id": 32, - "phone": "01223586967" + "phone": "01223586967", + "address": "hills rd , cambridge", + "postcode": "cb20qq" }, { "department": "medicine for the elderly", "id": 33, - "phone": "01223217484" + "phone": "01223217484", + "address": "hills rd , cambridge", + "postcode": "cb20qq" }, { "department": "medicine for the elderly", "id": 34, - "phone": "01223217498" + "phone": "01223217498", + "address": "hills rd , cambridge", + "postcode": "cb20qq" }, { "department": "transplant unit", "id": 35, - "phone": "01223217711" + "phone": "01223217711", + "address": "hills rd , cambridge", + "postcode": "cb20qq" }, { "department": "medicine for the elderly", "id": 36, - "phone": "01223217428" + "phone": "01223217428", + "address": "hills rd , cambridge", + "postcode": "cb20qq" }, { "department": "theatre admissions unit", "id": 37, - "phone": "01223256583" + "phone": "01223256583", + "address": "hills rd , cambridge", + "postcode": "cb20qq" }, { "department": "cardiology", "id": 38, - "phone": "01223256233" + "phone": "01223256233", + "address": "hills rd , cambridge", + "postcode": "cb20qq" }, { "department": "major trauma unit", "id": 39, - "phone": "01223349881" + "phone": "01223349881", + "address": "hills rd , cambridge", + "postcode": "cb20qq" }, { "department": "cardiology and coronary care unit", "id": 40, - "phone": "01223256459" + "phone": "01223256459", + "address": "hills rd , cambridge", + "postcode": "cb20qq" }, { "department": "colorectal surgery", "id": 41, - "phone": "01223348545" + "phone": "01223348545", + "address": "hills rd , cambridge", + "postcode": "cb20qq" }, { "department": "plastic and vascular surgery plastics", "id": 42, - "phone": "01223274280" + "phone": "01223274280", + "address": "hills rd , cambridge", + "postcode": "cb20qq" }, { "department": "gastroenterology", "id": 43, - "phone": "01223274284" + "phone": "01223274284", + "address": "hills rd , cambridge", + "postcode": "cb20qq" }, { "department": "oral and maxillofacial surgery and ent", "id": 44, - "phone": "01223348527" + "phone": "01223348527", + "address": "hills rd , cambridge", + "postcode": "cb20qq" }, { "department": "urology", "id": 45, - "phone": "01223256650" + "phone": "01223256650", + "address": "hills rd , cambridge", + "postcode": "cb20qq" }, { "department": "respiratory medicine", "id": 46, - "phone": "01223256645" + "phone": "01223256645", + "address": "hills rd , cambridge", + "postcode": "cb20qq" }, { "department": "lewin stroke and rehabilitation unit", "id": 47, - "phone": "01223274750" + "phone": "01223274750", + "address": "hills rd , cambridge", + "postcode": "cb20qq" }, { "department": "neurosciences", "id": 48, - "phone": "01223216348" + "phone": "01223216348", + "address": "hills rd , cambridge", + "postcode": "cb20qq" }, { "department": "psychiatry", "id": 49, - "phone": "01223596201" + "phone": "01223596201", + "address": "hills rd , cambridge", + "postcode": "cb20qq" }, { "department": "emergency department", "id": 50, - "phone": "01223217118" + "phone": "01223217118", + "address": "hills rd , cambridge", + "postcode": "cb20qq" }, { "department": "cambridge eye unit", "id": 51, - "phone": "01223257168" + "phone": "01223257168", + "address": "hills rd , cambridge", + "postcode": "cb20qq" }, { "department": "clinical investigation ward", "id": 52, - "phone": "01223586706" + "phone": "01223586706", + "address": "hills rd , cambridge", + "postcode": "cb20qq" }, { "department": "clinical research facility", "id": 53, - "phone": "01223596055" + "phone": "01223596055", + "address": "hills rd , cambridge", + "postcode": "cb20qq" }, { "department": "coronary care unit", "id": 54, - "phone": "01223217297" + "phone": "01223217297", + "address": "hills rd , cambridge", + "postcode": "cb20qq" }, { "department": "intermediate dependency area", "id": 55, - "phone": "01223217873" + "phone": "01223217873", + "address": "hills rd , cambridge", + "postcode": "cb20qq" }, { "department": "medical decisions unit", "id": 56, - "phone": "01223596066" + "phone": "01223596066", + "address": "hills rd , cambridge", + "postcode": "cb20qq" }, { "department": "paediatric intensive care unit", "id": 57, - "phone": "01223217715" + "phone": "01223217715", + "address": "hills rd , cambridge", + "postcode": "cb20qq" }, { "department": "paediatric day unit", "id": 58, - "phone": "01223257157" + "phone": "01223257157", + "address": "hills rd , cambridge", + "postcode": "cb20qq" }, { "department": "john farman intensive care unit", "id": 59, - "phone": "01223256166" + "phone": "01223256166", + "address": "hills rd , cambridge", + "postcode": "cb20qq" }, { "department": "delivery unit", "id": 60, - "phone": "01223217217" + "phone": "01223217217", + "address": "hills rd , cambridge", + "postcode": "cb20qq" }, { "department": "postnatal", "id": 61, - "phone": "01223217667" + "phone": "01223217667", + "address": "hills rd , cambridge", + "postcode": "cb20qq" }, { "department": "neonatal unit", "id": 62, - "phone": "01223217678" + "phone": "01223217678", + "address": "hills rd , cambridge", + "postcode": "cb20qq" }, { "department": "antenatal", "id": 63, - "phone": "01223217671" + "phone": "01223217671", + "address": "hills rd , cambridge", + "postcode": "cb20qq" }, { "department": "transitional care", "id": 64, - "phone": "01223254668" + "phone": "01223254668", + "address": "hills rd , cambridge", + "postcode": "cb20qq" }, { "department": "gynaecology", "id": 65, - "phone": "01223257206" + "phone": "01223257206", + "address": "hills rd , cambridge", + "postcode": "cb20qq" } ] diff --git a/data/multiwoz/db/police_db.json b/data/multiwoz/db/police_db.json index dbe208f..e040cec 100755 --- a/data/multiwoz/db/police_db.json +++ b/data/multiwoz/db/police_db.json @@ -3,6 +3,7 @@ "name": "Parkside Police Station", "address": "Parkside, Cambridge", "id": 0, - "phone": "01223358966" + "phone": "01223358966", + "postcode": "cb11jg" } ] -- GitLab