def _infer_last_talked_about_slots(self, user_da, system_da): """This adds dialogue act items to support inference of the last slots the user talked about.""" old_user_da = deepcopy(user_da) new_user_da = DialogueActConfusionNetwork() colliding_slots = {} done_slots = set() for prob, user_dai in user_da: new_user_dais = [] lta_tsvs = self.ontology.last_talked_about(user_dai.dat, user_dai.name, user_dai.value) for name, value in lta_tsvs: new_user_dais.append(DialogueActItem("inform", name, value)) if name in done_slots: if not name in colliding_slots: colliding_slots[name] = set() colliding_slots[name].add(value) else: done_slots.add(name) if new_user_dais: for nudai in new_user_dais: if not nudai in new_user_da: new_user_da.add(prob, nudai) # In case of collisions, prefer the current last talked about values if it is one of the colliding values. # If there is a collision and the current last talked about value is not among the colliding values, do not # consider the colliding DA's at all. invalid_das = set() for prob, da in set(new_user_da): if da.name in colliding_slots and self[ da.name].mpv() in colliding_slots[da.name]: if not da.value == self[da.name].mpv(): invalid_das.add(da) elif da.name in colliding_slots: invalid_das.add(da) for invalid_da in invalid_das: new_user_da.remove(invalid_da) old_user_da.merge(new_user_da, combine='max') return old_user_da
def _infer_last_talked_about_slots(self, user_da, system_da): """This adds dialogue act items to support inference of the last slots the user talked about.""" old_user_da = deepcopy(user_da) new_user_da = DialogueActConfusionNetwork() colliding_slots = {} done_slots = set() for prob, user_dai in user_da: new_user_dais = [] lta_tsvs = self.ontology.last_talked_about(user_dai.dat, user_dai.name, user_dai.value) for name, value in lta_tsvs: new_user_dais.append(DialogueActItem("inform", name, value)) if name in done_slots: if not name in colliding_slots: colliding_slots[name] = set() colliding_slots[name].add(value) else: done_slots.add(name) if new_user_dais: for nudai in new_user_dais: if not nudai in new_user_da: new_user_da.add(prob, nudai) # In case of collisions, prefer the current last talked about values if it is one of the colliding values. # If there is a collision and the current last talked about value is not among the colliding values, do not # consider the colliding DA's at all. invalid_das = set() for prob, da in set(new_user_da): if da.name in colliding_slots and self[da.name].mpv() in colliding_slots[da.name]: if not da.value == self[da.name].mpv(): invalid_das.add(da) elif da.name in colliding_slots: invalid_das.add(da) for invalid_da in invalid_das: new_user_da.remove(invalid_da) old_user_da.merge(new_user_da, combine='max') return old_user_da