Пример #1
0
    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()
Пример #2
0
    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()
Пример #3
0
    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)
Пример #4
0
    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)
Пример #5
0
    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))
Пример #6
0
    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))