Exemplo n.º 1
0
class TemplatingPlugin(IPlugin):
    
    def __init__(self):
        self.phrase_banks = PhraseBankParser()
        self.templates = TemplateCollector()
    
    def start_up(self, ctx):
        # parser has a read method that takes a single filename or list of filenames.
        ctx.er.phrase_banks.track(self.phrase_banks.register_file)
        ctx.er.template_files.track(self.templates.register_file)
        # we should tell the personalities to reset themselves.
        ctx.er.template_files.track(self.reset_base_templates)
        
        ctx.er.template_files.add(self, "ui/templates/utility.txt")
        ctx.er.phrase_banks.add(self, "ui/templates/zander_empty.txt")
        
        ctx.er.parser_filters.add(PersonalitySetter())
        ctx.er.parser_actions.add(TemplatingAction(self.phrase_banks))

    def reset_base_templates(self, *args, **kw):
        self.phrase_banks.set_base_template(self.templates.get_template())
Exemplo n.º 2
0
    def testParser(self):
        print """Testing the loading of new phrases via the config parser"""
        fn_values = ['a', 'b', 'c', 'd', 'e', 'f', 'g']
        agent = 'Alice'
        k = 'chars'

        p = PhraseBankParser()
        
        p.add_section(agent)
        for v in fn_values:
            p.set(agent, k, v)

        phrase_book = p.get_phrasebank(agent)

        out = map(lambda n:phrase_book.render(defName=k), range(0,100))
        out = "".join(out)
        
        
        print "out is", out
        for c in fn_values:
            if c not in out:
                print "%s not in out" % (c)
            self.assertTrue(c in out)
Exemplo n.º 3
0
 def __init__(self):
     self.phrase_banks = PhraseBankParser()
     self.templates = TemplateCollector()