jaclearn.nlp.tree package

Submodules

jaclearn.nlp.tree.constituency module

Constituency Tree.

class jaclearn.nlp.tree.constituency.StepMaskSelectionMode[source]

Bases: jacinle.utils.enum.JacEnum

An enumeration.

FIRST = 'first'
RANDOM = 'random'
jaclearn.nlp.tree.constituency.binarize_tree(tree)[source]
jaclearn.nlp.tree.constituency.compose_bianry_tree_step_masks(tree, selection='first')[source]
jaclearn.nlp.tree.constituency.make_balanced_binary_tree(sequence)[source]

jaclearn.nlp.tree.node module

The definition for tree Nodes.

class jaclearn.nlp.tree.node.Node(vtype, etype=None)[source]

Bases: object

append_child(node)[source]
attach(father, sibling_ind=-1)[source]

Attach to a new father.

breadth

Breadth is defined as the maximum number of children of nodes in the tree.

clone()[source]
depth

Depth is defined as the number of nodes on the maximum distance with the root of nodes + 1. (Thus a single nodes will have depth 1.)

detach()[source]

Detach from the father.

insert_child(pos, node)[source]
is_leaf
lson
nr_children
nr_leaves
remove_child(node)[source]
rson
size

jaclearn.nlp.tree.ptb module

PTB-formed constituency trees.

class jaclearn.nlp.tree.ptb.PTBNode(vtype, token=None, index=-1)[source]

Bases: jaclearn.nlp.tree.node.Node

assign_index(start_index=0)[source]
classmethod from_string(encoding, incl_vtype=True, default_vtype=None)[source]
leftmost_index
rightmost_index
to_sentence(to_string=True)[source]
to_string(to_string=True, compressed=True, vtype=True)[source]
jaclearn.nlp.tree.ptb.parse_ptb(sentence)[source]

jaclearn.nlp.tree.traversal module

Tree traversal uilties.

class jaclearn.nlp.tree.traversal.TraversalOrder[source]

Bases: jacinle.utils.enum.JacEnum

An enumeration.

POST = 'post'
PRE = 'pre'
jaclearn.nlp.tree.traversal.traversal(root, order='pre')[source]