예제 #1
0
파일: template.py 프로젝트: UFAL-DSG/alex
class TectoTemplateNLG(AbstractTemplateNLG):
    """\
    Template generation using tecto-trees and NLG rules.
    """

    def __init__(self, cfg):
        """\
        Initialization, checking configuration, loading
        templates and NLG rules.
        """
        super(TectoTemplateNLG, self).__init__(cfg)
        # check that the configuration contains everything we need
        if not 'NLG' in self.cfg or not 'TectoTemplate' in self.cfg['NLG']:
            raise TemplateNLGException('No configuration found!')
        mycfg = self.cfg['NLG']['TectoTemplate']
        if not 'model' in mycfg or not 'scenario' in mycfg or \
                not 'data_dir' in mycfg:
            raise TemplateNLGException('NLG scenario, data directory ' +
                                       'and templates must be defined!')
        # load templates
        self.load_templates(mycfg['model'])
        # load NLG system
        self.nlg_rules = Scenario(mycfg)
        self.nlg_rules.load_blocks()

    def fill_in_template(self, tpl, svs):
        """\
        Filling in tecto-templates, i.e. filling-in strings to templates
        and using rules to generate the result.
        """
        tpl = unicode(tpl)
        filled_tpl = tpl.format(**dict(svs))
        return self.nlg_rules.apply_to(filled_tpl)
예제 #2
0
class TectoTemplateNLG(AbstractTemplateNLG):
    """\
    Template generation using tecto-trees and NLG rules.
    """

    def __init__(self, cfg):
        """\
        Initialization, checking configuration, loading
        templates and NLG rules.
        """
        super(TectoTemplateNLG, self).__init__(cfg)
        # check that the configuration contains everything we need
        if not 'NLG' in self.cfg or not 'TectoTemplate' in self.cfg['NLG']:
            raise TemplateNLGException('No configuration found!')
        mycfg = self.cfg['NLG']['TectoTemplate']
        if not 'model' in mycfg or not 'scenario' in mycfg or \
                not 'data_dir' in mycfg:
            raise TemplateNLGException('NLG scenario, data directory ' +
                                       'and templates must be defined!')
        # load templates
        self.load_templates(mycfg['model'])
        # load NLG system
        self.nlg_rules = Scenario(mycfg)
        self.nlg_rules.load_blocks()

    def fill_in_template(self, tpl, svs):
        """\
        Filling in tecto-templates, i.e. filling-in strings to templates
        and using rules to generate the result.
        """
        tpl = unicode(tpl)
        filled_tpl = tpl.format(**dict(svs))
        return self.nlg_rules.apply_to(filled_tpl)
예제 #3
0
 def __init__(self, cfg):
     """\
     Initialization, checking configuration, loading
     templates and NLG rules.
     """
     super(TectoTemplateNLG, self).__init__(cfg)
     # check that the configuration contains everything we need
     if not 'NLG' in self.cfg or not 'TectoTemplate' in self.cfg['NLG']:
         raise TemplateNLGException('No configuration found!')
     mycfg = self.cfg['NLG']['TectoTemplate']
     if not 'model' in mycfg or not 'scenario' in mycfg or \
             not 'data_dir' in mycfg:
         raise TemplateNLGException('NLG scenario, data directory ' +
                                    'and templates must be defined!')
     # load templates
     self.load_templates(mycfg['model'])
     # load NLG system
     self.nlg_rules = Scenario(mycfg)
     self.nlg_rules.load_blocks()
예제 #4
0
파일: template.py 프로젝트: UFAL-DSG/alex
 def __init__(self, cfg):
     """\
     Initialization, checking configuration, loading
     templates and NLG rules.
     """
     super(TectoTemplateNLG, self).__init__(cfg)
     # check that the configuration contains everything we need
     if not 'NLG' in self.cfg or not 'TectoTemplate' in self.cfg['NLG']:
         raise TemplateNLGException('No configuration found!')
     mycfg = self.cfg['NLG']['TectoTemplate']
     if not 'model' in mycfg or not 'scenario' in mycfg or \
             not 'data_dir' in mycfg:
         raise TemplateNLGException('NLG scenario, data directory ' +
                                    'and templates must be defined!')
     # load templates
     self.load_templates(mycfg['model'])
     # load NLG system
     self.nlg_rules = Scenario(mycfg)
     self.nlg_rules.load_blocks()