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:
objectA 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:
objectRepresents 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.
-
document¶ The document this bundle belongs to.
-
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.
-
has_zone(language, selector)[source]¶ Returns True if the bundle has a zone for the given language and selector.
-
ord¶ The order of this bundle in the document, as given by constructor
-
-
class
alex.components.nlg.tectotpl.core.document.Document(filename=None, data=None)[source]¶ Bases:
objectThis 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:
objectRepresents a zone, i.e. a sentence and corresponding trees.
-
atree¶ Direct access to a-tree (will raise an exception if the tree does not exist).
-
bundle¶ The bundle in which this zone is located
-
create_tree(layer, data=None)[source]¶ Create a tree on the given layer, filling it with the given data (if applicable).
-
document¶ The document in which this zone is located
-
get_tree(layer)[source]¶ Return a tree this node has on the given layer or raise an exception if the tree does not exist.
-
language_and_selector¶ Return string concatenation of the zone’s language and selector.
-
ntree¶ Direct access to n-tree (will raise an exception if the tree does not exist).
-
ptree¶ Direct access to p-tree (will raise an exception if the tree does not exist).
-
ttree¶ Direct access to t-tree (will raise an exception if the tree does not exist).
-
alex.components.nlg.tectotpl.core.exception module¶
-
exception
alex.components.nlg.tectotpl.core.exception.DataException(path)[source]¶ Bases:
alex.components.nlg.tectotpl.core.exception.TreexExceptionData file not found exception
-
exception
alex.components.nlg.tectotpl.core.exception.LoadingException(text)[source]¶ Bases:
alex.components.nlg.tectotpl.core.exception.TreexExceptionBlock loading exception
-
exception
alex.components.nlg.tectotpl.core.exception.RuntimeException(text)[source]¶ Bases:
alex.components.nlg.tectotpl.core.exception.TreexExceptionBlock runtime exception
-
exception
alex.components.nlg.tectotpl.core.exception.ScenarioException(text)[source]¶ Bases:
alex.components.nlg.tectotpl.core.exception.TreexExceptionScenario-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.InClauseRepresenting 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_case¶
-
morphcat_gender¶
-
morphcat_grade¶
-
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']¶
-
morphcat_mood¶
-
morphcat_negation¶
-
morphcat_number¶
-
morphcat_person¶
-
morphcat_pos¶
-
morphcat_possgender¶
-
morphcat_possnumber¶
-
morphcat_subpos¶
-
morphcat_tense¶
-
morphcat_voice¶
-
ref_attrib= [u'p_terminal.rf']¶
-
-
class
alex.components.nlg.tectotpl.core.node.EffectiveRelations[source]¶ Bases:
objectRepresenting 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:
objectRepresents 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.NodeRepresenting 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:
objectRepresenting a node in a tree (recursively)
-
attrib= [(u'alignment', <type 'list'>), (u'wild', <type 'dict'>)]¶
-
document¶ The document this node is a member of.
-
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.
-
id¶ The unique id of the node within the document.
-
is_root¶ Return true if this node is a root
-
parent¶ The parent of the current node. None for roots.
-
ref_attrib= []¶
-
remove_reference(ref_type, refd_id)[source]¶ Remove the reference of the given type to the given node.
-
root¶ The root of the tree this node is in.
-
set_attr(name, value)[source]¶ Set the value of the given attribute. Allows for dictionary nesting, e.g. ‘morphcat/gender’
-
set_deref_attr(name, value)[source]¶ This assumes the value is a node/list of nodes and sets its id/their ids as the value of the given attribute.
-
zone¶ The zone this node belongs to.
-
-
class
alex.components.nlg.tectotpl.core.node.Ordered[source]¶ Bases:
objectRepresenting 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¶ 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.NodeRepresenting 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.InClauseRepresenting a t-node
-
anodes¶ Return all anodes of 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'>)]¶
-
aux_anodes¶
-
compl_nodes¶
-
coref_gram_nodes¶
-
coref_text_nodes¶
-
gram_aspect¶
-
gram_degcmp¶
-
gram_deontmod¶
-
gram_diathesis¶
-
gram_dispmod¶
-
gram_gender¶
-
gram_indeftype¶
-
gram_iterativeness¶
-
gram_negation¶
-
gram_number¶
-
gram_numertype¶
-
gram_person¶
-
gram_politeness¶
-
gram_resultative¶
-
gram_sempos¶
-
gram_tense¶
-
gram_verbmod¶
-
lex_anode¶
-
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:
objectThis 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).