Package nltk :: Module tree :: Class AbstractParentedTree
[hide private]
[frames] | no frames]

Class AbstractParentedTree

source code

object --+        
         |        
      list --+    
             |    
          Tree --+
                 |
                AbstractParentedTree
Known Subclasses:

An abstract base class for Trees that automatically maintain pointers to their parents. These parent pointers are updated whenever any change is made to a tree's structure. Two subclasses are currently defined:

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:

Instance Methods [hide private]
 
__init__(self, node_or_str, children=None)
Construct a new tree.
source code
 
_setparent(self, child, index, dry_run=False)
Update child's parent pointer to point to self.
source code
 
_delparent(self, child, index)
Update child's parent pointer to not point to self.
source code
 
__delitem__(self, index) source code
 
__setitem__(self, index, value) source code
 
append(self, child)
append object to end
source code
 
extend(self, children)
extend list by appending elements from the iterable
source code
 
insert(self, index, child)
insert object before index
source code
item
pop(self, index=-1)
remove and return item at index (default last)
source code
 
remove(self, child)
remove first occurrence of value
source code
 
__getslice__(self, start, stop)
x[i:j]
source code
 
__delslice__(self, start, stop)
del x[i:j]
source code
 
__setslice__(self, start, stop, value)
x[i:j]=y
source code

Inherited from Tree: __add__, __eq__, __ge__, __getitem__, __gt__, __le__, __lt__, __mul__, __ne__, __radd__, __repr__, __rmul__, __str__, chomsky_normal_form, collapse_unary, copy, draw, flatten, freeze, height, leaf_treeposition, leaves, pos, pprint, pprint_latex_qtree, productions, subtrees, treeposition_spanning_leaves, treepositions, un_chomsky_normal_form

Inherited from Tree (private): _frozen_class, _pprint_flat

Inherited from list: __contains__, __getattribute__, __hash__, __iadd__, __imul__, __iter__, __len__, __reversed__, count, index, reverse, sort

Inherited from object: __delattr__, __reduce__, __reduce_ex__, __setattr__

Class Methods [hide private]

Inherited from Tree: convert, parse

Inherited from Tree (private): _parse_error

Static Methods [hide private]

Inherited from Tree: __new__

Properties [hide private]

Inherited from object: __class__

Method Details [hide private]

__init__(self, node_or_str, children=None)
(Constructor)

source code 

Construct a new tree. This constructor can be called in one of two ways:

  • Tree(node, children) constructs a new tree with the specified node value and list of children.
  • Tree(s) constructs a new tree by parsing the string s. It is equivalent to calling the class method Tree.parse(s).
Overrides: Tree.__init__
(inherited documentation)

_setparent(self, child, index, dry_run=False)

source code 

Update child's parent pointer to point to self. This method is only called if child's type 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 self's child list.

Parameters:
  • index (int) - The index of child in self.
  • dry_run - 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.
  • child (Tree)
Raises:
  • TypeError - If child is a tree with an impropriate type. Typically, if child is a tree, then its type needs to match self's type. This prevents mixing of different tree types (single-parented, multi-parented, and non-parented).

_delparent(self, child, index)

source code 

Update child's parent pointer to not point to self. This method is only called if child's type 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 self's child list.

Parameters:
  • index (int) - The index of child in self.
  • child (Tree)

__delitem__(self, index)
(Index deletion operator)

source code 
Overrides: Tree.__delitem__

__setitem__(self, index, value)
(Index assignment operator)

source code 
Overrides: Tree.__setitem__

append(self, child)

source code 

append object to end

Overrides: list.append
(inherited documentation)

extend(self, children)

source code 

extend list by appending elements from the iterable

Overrides: list.extend
(inherited documentation)

insert(self, index, child)

source code 

insert object before index

Overrides: list.insert
(inherited documentation)

pop(self, index=-1)

source code 

remove and return item at index (default last)

Returns: item
Overrides: list.pop
(inherited documentation)

remove(self, child)

source code 

remove first occurrence of value

Overrides: list.remove
(inherited documentation)

__getslice__(self, start, stop)
(Slicling operator)

source code 

x[i:j]

Use of negative indices is not supported.

Overrides: list.__getslice__
(inherited documentation)

__delslice__(self, start, stop)
(Slice deletion operator)

source code 

del x[i:j]

Use of negative indices is not supported.

Overrides: list.__delslice__
(inherited documentation)

__setslice__(self, start, stop, value)
(Slice assignment operator)

source code 

x[i:j]=y

Use of negative indices is not supported.

Overrides: list.__setslice__
(inherited documentation)