class nltk.MultiParentedTree(node, children=None)[source]

A Tree that automatically maintains parent pointers for multi-parented trees. The following are methods for querying the structure of a multi-parented tree: parents(), parent_indices(), left_siblings(), right_siblings(), roots, treepositions.

Each MultiParentedTree may have zero or more parents. In particular, subtrees may be shared. If a single MultiParentedTree is used as multiple children of the same parent, then that parent will appear multiple times in its parents() method.

MultiParentedTrees should never be used in the same tree as Trees or ParentedTrees. Mixing tree implementations may result in incorrect parent pointers and in TypeError exceptions.


__init__(node[, children])
chomsky_normal_form([factor, horzMarkov, ...]) This method can modify a tree in three ways:
collapse_unary([collapsePOS, collapseRoot, ...]) Collapse subtrees with a single child (ie.
convert(tree) Convert a tree between different subtypes of Tree.
draw() Open a new window containing a graphical diagram of this tree.
flatten() Return a flat version of the tree, with all non-root non-terminals removed.
fromstring(s[, brackets, read_node, ...]) Read a bracketed tree string and return the resulting tree.
height() Return the height of the tree.
index((value, [start, ...) Raises ValueError if the value is not present.
insert(index, child)
label() Return the node label of the tree.
return:The tree position of the index-th leaf in this
leaves() Return the leaves of the tree.
left_siblings() A list of all left siblings of this tree, in any of its parent trees.
parent_indices(parent) Return a list of the indices where this tree occurs as a child of parent.
parents() The set of parents of this tree.
pformat([margin, indent, nodesep, parens, ...])
return:A pretty-printed string representation of this tree.
pformat_latex_qtree() Returns a representation of the tree compatible with the LaTeX qtree package.
pos() Return a sequence of pos-tagged words extracted from the tree.
pprint(**kwargs) Print a string representation of this Tree to ‘stream’
pretty_print([sentence, highlight, stream]) Pretty-print this tree as ASCII or Unicode art.
productions() Generate the productions that correspond to the non-terminal nodes of the tree.
reverse L.reverse() – reverse IN PLACE
right_siblings() A list of all right siblings of this tree, in any of its parent trees.
roots() The set of all roots of this tree.
set_label(label) Set the node label of the tree.
sort L.sort(cmp=None, key=None, reverse=False) – stable sort IN PLACE;
subtrees([filter]) Generate all the subtrees of this tree, optionally restricted to trees matching the filter function.
treeposition_spanning_leaves(start, end)
return:The tree position of the lowest descendant of this
treepositions(root) Return a list of all tree positions that can be used to reach this multi-parented tree starting from root.
un_chomsky_normal_form([expandUnary, ...]) This method modifies the tree in three ways:


node Outdated method to access the node value; use the label() method instead.