def input_da_nblist(self): """Reads an N-best list of dialogue acts from the input. :rtype : confusion network """ self.init_readline() nblist = DialogueActNBList() i = 1 while i < 100: l = raw_input("User DA %d: " % i).decode('utf8') if len(l) == 1 and l.startswith("."): print break try: prob, da = self.parse_input_da(l) except SemHubException as e: print e continue nblist.add(prob, da) i += 1 nblist.merge() nblist.scale() return nblist.get_confnet()
def main(): import autopath cfg = Config.load_configs(['resources/default-lz.cfg'], use_default=False, project_root=True) #cfg = {'DM': {'UfalRuleDM': # {'ontology':"/xdisk/devel/vystadial/alex/applications/" + \ # "CamInfoRest/ontology.cfg", # 'db_cfg': "/xdisk/devel/vystadial/alex/applications/" + \ # "CamInfoRest/cued_data/CIRdbase_V7_noloc.txt"}}} u = UfalRuleDM(cfg) # ufal_ds = u.create_ds() while 1: curr_acts = DialogueActNBList() for ln in sys.stdin: if len(ln.strip()) == 0: break ln = ln.strip() print ln score, act = ln.split(" ", 1) score = float(score) curr_acts.add(score, DialogueActItem(dai=act)) u.da_in(curr_acts) print " >", u.da_out()
def filter(self, in_da): """Go through the input dialogue acts and pick only the ones that we can understand and that have good enough confidence.""" new_nblist = DialogueActNBList() # for each dialogue act item check if it is of known type # and if it has good probability for item in in_da: da = item[1] new_da = DialogueAct() for dai in da: if dai.dat in ["inform", "request"]: if dai.value is not None and not dai.value in self.policy.values: continue if dai.dat in ["inform", "request", "confirm"]: if not dai.name in self.policy.slots: continue # check if the value is in our ontology #if type(dai.value) is str and \ # self.ontology_unknown_re.match(dai.value): # continue if dai.dat in ["inform", "request", "other", "confirm", "reqalts", "bye", "restart"]: new_da.append(dai) if item[0] >= 0.3: # do not consider things bellow 0.3 if len(new_da) > 0: new_nblist.add(item[0], new_da) return new_nblist
def test_merge_slu_nblists_full_nbest_lists(self): # make sure the alex.components.slu.da.merge_slu_nblists merges nblists correctly nblist1 = DialogueActNBList() nblist1.add(0.7, DialogueAct("hello()")) nblist1.add(0.2, DialogueAct("bye()")) nblist1.merge().normalise() # nblist1.normalise() nblist2 = DialogueActNBList() nblist2.add(0.6, DialogueAct("hello()")) nblist2.add(0.3, DialogueAct("restart()")) nblist2.merge().normalise() # nblist2.normalise() nblists = [[0.7, nblist1], [0.3, nblist2]] merged_nblists = merge_slu_nblists(nblists) correct_merged_nblists = DialogueActNBList() correct_merged_nblists.add(0.7 * 0.7, DialogueAct("hello()")) correct_merged_nblists.add(0.7 * 0.2, DialogueAct("bye()")) correct_merged_nblists.add(0.7 * 0.1, DialogueAct("other()")) correct_merged_nblists.add(0.3 * 0.6, DialogueAct("hello()")) correct_merged_nblists.add(0.3 * 0.3, DialogueAct("restart()")) correct_merged_nblists.add(0.3 * 0.1, DialogueAct("other()")) correct_merged_nblists.merge().normalise() # correct_merged_nblists.normalise() s = [] s.append("") s.append("Merged nblists:") s.append(unicode(merged_nblists)) s.append("") s.append("Correct merged results:") s.append(unicode(correct_merged_nblists)) s.append("") print '\n'.join(s) self.assertEqual(unicode(merged_nblists), unicode(correct_merged_nblists))
def test_swapping_merge_normalise(self): nblist1 = DialogueActNBList() nblist1.add(0.7, DialogueAct("hello()")) nblist1.add(0.2, DialogueAct("bye()")) nblist2 = deepcopy(nblist1) nblist1.merge().normalise() nblist2.normalise().merge() s = [] s.append("") s.append("Using merge().normalise():") s.append(unicode(nblist1)) s.append("") s.append("Using normalise().merge():") s.append(unicode(nblist2)) s.append("") self.assertEqual(nblist1, nblist2)