alex.components.nlg package

Subpackages

Submodules

alex.components.nlg.autopath module

self cloning, automatic path configuration

copy this into any subdirectory of pypy from which scripts need to be run, typically all of the test subdirs. The idea is that any such script simply issues

import autopath

and this will make sure that the parent directory containing “pypy” is in sys.path.

If you modify the master “autopath.py” version (in pypy/tool/autopath.py) you can directly run it which will copy itself on all autopath.py files it finds under the pypy root directory.

This module always provides these attributes:

pypydir pypy root directory path this_dir directory where this autopath.py resides

alex.components.nlg.common module

alex.components.nlg.common.get_nlg_type(cfg)[source]
alex.components.nlg.common.nlg_factory(nlg_type, cfg)[source]

alex.components.nlg.exceptions module

exception alex.components.nlg.exceptions.NLGException[source]

Bases: alex.AlexException

exception alex.components.nlg.exceptions.TemplateNLGException[source]

Bases: alex.components.nlg.exceptions.NLGException

alex.components.nlg.template module

class alex.components.nlg.template.AbstractTemplateNLG(cfg)[source]

Bases: object

Base abstract class for template-filling generators, providing the routines for template loading and selection.

The generation (i.e. template filling) is left to the derived classes.

It implements numerous backoff strategies: 1) it matches the exactly the input dialogue against the templates 2) if it cannot find exact match, then it tries to find a generic template (slot-independent) 3) if it cannot find a generic template, the it tries to compose

the template from templates for individual dialogue act items
backoff(da)[source]

Provide an alternative NLG template for the dialogue output which is not covered in the templates. This serves as a backoff solution. This should be implemented in derived classes.

compose_utterance_greedy(da)[source]

Compose an utterance from templates by iteratively looking for the longest (up to self.compose_greedy_lookahead) matching sub-utterance at the current position in the DA.

Returns the composed utterance.

compose_utterance_single(da)[source]

Compose an utterance from templates for single dialogue act items. Returns the composed utterance.

fill_in_template(tpl, svs)[source]

Fill in the given slot values of a dialogue act into the given template. This should be implemented in derived classes.

generate(da)[source]

Generate the natural text output for the given dialogue act.

First, try to find an exact match with no variables to fill in. Then try to find a relaxed match of a more generic template and fill in the actual values of the variables.

get_generic_da(da)[source]

Given a dialogue act and a list of slots and values, substitute the generic values (starting with { and ending with }) with empty string.

get_generic_da_given_svs(da, svs)[source]

Given a dialogue act and a list of slots and values, substitute the matching slot and values with empty string.

load_templates(file_name)[source]

Load templates from an external file, which is assumed to be a Python source which defines the variable ‘templates’ as a dictionary containing stringified dialog acts as keys and (lists of) templates as values.

match_and_fill_generic(da, svs)[source]

Match a generic template and fill in the proper values for the slots which were substituted by a generic value.

Will return the output text with the proper values filled in if a generic template can be found; will throw a TemplateNLGException otherwise.

match_generic_templates(da, svs)[source]

Find a matching template for a dialogue act using substitutions for slot values.

Returns a matching template and a dialogue act where values of some of the slots are substituted with a generic value.

random_select(tpl)[source]

Randomly select alternative templates for generation.

The selection process is modeled by an embedded list structure (a tree-like structure). In the first level, the algorithm selects one of N. In the second level, for every item it selects one of M, and joins them together. This continues toward the leaves which must be non-list objects.

There are the following random selection options (only the first three):

  1. { ‘hello()’ : u”Hello”, }

    This will return the “Hello” string.

  2. { ‘hello()’ : (u”Hello”,

    u”Hi”,

    ),

    }

    This will return one of the “Hello” or “Hi” strings.

  1. { ‘hello()’ : (

    [
    (u”Hello.”,

    u”Hi.”,

    ) (u”How are you doing?”,

    u”Welcome”.,

    ), u”Speak!”,

    ],

    u”Hi my friend.”

    ),

    }

    This will return one of the following strings:

    “Hello. How are you doing? Speak!” “Hi. How are you doing? Speak!” “Hello. Welcome. Speak!” “Hi. Welcome. Speak!” “Hi my friend.”

class alex.components.nlg.template.TectoTemplateNLG(cfg)[source]

Bases: alex.components.nlg.template.AbstractTemplateNLG

Template generation using tecto-trees and NLG rules.

fill_in_template(tpl, svs)[source]

Filling in tecto-templates, i.e. filling-in strings to templates and using rules to generate the result.

class alex.components.nlg.template.TemplateNLG(cfg)[source]

Bases: alex.components.nlg.template.AbstractTemplateNLG

A simple text-replacement template NLG implementation with the ability to resort to a back-off system if no appropriate template is found.

fill_in_template(tpl, svs)[source]

Simple text replacement template filling.

Applies template NLG pre- and postprocessing, if applicable.

class alex.components.nlg.template.TemplateNLGPostprocessing[source]

Bases: object

Base class for template NLG postprocessing, handles postprocessing of the text resulting from filling in a template.

This base class provides no functionality, it just defines an interface for derived language-specific and/or domain-specific classes.

postprocess(nlg_text)[source]
class alex.components.nlg.template.TemplateNLGPreprocessing(ontology)[source]

Bases: object

Base class for template NLG preprocessing, handles preprocessing of the values to be filled into a template.

This base class provides no functionality, it just defines an interface for derived language-specific and/or domain-specific classes.

preprocess(svs_dict)[source]

alex.components.nlg.test_tectotpl module

class alex.components.nlg.test_tectotpl.TestTectoTemplateNLG(methodName='runTest')[source]

Bases: unittest.case.TestCase

test_tecto_template_nlg()[source]

alex.components.nlg.test_template module

class alex.components.nlg.test_template.TestTemplateNLG(methodName='runTest')[source]

Bases: unittest.case.TestCase

setUp()[source]
test_template_nlg()[source]
test_template_nlg_r()[source]

Module contents