Skip to content
Snippets Groups Projects
Unverified Commit b82732ea authored by zhuqi's avatar zhuqi Committed by GitHub
Browse files

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
parent db9ddd46
No related branches found
No related tags found
No related merge requests found
...@@ -135,7 +135,7 @@ class GoalGenerator: ...@@ -135,7 +135,7 @@ class GoalGenerator:
"""User goal generator.""" """User goal generator."""
def __init__(self, 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, corpus_path=None,
boldify=False, boldify=False,
sample_info_from_trainset=True, sample_info_from_trainset=True,
...@@ -163,13 +163,13 @@ class GoalGenerator: ...@@ -163,13 +163,13 @@ class GoalGenerator:
self._build_goal_model() self._build_goal_model()
print('Building goal model is done') print('Building goal model is done')
# remove some slot (now no police and hospital domains) # remove some slot
# del self.ind_slot_dist['police']['reqt']['postcode'] del self.ind_slot_dist['police']['reqt']['postcode']
# del self.ind_slot_value_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_dist['hospital']['reqt']['postcode']
# del self.ind_slot_value_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_dist['hospital']['reqt']['address']
# del self.ind_slot_value_dist['hospital']['reqt']['address'] del self.ind_slot_value_dist['hospital']['reqt']['address']
# print(self.slots_combination_dist['police']) # print(self.slots_combination_dist['police'])
# print(self.slots_combination_dist['hospital']) # print(self.slots_combination_dist['hospital'])
...@@ -187,8 +187,6 @@ class GoalGenerator: ...@@ -187,8 +187,6 @@ class GoalGenerator:
domain_orderings = [] domain_orderings = []
for d in dialogs: for d in dialogs:
d_domains = _get_dialog_domains(dialogs[d]) d_domains = _get_dialog_domains(dialogs[d])
if 'police' in d_domains or 'hospital' in d_domains:
continue
first_index = [] first_index = []
for domain in d_domains: for domain in d_domains:
message = [dialogs[d]['goal']['message']] if type(dialogs[d]['goal']['message']) == str else \ message = [dialogs[d]['goal']['message']] if type(dialogs[d]['goal']['message']) == str else \
...@@ -211,9 +209,6 @@ class GoalGenerator: ...@@ -211,9 +209,6 @@ class GoalGenerator:
self.slots_num_dist = {domain: {} for domain in domains} self.slots_num_dist = {domain: {} for domain in domains}
for d in dialogs: 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: for domain in domains:
if dialogs[d]['goal'][domain] != {}: if dialogs[d]['goal'][domain] != {}:
domain_cnt[domain] += 1 domain_cnt[domain] += 1
...@@ -740,5 +735,4 @@ class GoalGenerator: ...@@ -740,5 +735,4 @@ class GoalGenerator:
if __name__ == '__main__': 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 = 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()) pprint(goal_generator.get_user_goal())
...@@ -3,6 +3,7 @@ ...@@ -3,6 +3,7 @@
import json import json
import os import os
import random import random
from copy import deepcopy
class Database(object): class Database(object):
...@@ -26,9 +27,16 @@ class Database(object): ...@@ -26,9 +27,16 @@ class Database(object):
'taxi_types': random.choice(self.dbs[domain]['taxi_types']), 'taxi_types': random.choice(self.dbs[domain]['taxi_types']),
'taxi_phone': ''.join([str(random.randint(1, 9)) for _ in range(11)])}] 'taxi_phone': ''.join([str(random.randint(1, 9)) for _ in range(11)])}]
if domain == 'police': if domain == 'police':
return self.dbs['police'] return deepcopy(self.dbs['police'])
if domain == 'hospital': 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: for ele in constraints:
if ele[0] == 'area' and ele[1] == 'center': if ele[0] == 'area' and ele[1] == 'center':
ele[1] = 'centre' ele[1] = 'centre'
...@@ -62,10 +70,13 @@ class Database(object): ...@@ -62,10 +70,13 @@ class Database(object):
except: except:
continue continue
else: else:
record['Ref'] = '{0:08d}'.format(i) res = deepcopy(record)
found.append(record) res['Ref'] = '{0:08d}'.format(i)
found.append(res)
return found return found
if __name__ == '__main__': if __name__ == '__main__':
db = Database() db = Database()
print(db.query("train", [['departure', 'cambridge'], ['destination','peterborough'], ['day', 'tuesday'], ['arriveBy', '11:15']])) print(db.query("train", [['departure', 'cambridge'], ['destination','peterborough'], ['day', 'tuesday'], ['arriveBy', '11:15']]))
...@@ -2,331 +2,463 @@ ...@@ -2,331 +2,463 @@
{ {
"department": "neurosciences critical care unit", "department": "neurosciences critical care unit",
"id": 0, "id": 0,
"phone": "01223216297" "phone": "01223216297",
"address": "hills rd , cambridge",
"postcode": "cb20qq"
}, },
{ {
"department": "trauma high dependency unit", "department": "trauma high dependency unit",
"id": 1, "id": 1,
"phone": "01223216305" "phone": "01223216305",
"address": "hills rd , cambridge",
"postcode": "cb20qq"
}, },
{ {
"department": "neurology neurosurgery", "department": "neurology neurosurgery",
"id": 2, "id": 2,
"phone": "01223217216" "phone": "01223217216",
"address": "hills rd , cambridge",
"postcode": "cb20qq"
}, },
{ {
"department": "oncology neurosurgery", "department": "oncology neurosurgery",
"id": 3, "id": 3,
"phone": "01223216314" "phone": "01223216314",
"address": "hills rd , cambridge",
"postcode": "cb20qq"
}, },
{ {
"department": "children's oncology and haematology", "department": "children's oncology and haematology",
"id": 4, "id": 4,
"phone": "01223217231" "phone": "01223217231",
"address": "hills rd , cambridge",
"postcode": "cb20qq"
}, },
{ {
"department": "children's surgical and medicine", "department": "children's surgical and medicine",
"id": 5, "id": 5,
"phone": "01223217450" "phone": "01223217450",
"address": "hills rd , cambridge",
"postcode": "cb20qq"
}, },
{ {
"department": "acute medicine for the elderly", "department": "acute medicine for the elderly",
"id": 6, "id": 6,
"phone": "01223217261" "phone": "01223217261",
"address": "hills rd , cambridge",
"postcode": "cb20qq"
}, },
{ {
"department": "general medicine and nephrology", "department": "general medicine and nephrology",
"id": 7, "id": 7,
"phone": "01223217195" "phone": "01223217195",
"address": "hills rd , cambridge",
"postcode": "cb20qq"
}, },
{ {
"department": "medicine for the elderly", "department": "medicine for the elderly",
"id": 8, "id": 8,
"phone": "01223216988" "phone": "01223216988",
"address": "hills rd , cambridge",
"postcode": "cb20qq"
}, },
{ {
"department": "hepatobillary and gastrointestinal surgery regional referral centre", "department": "hepatobillary and gastrointestinal surgery regional referral centre",
"id": 9, "id": 9,
"phone": "01223217300" "phone": "01223217300",
"address": "hills rd , cambridge",
"postcode": "cb20qq"
}, },
{ {
"department": "trauma and orthopaedics", "department": "trauma and orthopaedics",
"id": 10, "id": 10,
"phone": "01223217279" "phone": "01223217279",
"address": "hills rd , cambridge",
"postcode": "cb20qq"
}, },
{ {
"department": "teenage cancer trust unit", "department": "teenage cancer trust unit",
"id": 11, "id": 11,
"phone": "01223274222" "phone": "01223274222",
"address": "hills rd , cambridge",
"postcode": "cb20qq"
}, },
{ {
"department": "haematology and haematological oncology", "department": "haematology and haematological oncology",
"id": 12, "id": 12,
"phone": "01223217312" "phone": "01223217312",
"address": "hills rd , cambridge",
"postcode": "cb20qq"
}, },
{ {
"department": "children's surgical and medicine", "department": "children's surgical and medicine",
"id": 13, "id": 13,
"phone": "01223217250" "phone": "01223217250",
"address": "hills rd , cambridge",
"postcode": "cb20qq"
}, },
{ {
"department": "intermediate dependancy area", "department": "intermediate dependancy area",
"id": 14, "id": 14,
"phone": "01223348144" "phone": "01223348144",
"address": "hills rd , cambridge",
"postcode": "cb20qq"
}, },
{ {
"department": "hepatology", "department": "hepatology",
"id": 15, "id": 15,
"phone": "01223217712" "phone": "01223217712",
"address": "hills rd , cambridge",
"postcode": "cb20qq"
}, },
{ {
"department": "haematology", "department": "haematology",
"id": 16, "id": 16,
"phone": "01223274679" "phone": "01223274679",
"address": "hills rd , cambridge",
"postcode": "cb20qq"
}, },
{ {
"department": "neurology", "department": "neurology",
"id": 17, "id": 17,
"phone": "01223274680" "phone": "01223274680",
"address": "hills rd , cambridge",
"postcode": "cb20qq"
}, },
{ {
"department": "surgery", "department": "surgery",
"id": 18, "id": 18,
"phone": "01223217303" "phone": "01223217303",
"address": "hills rd , cambridge",
"postcode": "cb20qq"
}, },
{ {
"department": "trauma and orthopaedics", "department": "trauma and orthopaedics",
"id": 19, "id": 19,
"phone": "01223217282" "phone": "01223217282",
"address": "hills rd , cambridge",
"postcode": "cb20qq"
}, },
{ {
"department": "oncology", "department": "oncology",
"id": 20, "id": 20,
"phone": "01223217708" "phone": "01223217708",
"address": "hills rd , cambridge",
"postcode": "cb20qq"
}, },
{ {
"department": "infectious diseases", "department": "infectious diseases",
"id": 21, "id": 21,
"phone": "01223217314" "phone": "01223217314",
"address": "hills rd , cambridge",
"postcode": "cb20qq"
}, },
{ {
"department": "haematology day unit", "department": "haematology day unit",
"id": 22, "id": 22,
"phone": "01223348169" "phone": "01223348169",
"address": "hills rd , cambridge",
"postcode": "cb20qq"
}, },
{ {
"department": "clinical decisions unit", "department": "clinical decisions unit",
"id": 23, "id": 23,
"phone": "01223596203" "phone": "01223596203",
"address": "hills rd , cambridge",
"postcode": "cb20qq"
}, },
{ {
"department": "acute medical assessment unit", "department": "acute medical assessment unit",
"id": 24, "id": 24,
"phone": "01223348314" "phone": "01223348314",
"address": "hills rd , cambridge",
"postcode": "cb20qq"
}, },
{ {
"department": "medical short stay unit", "department": "medical short stay unit",
"id": 25, "id": 25,
"phone": "01223348336" "phone": "01223348336",
"address": "hills rd , cambridge",
"postcode": "cb20qq"
}, },
{ {
"department": "inpatient occupational therapy", "department": "inpatient occupational therapy",
"id": 26, "id": 26,
"phone": "01223216881" "phone": "01223216881",
"address": "hills rd , cambridge",
"postcode": "cb20qq"
}, },
{ {
"department": "paediatric day unit", "department": "paediatric day unit",
"id": 27, "id": 27,
"phone": "01223217567" "phone": "01223217567",
"address": "hills rd , cambridge",
"postcode": "cb20qq"
}, },
{ {
"department": "paediatric clinic", "department": "paediatric clinic",
"id": 28, "id": 28,
"phone": "01223348313" "phone": "01223348313",
"address": "hills rd , cambridge",
"postcode": "cb20qq"
}, },
{ {
"department": "medicine for the elderly", "department": "medicine for the elderly",
"id": 29, "id": 29,
"phone": "01223274744" "phone": "01223274744",
"address": "hills rd , cambridge",
"postcode": "cb20qq"
}, },
{ {
"department": "transplant high dependency unit", "department": "transplant high dependency unit",
"id": 30, "id": 30,
"phone": "01223216811" "phone": "01223216811",
"address": "hills rd , cambridge",
"postcode": "cb20qq"
}, },
{ {
"department": "diabetes and endocrinology", "department": "diabetes and endocrinology",
"id": 31, "id": 31,
"phone": "01223217323" "phone": "01223217323",
"address": "hills rd , cambridge",
"postcode": "cb20qq"
}, },
{ {
"department": "infusion services", "department": "infusion services",
"id": 32, "id": 32,
"phone": "01223586967" "phone": "01223586967",
"address": "hills rd , cambridge",
"postcode": "cb20qq"
}, },
{ {
"department": "medicine for the elderly", "department": "medicine for the elderly",
"id": 33, "id": 33,
"phone": "01223217484" "phone": "01223217484",
"address": "hills rd , cambridge",
"postcode": "cb20qq"
}, },
{ {
"department": "medicine for the elderly", "department": "medicine for the elderly",
"id": 34, "id": 34,
"phone": "01223217498" "phone": "01223217498",
"address": "hills rd , cambridge",
"postcode": "cb20qq"
}, },
{ {
"department": "transplant unit", "department": "transplant unit",
"id": 35, "id": 35,
"phone": "01223217711" "phone": "01223217711",
"address": "hills rd , cambridge",
"postcode": "cb20qq"
}, },
{ {
"department": "medicine for the elderly", "department": "medicine for the elderly",
"id": 36, "id": 36,
"phone": "01223217428" "phone": "01223217428",
"address": "hills rd , cambridge",
"postcode": "cb20qq"
}, },
{ {
"department": "theatre admissions unit", "department": "theatre admissions unit",
"id": 37, "id": 37,
"phone": "01223256583" "phone": "01223256583",
"address": "hills rd , cambridge",
"postcode": "cb20qq"
}, },
{ {
"department": "cardiology", "department": "cardiology",
"id": 38, "id": 38,
"phone": "01223256233" "phone": "01223256233",
"address": "hills rd , cambridge",
"postcode": "cb20qq"
}, },
{ {
"department": "major trauma unit", "department": "major trauma unit",
"id": 39, "id": 39,
"phone": "01223349881" "phone": "01223349881",
"address": "hills rd , cambridge",
"postcode": "cb20qq"
}, },
{ {
"department": "cardiology and coronary care unit", "department": "cardiology and coronary care unit",
"id": 40, "id": 40,
"phone": "01223256459" "phone": "01223256459",
"address": "hills rd , cambridge",
"postcode": "cb20qq"
}, },
{ {
"department": "colorectal surgery", "department": "colorectal surgery",
"id": 41, "id": 41,
"phone": "01223348545" "phone": "01223348545",
"address": "hills rd , cambridge",
"postcode": "cb20qq"
}, },
{ {
"department": "plastic and vascular surgery plastics", "department": "plastic and vascular surgery plastics",
"id": 42, "id": 42,
"phone": "01223274280" "phone": "01223274280",
"address": "hills rd , cambridge",
"postcode": "cb20qq"
}, },
{ {
"department": "gastroenterology", "department": "gastroenterology",
"id": 43, "id": 43,
"phone": "01223274284" "phone": "01223274284",
"address": "hills rd , cambridge",
"postcode": "cb20qq"
}, },
{ {
"department": "oral and maxillofacial surgery and ent", "department": "oral and maxillofacial surgery and ent",
"id": 44, "id": 44,
"phone": "01223348527" "phone": "01223348527",
"address": "hills rd , cambridge",
"postcode": "cb20qq"
}, },
{ {
"department": "urology", "department": "urology",
"id": 45, "id": 45,
"phone": "01223256650" "phone": "01223256650",
"address": "hills rd , cambridge",
"postcode": "cb20qq"
}, },
{ {
"department": "respiratory medicine", "department": "respiratory medicine",
"id": 46, "id": 46,
"phone": "01223256645" "phone": "01223256645",
"address": "hills rd , cambridge",
"postcode": "cb20qq"
}, },
{ {
"department": "lewin stroke and rehabilitation unit", "department": "lewin stroke and rehabilitation unit",
"id": 47, "id": 47,
"phone": "01223274750" "phone": "01223274750",
"address": "hills rd , cambridge",
"postcode": "cb20qq"
}, },
{ {
"department": "neurosciences", "department": "neurosciences",
"id": 48, "id": 48,
"phone": "01223216348" "phone": "01223216348",
"address": "hills rd , cambridge",
"postcode": "cb20qq"
}, },
{ {
"department": "psychiatry", "department": "psychiatry",
"id": 49, "id": 49,
"phone": "01223596201" "phone": "01223596201",
"address": "hills rd , cambridge",
"postcode": "cb20qq"
}, },
{ {
"department": "emergency department", "department": "emergency department",
"id": 50, "id": 50,
"phone": "01223217118" "phone": "01223217118",
"address": "hills rd , cambridge",
"postcode": "cb20qq"
}, },
{ {
"department": "cambridge eye unit", "department": "cambridge eye unit",
"id": 51, "id": 51,
"phone": "01223257168" "phone": "01223257168",
"address": "hills rd , cambridge",
"postcode": "cb20qq"
}, },
{ {
"department": "clinical investigation ward", "department": "clinical investigation ward",
"id": 52, "id": 52,
"phone": "01223586706" "phone": "01223586706",
"address": "hills rd , cambridge",
"postcode": "cb20qq"
}, },
{ {
"department": "clinical research facility", "department": "clinical research facility",
"id": 53, "id": 53,
"phone": "01223596055" "phone": "01223596055",
"address": "hills rd , cambridge",
"postcode": "cb20qq"
}, },
{ {
"department": "coronary care unit", "department": "coronary care unit",
"id": 54, "id": 54,
"phone": "01223217297" "phone": "01223217297",
"address": "hills rd , cambridge",
"postcode": "cb20qq"
}, },
{ {
"department": "intermediate dependency area", "department": "intermediate dependency area",
"id": 55, "id": 55,
"phone": "01223217873" "phone": "01223217873",
"address": "hills rd , cambridge",
"postcode": "cb20qq"
}, },
{ {
"department": "medical decisions unit", "department": "medical decisions unit",
"id": 56, "id": 56,
"phone": "01223596066" "phone": "01223596066",
"address": "hills rd , cambridge",
"postcode": "cb20qq"
}, },
{ {
"department": "paediatric intensive care unit", "department": "paediatric intensive care unit",
"id": 57, "id": 57,
"phone": "01223217715" "phone": "01223217715",
"address": "hills rd , cambridge",
"postcode": "cb20qq"
}, },
{ {
"department": "paediatric day unit", "department": "paediatric day unit",
"id": 58, "id": 58,
"phone": "01223257157" "phone": "01223257157",
"address": "hills rd , cambridge",
"postcode": "cb20qq"
}, },
{ {
"department": "john farman intensive care unit", "department": "john farman intensive care unit",
"id": 59, "id": 59,
"phone": "01223256166" "phone": "01223256166",
"address": "hills rd , cambridge",
"postcode": "cb20qq"
}, },
{ {
"department": "delivery unit", "department": "delivery unit",
"id": 60, "id": 60,
"phone": "01223217217" "phone": "01223217217",
"address": "hills rd , cambridge",
"postcode": "cb20qq"
}, },
{ {
"department": "postnatal", "department": "postnatal",
"id": 61, "id": 61,
"phone": "01223217667" "phone": "01223217667",
"address": "hills rd , cambridge",
"postcode": "cb20qq"
}, },
{ {
"department": "neonatal unit", "department": "neonatal unit",
"id": 62, "id": 62,
"phone": "01223217678" "phone": "01223217678",
"address": "hills rd , cambridge",
"postcode": "cb20qq"
}, },
{ {
"department": "antenatal", "department": "antenatal",
"id": 63, "id": 63,
"phone": "01223217671" "phone": "01223217671",
"address": "hills rd , cambridge",
"postcode": "cb20qq"
}, },
{ {
"department": "transitional care", "department": "transitional care",
"id": 64, "id": 64,
"phone": "01223254668" "phone": "01223254668",
"address": "hills rd , cambridge",
"postcode": "cb20qq"
}, },
{ {
"department": "gynaecology", "department": "gynaecology",
"id": 65, "id": 65,
"phone": "01223257206" "phone": "01223257206",
"address": "hills rd , cambridge",
"postcode": "cb20qq"
} }
] ]
...@@ -3,6 +3,7 @@ ...@@ -3,6 +3,7 @@
"name": "Parkside Police Station", "name": "Parkside Police Station",
"address": "Parkside, Cambridge", "address": "Parkside, Cambridge",
"id": 0, "id": 0,
"phone": "01223358966" "phone": "01223358966",
"postcode": "cb11jg"
} }
] ]
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment