alex.components.nlg package¶
Subpackages¶
- alex.components.nlg.tectotpl package
- Subpackages
- alex.components.nlg.tectotpl.block package
- Subpackages
- alex.components.nlg.tectotpl.block.a2w package
- alex.components.nlg.tectotpl.block.read package
- alex.components.nlg.tectotpl.block.t2a package
- Subpackages
- alex.components.nlg.tectotpl.block.t2a.cs package
- Submodules
- alex.components.nlg.tectotpl.block.t2a.cs.addappositionpunct module
- alex.components.nlg.tectotpl.block.t2a.cs.addauxverbcompoundfuture module
- alex.components.nlg.tectotpl.block.t2a.cs.addauxverbcompoundpassive module
- alex.components.nlg.tectotpl.block.t2a.cs.addauxverbcompoundpast module
- alex.components.nlg.tectotpl.block.t2a.cs.addauxverbconditional module
- alex.components.nlg.tectotpl.block.t2a.cs.addauxverbmodal module
- alex.components.nlg.tectotpl.block.t2a.cs.addclausalexpletives module
- alex.components.nlg.tectotpl.block.t2a.cs.addclausalpunct module
- alex.components.nlg.tectotpl.block.t2a.cs.addcoordpunct module
- alex.components.nlg.tectotpl.block.t2a.cs.addparentheses module
- alex.components.nlg.tectotpl.block.t2a.cs.addprepositions module
- alex.components.nlg.tectotpl.block.t2a.cs.addreflexiveparticles module
- alex.components.nlg.tectotpl.block.t2a.cs.addsentfinalpunct module
- alex.components.nlg.tectotpl.block.t2a.cs.addsubconjs module
- alex.components.nlg.tectotpl.block.t2a.cs.addsubordclausepunct module
- alex.components.nlg.tectotpl.block.t2a.cs.capitalizesentstart module
- alex.components.nlg.tectotpl.block.t2a.cs.deletesuperfluousauxs module
- alex.components.nlg.tectotpl.block.t2a.cs.dropsubjpersprons module
- alex.components.nlg.tectotpl.block.t2a.cs.generatepossessiveadjectives module
- alex.components.nlg.tectotpl.block.t2a.cs.generatewordforms module
- alex.components.nlg.tectotpl.block.t2a.cs.imposeattragr module
- alex.components.nlg.tectotpl.block.t2a.cs.imposecomplagr module
- alex.components.nlg.tectotpl.block.t2a.cs.imposepronzagr module
- alex.components.nlg.tectotpl.block.t2a.cs.imposerelpronagr module
- alex.components.nlg.tectotpl.block.t2a.cs.imposesubjpredagr module
- alex.components.nlg.tectotpl.block.t2a.cs.initmorphcat module
- alex.components.nlg.tectotpl.block.t2a.cs.marksubject module
- alex.components.nlg.tectotpl.block.t2a.cs.markverbalcategories module
- alex.components.nlg.tectotpl.block.t2a.cs.movecliticstowackernagel module
- alex.components.nlg.tectotpl.block.t2a.cs.projectclausenumber module
- alex.components.nlg.tectotpl.block.t2a.cs.reversenumbernoundependency module
- alex.components.nlg.tectotpl.block.t2a.cs.vocalizeprepos module
- Module contents
- alex.components.nlg.tectotpl.block.t2a.cs package
- Submodules
- alex.components.nlg.tectotpl.block.t2a.addauxwords module
- alex.components.nlg.tectotpl.block.t2a.copyttree module
- alex.components.nlg.tectotpl.block.t2a.imposeagreement module
- Module contents
- Subpackages
- alex.components.nlg.tectotpl.block.t2t package
- alex.components.nlg.tectotpl.block.util package
- alex.components.nlg.tectotpl.block.write package
- Module contents
- Subpackages
- alex.components.nlg.tectotpl.core package
- Submodules
- alex.components.nlg.tectotpl.core.block module
- alex.components.nlg.tectotpl.core.document module
- alex.components.nlg.tectotpl.core.exception module
- alex.components.nlg.tectotpl.core.log module
- alex.components.nlg.tectotpl.core.node module
- alex.components.nlg.tectotpl.core.run module
- alex.components.nlg.tectotpl.core.util module
- Module contents
- alex.components.nlg.tectotpl.tool package
- alex.components.nlg.tectotpl.block package
- Module contents
- Subpackages
- alex.components.nlg.tools package
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.exceptions module¶
-
exception
alex.components.nlg.exceptions.
NLGException
[source]¶ Bases:
alex.AlexException
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):
{ ‘hello()’ : u”Hello”, }
This will return the “Hello” string.
{ ‘hello()’ : (u”Hello”,
u”Hi”,
),
}
This will return one of the “Hello” or “Hi” strings.
{ ‘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.
-
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.
-
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.
-
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.