class AbstractParentedTree(Tree): (source)
Known subclasses: nltk.tree.MultiParentedTree
, nltk.tree.ParentedTree
Constructor: AbstractParentedTree(node, children)
An abstract base class for a Tree that automatically maintains pointers to parent nodes. These parent pointers are updated whenever any change is made to a tree's structure. Two subclasses are currently defined:
- ParentedTree is used for tree structures where each subtree has at most one parent. This class should be used in cases where there is no"sharing" of subtrees.
- MultiParentedTree is used for tree structures where a subtree may have zero or more parents. This class should be used in cases where subtrees may be shared.
Subclassing
The AbstractParentedTree class redefines all operations that modify a tree's structure to call two methods, which are used by subclasses to update parent information:
- _setparent() is called whenever a new child is added.
- _delparent() is called whenever a child is removed.
Method | __delitem__ |
Undocumented |
Method | __delslice__ |
Undocumented |
Method | __getslice__ |
Undocumented |
Method | __init__ |
Undocumented |
Method | __setitem__ |
Undocumented |
Method | __setslice__ |
Undocumented |
Method | append |
Undocumented |
Method | extend |
Undocumented |
Method | insert |
Undocumented |
Method | pop |
Undocumented |
Method | remove |
Undocumented |
Method | _delparent |
Update the parent pointer of child to not point to self. This method is only called if the type of child is Tree; i.e., it is not called when removing a leaf from a tree. This method is always called before the child is actually removed from the child list of ... |
Method | _setparent |
Update the parent pointer of child to point to self. This method is only called if the type of child is Tree; i.e., it is not called when adding a leaf to a tree. This method is always called before the child is actually added to the child list of ... |
Inherited from Tree
:
Class Method | convert |
Convert a tree between different subtypes of Tree. cls determines which class will be used to encode the new tree. |
Class Method | fromlist |
Convert nested lists to a NLTK Tree |
Class Method | fromstring |
Read a bracketed tree string and return the resulting tree. Trees are represented as nested brackettings, such as: |
Method | __add__ |
Undocumented |
Method | __copy__ |
Undocumented |
Method | __deepcopy__ |
Undocumented |
Method | __eq__ |
Undocumented |
Method | __getitem__ |
Undocumented |
Method | __lt__ |
Undocumented |
Method | __mul__ |
Undocumented |
Method | __radd__ |
Undocumented |
Method | __repr__ |
Undocumented |
Method | __rmul__ |
Undocumented |
Method | __str__ |
Undocumented |
Method | chomsky |
This method can modify a tree in three ways: |
Method | collapse |
Collapse subtrees with a single child (ie. unary productions) into a new non-terminal (Tree node) joined by 'joinChar'. This is useful when working with algorithms that do not allow unary productions, and completely removing the unary productions would require loss of useful information... |
Method | copy |
Undocumented |
Method | draw |
Open a new window containing a graphical diagram of this tree. |
Method | flatten |
Return a flat version of the tree, with all non-root non-terminals removed. |
Method | freeze |
Undocumented |
Method | height |
Return the height of the tree. |
Method | label |
Return the node label of the tree. |
Method | leaf |
No summary |
Method | leaves |
Return the leaves of the tree. |
Method | pformat |
No summary |
Method | pformat |
Returns a representation of the tree compatible with the LaTeX qtree package. This consists of the string \Tree followed by the tree represented in bracketed notation. |
Method | pos |
Return a sequence of pos-tagged words extracted from the tree. |
Method | pprint |
Print a string representation of this Tree to 'stream' |
Method | pretty |
Pretty-print this tree as ASCII or Unicode art. For explanation of the arguments, see the documentation for nltk.treeprettyprinter.TreePrettyPrinter . |
Method | productions |
Generate the productions that correspond to the non-terminal nodes of the tree. For each subtree of the form (P: C1 C2 ... Cn) this produces a production of the form P -> C1 C2 ... Cn. |
Method | set |
Set the node label of the tree. |
Method | subtrees |
Generate all the subtrees of this tree, optionally restricted to trees matching the filter function. |
Method | treeposition |
No summary |
Method | treepositions |
No summary |
Method | un |
This method modifies the tree in three ways: |
Class Variable | __ge__ |
Undocumented |
Class Variable | __gt__ |
Undocumented |
Class Variable | __le__ |
Undocumented |
Class Variable | __ne__ |
Undocumented |
Class Variable | node |
Undocumented |
Class Method | _parse |
Display a friendly error message when parsing a tree string fails. :param s: The string we're parsing. :param match: regexp match of the problem token. :param expecting: what we expected to see instead. |
Method | _frozen |
Undocumented |
Method | _get |
Outdated method to access the node value; use the label() method instead. |
Method | _pformat |
Undocumented |
Method | _repr |
Draws and outputs in PNG for ipython. PNG is used instead of PDF, since it can be displayed in the qt console and has wider browser support. |
Method | _set |
Outdated method to set the node value; use the set_label() method instead. |
Instance Variable | _label |
Undocumented |
nltk.tree.Tree.__init__
nltk.tree.MultiParentedTree
, nltk.tree.ParentedTree
Undocumented
nltk.tree.MultiParentedTree
, nltk.tree.ParentedTree
Update the parent pointer of child to not point to self. This method is only called if the type of child is Tree; i.e., it is not called when removing a leaf from a tree. This method is always called before the child is actually removed from the child list of self.
Parameters | |
child:Tree | Undocumented |
index:int | The index of child in self. |
nltk.tree.MultiParentedTree
, nltk.tree.ParentedTree
Update the parent pointer of child to point to self. This method is only called if the type of child is Tree; i.e., it is not called when adding a leaf to a tree. This method is always called before the child is actually added to the child list of self.
Parameters | |
child:Tree | Undocumented |
index:int | The index of child in self. |
dry | If true, the don't actually set the child's parent pointer; just check for any error conditions, and raise an exception if one is found. |
Raises | |
TypeError | If child is a tree with an impropriate type. Typically, if child is a tree, then its type needs to match the type of self. This prevents mixing of different tree types (single-parented, multi-parented, and non-parented). |