alex.components.nlg.tectotpl.core package¶
Submodules¶
alex.components.nlg.tectotpl.core.block module¶
- class alex.components.nlg.tectotpl.core.block.Block(scenario, args)[source]¶
Bases: object
A common ancestor to all Treex processing blocks.
- process_bundle(bundle)[source]¶
Process a bundle. Default behavior is to process the zone according to the current language and selector.
alex.components.nlg.tectotpl.core.document module¶
- class alex.components.nlg.tectotpl.core.document.Bundle(document, data=None, b_ord=None)[source]¶
Bases: object
Represents a bundle, i.e. a list of zones pertaining to the same sentence (in different variations).
- create_zone(language, selector)[source]¶
Creates a zone at the given language and selector. Will overwrite any existing zones.
- get_or_create_zone(language, selector)[source]¶
Returns the zone for a language and selector; if it does not exist, creates an empty zone.
- get_zone(language, selector)[source]¶
Returns the corresponding zone for a language and selector; raises an exception if the zone does not exist.
- class alex.components.nlg.tectotpl.core.document.Document(filename=None, data=None)[source]¶
Bases: object
This represents a Treex document, i.e. a sequence of bundles. It contains an index of node IDs.
- index_backref(attr_name, source_id, target_ids)[source]¶
Keep track of a backward reference (source, target node IDs are in the direction of the original reference)
- index_node(node)[source]¶
Index a node by its id. Also index the node’s references in the backwards reference index.
- class alex.components.nlg.tectotpl.core.document.Zone(data=None, language=None, selector=None, bundle=None)[source]¶
Bases: object
Represents a zone, i.e. a sentence and corresponding trees.
- create_tree(layer, data=None)[source]¶
Create a tree on the given layer, filling it with the given data (if applicable).
alex.components.nlg.tectotpl.core.exception module¶
- exception alex.components.nlg.tectotpl.core.exception.DataException(path)[source]¶
Bases: alex.components.nlg.tectotpl.core.exception.TreexException
Data file not found exception
- exception alex.components.nlg.tectotpl.core.exception.LoadingException(text)[source]¶
Bases: alex.components.nlg.tectotpl.core.exception.TreexException
Block loading exception
- exception alex.components.nlg.tectotpl.core.exception.RuntimeException(text)[source]¶
Bases: alex.components.nlg.tectotpl.core.exception.TreexException
Block runtime exception
- exception alex.components.nlg.tectotpl.core.exception.ScenarioException(text)[source]¶
Bases: alex.components.nlg.tectotpl.core.exception.TreexException
Scenario-related exception.
alex.components.nlg.tectotpl.core.log module¶
alex.components.nlg.tectotpl.core.node module¶
- class alex.components.nlg.tectotpl.core.node.A(data=None, parent=None, zone=None)[source]¶
Bases: alex.components.nlg.tectotpl.core.node.Node, alex.components.nlg.tectotpl.core.node.Ordered, alex.components.nlg.tectotpl.core.node.EffectiveRelations, alex.components.nlg.tectotpl.core.node.InClause
Representing an a-node
- attrib = [(u'form', <type 'unicode'>), (u'lemma', <type 'unicode'>), (u'tag', <type 'unicode'>), (u'afun', <type 'unicode'>), (u'no_space_after', <type 'bool'>), (u'morphcat', <type 'dict'>), (u'is_parenthesis_root', <type 'bool'>), (u'edge_to_collapse', <type 'bool'>), (u'is_auxiliary', <type 'bool'>), (u'p_terminal.rf', <type 'unicode'>)]¶
- morphcat_members = [u'pos', u'subpos', u'gender', u'number', u'case', u'person', u'tense', u'negation', u'voice', u'grade', u'mood', u'possnumber', u'possgender']¶
- ref_attrib = [u'p_terminal.rf']¶
- class alex.components.nlg.tectotpl.core.node.EffectiveRelations[source]¶
Bases: object
Representing a node with effective relations
- attrib = [(u'is_member', <type 'bool'>)]¶
- get_coap_members()[source]¶
Return the members of the coordination, if the node is a coap root. Otherwise return the node itself.
- get_echildren(or_topological=False, add_self=False, ordered=False, preceding_only=False, following_only=False)[source]¶
Return the effective children of the current node.
- get_eparents(or_topological=False, add_self=False, ordered=False, preceding_only=False, following_only=False)[source]¶
Return the effective parents of the current node.
- is_coap_root()[source]¶
Testing whether the node is a coordination/apposition root. Must be implemented in descendants.
- ref_attrib = []¶
- class alex.components.nlg.tectotpl.core.node.InClause[source]¶
Bases: object
Represents nodes that are organized in clauses
- attrib = [(u'clause_number', <type 'int'>), (u'is_clause_head', <type 'bool'>)]¶
- ref_attrib = []¶
- class alex.components.nlg.tectotpl.core.node.N(data=None, parent=None, zone=None)[source]¶
Bases: alex.components.nlg.tectotpl.core.node.Node
Representing an n-node
- attrib = [(u'ne_type', <type 'unicode'>), (u'normalized_name', <type 'unicode'>), (u'a.rf', <type 'list'>)]¶
- ref_attrib = [u'a.rf']¶
- class alex.components.nlg.tectotpl.core.node.Node(data=None, parent=None, zone=None)[source]¶
Bases: object
Representing a node in a tree (recursively)
- attrib = [(u'alignment', <type 'list'>), (u'wild', <type 'dict'>)]¶
- get_attr(name)[source]¶
Return the value of the given attribute. Allows for dictionary nesting, e.g. ‘morphcat/gender’
- get_attr_list(include_types=False, safe=False)[source]¶
Get attributes of the current class (gathering all attributes of base classes)
- get_children(add_self=False, ordered=False, preceding_only=False, following_only=False)[source]¶
Return all children of the node
- get_deref_attr(name)[source]¶
This assumes the given attribute holds node id(s) and returns the corresponding node(s)
- get_descendants(add_self=False, ordered=False, preceding_only=False, following_only=False)[source]¶
Return all topological descendants of this node.
- get_ref_attr_list(split_nested=False)[source]¶
Return a list of the attributes of the current class that contain references (splitting nested ones, if needed)
- get_referenced_ids()[source]¶
Return all ids referenced by this node, keyed under their reference types in a hash.
- ref_attrib = []¶
- remove_reference(ref_type, refd_id)[source]¶
Remove the reference of the given type to the given node.
- set_attr(name, value)[source]¶
Set the value of the given attribute. Allows for dictionary nesting, e.g. ‘morphcat/gender’
- class alex.components.nlg.tectotpl.core.node.Ordered[source]¶
Bases: object
Representing an ordered node (has an attribute called ord), defines sorting.
- attrib = [(u'ord', <type 'int'>)]¶
- is_first_node()[source]¶
Return True if this node is the first node in the tree, i.e. has no previous nodes.
- is_last_node()[source]¶
Return True if this node is the last node in the tree, i.e. has no following nodes.
- is_right_child[source]¶
Return True if this node has a greater ord than its parent. Returns None for a root.
- ref_attrib = []¶
- shift_after_node(other, without_children=False)[source]¶
Shift one node after another in the ordering.
- shift_after_subtree(other, without_children=False)[source]¶
Shift one node after the whole subtree of another node in the ordering.
- class alex.components.nlg.tectotpl.core.node.P(data=None, parent=None, zone=None)[source]¶
Bases: alex.components.nlg.tectotpl.core.node.Node
Representing a p-node
- attrib = [(u'is_head', <type 'bool'>), (u'index', <type 'unicode'>), (u'coindex', <type 'unicode'>), (u'edgelabel', <type 'unicode'>), (u'form', <type 'unicode'>), (u'lemma', <type 'unicode'>), (u'tag', <type 'unicode'>), (u'phrase', <type 'unicode'>), (u'functions', <type 'unicode'>)]¶
- ref_attrib = []¶
- class alex.components.nlg.tectotpl.core.node.T(data=None, parent=None, zone=None)[source]¶
Bases: alex.components.nlg.tectotpl.core.node.Node, alex.components.nlg.tectotpl.core.node.Ordered, alex.components.nlg.tectotpl.core.node.EffectiveRelations, alex.components.nlg.tectotpl.core.node.InClause
Representing a t-node
- attrib = [(u'functor', <type 'unicode'>), (u'formeme', <type 'unicode'>), (u't_lemma', <type 'unicode'>), (u'nodetype', <type 'unicode'>), (u'subfunctor', <type 'unicode'>), (u'tfa', <type 'unicode'>), (u'is_dsp_root', <type 'bool'>), (u'gram', <type 'dict'>), (u'a', <type 'dict'>), (u'compl.rf', <type 'list'>), (u'coref_gram.rf', <type 'list'>), (u'coref_text.rf', <type 'list'>), (u'sentmod', <type 'unicode'>), (u'is_parenthesis', <type 'bool'>), (u'is_passive', <type 'bool'>), (u'is_generated', <type 'bool'>), (u'is_relclause_head', <type 'bool'>), (u'is_name_of_person', <type 'bool'>), (u'voice', <type 'unicode'>), (u'mlayer_pos', <type 'unicode'>), (u't_lemma_origin', <type 'unicode'>), (u'formeme_origin', <type 'unicode'>), (u'is_infin', <type 'bool'>), (u'is_reflexive', <type 'bool'>)]¶
- ref_attrib = [u'a/lex.rf', u'a/aux.rf', u'compl.rf', u'coref_gram.rf', u'coref_text.rf']¶
alex.components.nlg.tectotpl.core.run module¶
- class alex.components.nlg.tectotpl.core.run.Scenario(config)[source]¶
Bases: object
This represents a scenario, i.e. a sequence of blocks to be run on the data
alex.components.nlg.tectotpl.core.util module¶
- alex.components.nlg.tectotpl.core.util.as_list(value)[source]¶
Cast anything to a list (just copy a list or a tuple, or put an atomic item to as a single element to a list).