Example #1
0
def main(num_tasks):
    out = codecs.getwriter('utf-8')(sys.stdout)
    random.seed()
    nlg = TemplateNLG(cfg=CFG)
    for _ in xrange(num_tasks):
        task = generate_task()
        sents = [nlg.generate(da) for da in task]
        print >> out, '\t'.join([unicode(da) for da in task])
        sent_text = '\t'.join(sents)
        sent_text = sent_text.replace(' .', '.')
        sent_text = sent_text.replace(' ,', ',')
        print >> out, sent_text
        print >> out, ''
Example #2
0
def main(num_tasks):
    out = codecs.getwriter('utf-8')(sys.stdout)
    random.seed()
    nlg = TemplateNLG(cfg=CFG)
    for _ in xrange(num_tasks):
        task = generate_task()
        sents = [nlg.generate(da) for da in task]
        print >> out, '\t'.join([unicode(da) for da in task])
        sent_text = '\t'.join(sents)
        sent_text = sent_text.replace(' .', '.')
        sent_text = sent_text.replace(' ,', ',')
        print >> out, sent_text
        print >> out, ''
Example #3
0
    def test_template_nlg_r(self):

        cfg = self.cfg
        nlg = TemplateNLG(cfg)

        da = DialogueAct('affirm()&inform(from_stop=Sparta)').sort()
        correct_text = "Ano, jede to ze zastávky Sparta."
        generated_text = nlg.generate(da)

        s = []
        s.append("")
        s.append("Input DA:")
        s.append(unicode(da))
        s.append("")
        s.append("Correct text:")
        s.append(unicode(correct_text))
        s.append("")
        s.append("Generated text:")
        s.append(unicode(generated_text))
        s.append("")

        self.assertEqual(unicode(correct_text), unicode(generated_text))
Example #4
0
    def test_template_nlg(self):

        cfg = self.cfg
        nlg = TemplateNLG(cfg)

        da = DialogueAct('affirm()&inform(num_transfers="2")').sort()
        correct_text = u"Ano. Na dané trase jsou dva přestupy."
        generated_text = nlg.generate(da)

        s = []
        s.append("")
        s.append("Input DA:")
        s.append(unicode(da))
        s.append("")
        s.append("Correct text:")
        s.append(unicode(correct_text))
        s.append("")
        s.append("Generated text:")
        s.append(unicode(generated_text))
        s.append("")

        self.assertEqual(unicode(correct_text), unicode(generated_text))
Example #5
0
    def test_template_nlg_r(self):

        cfg = self.cfg
        nlg = TemplateNLG(cfg)

        da = DialogueAct("affirm()&inform(from_stop=Sparta)").sort()
        correct_text = "Ano, jede to ze zastávky Sparta."
        generated_text = nlg.generate(da)

        s = []
        s.append("")
        s.append("Input DA:")
        s.append(unicode(da))
        s.append("")
        s.append("Correct text:")
        s.append(unicode(correct_text))
        s.append("")
        s.append("Generated text:")
        s.append(unicode(generated_text))
        s.append("")

        self.assertEqual(unicode(correct_text), unicode(generated_text))
Example #6
0
    def test_template_nlg(self):

        cfg = self.cfg
        nlg = TemplateNLG(cfg)

        da = DialogueAct('affirm()&inform(num_transfers="2")').sort()
        correct_text = "Ano. Na dané trase jsou dva přestupy."
        generated_text = nlg.generate(da)

        s = []
        s.append("")
        s.append("Input DA:")
        s.append(unicode(da))
        s.append("")
        s.append("Correct text:")
        s.append(unicode(correct_text))
        s.append("")
        s.append("Generated text:")
        s.append(unicode(generated_text))
        s.append("")

        self.assertEqual(unicode(correct_text), unicode(generated_text))
Example #7
0
    def test_template_nlg_r(self):

        cfg = self.cfg
        nlg = TemplateNLG(cfg)

        da = DialogueAct('affirm()&inform(pricerange="cheap")&inform(task="find")').sort()
        correct_text = "Ok, you are looking for something in the cheap price range."
        generated_text = nlg.generate(da)

        s = []
        s.append("")
        s.append("Input DA:")
        s.append(unicode(da))
        s.append("")
        s.append("Correct text:")
        s.append(unicode(correct_text))
        s.append("")
        s.append("Generated text:")
        s.append(unicode(generated_text))
        s.append("")
        print '\n'.join(s)

        self.assertEqual(unicode(correct_text), unicode(generated_text))
Example #8
0
def nlg_factory(nlg_type, cfg):
    nlg = None

    # do not forget to maintain all supported dialogue managers
    if nlg_type == 'Template':
        nlg = TemplateNLG(cfg)
    elif nlg_type == 'TectoTemplate':
        nlg = TectoTemplateNLG(cfg)
    else:
        try:
            nlg = nlg_type(cfg)
        except NameError:
            raise TemplateNLGException('Unsupported NLG: %s' % nlg_type)

    return nlg