Package rdkit :: Package ML :: Package DecTree :: Module Tree :: Class TreeNode
[hide private]
[frames] | no frames]

Class TreeNode

source code

Known Subclasses:

This is your bog standard Tree class.

the root of the tree is just a TreeNode like all other members.

Instance Methods [hide private]
 
__init__(self, parent, name, label=None, data=None, level=0, isTerminal=0)
constructor
source code
 
NameTree(self, varNames)
Set the names of each node in the tree from a list of variable names.
source code
 
NameModel(self, varNames)
Set the names of each node in the tree from a list of variable names.
source code
 
AddChildNode(self, node)
Adds a TreeNode to the local list of children
source code
 
AddChild(self, name, label=None, data=None, isTerminal=0)
Creates a new TreeNode and adds a child to the tree
source code
 
PruneChild(self, child)
Removes the child node
source code
 
ReplaceChildIndex(self, index, newChild)
Replaces a given child with a new one
source code
 
GetChildren(self)
Returns a python list of the children of this node
source code
 
Destroy(self)
Destroys this node and all of its children
source code
 
GetName(self)
Returns the name of this node
source code
 
SetName(self, name)
Sets the name of this node
source code
 
GetData(self)
Returns the data stored at this node
source code
 
SetData(self, data)
Sets the data stored at this node
source code
 
GetTerminal(self)
Returns whether or not this node is terminal
source code
 
SetTerminal(self, isTerminal)
Sets whether or not this node is terminal
source code
 
GetLabel(self)
Returns the label of this node
source code
 
SetLabel(self, label)
Sets the label of this node (should be an integer)
source code
 
GetLevel(self)
Returns the level of this node
source code
 
SetLevel(self, level)
Sets the level of this node
source code
 
GetParent(self)
Returns the parent of this node
source code
 
SetParent(self, parent)
Sets the parent of this node
source code
 
Print(self, level=0, showData=0)
Pretty prints the tree
source code
 
Pickle(self, fileName='foo.pkl')
Pickles the tree and writes it to disk
source code
 
__str__(self)
returns a string representation of the tree
source code
 
__cmp__(self, other)
allows tree1 == tree2
source code
Method Details [hide private]

__init__(self, parent, name, label=None, data=None, level=0, isTerminal=0)
(Constructor)

source code 
constructor

**Arguments**

  - parent: the parent of this node in the tree

  - name: the name of the node

  - label: the node's label (should be an integer)

  - data: an optional data field

  - level: an integer indicating the level of this node in the hierarchy
    (used for printing)

  - isTerminal: flags a node as being terminal.  This is useful for those
    times when it's useful to know such things.

NameTree(self, varNames)

source code 
Set the names of each node in the tree from a list of variable names.

**Arguments**

  - varNames: a list of names to be assigned

**Notes**

   1) this works its magic by recursively traversing all children

   2) The assumption is made here that the varNames list can be indexed
      by the labels of tree nodes

NameModel(self, varNames)

source code 
Set the names of each node in the tree from a list of variable names.

**Arguments**

  - varNames: a list of names to be assigned

**Notes**

   1) this works its magic by recursively traversing all children

   2) The assumption is made here that the varNames list can be indexed
      by the labels of tree nodes

AddChildNode(self, node)

source code 
Adds a TreeNode to the local list of children

**Arguments**

  - node: the node to be added

**Note**

  the level of the node (used in printing) is set as well

AddChild(self, name, label=None, data=None, isTerminal=0)

source code 
Creates a new TreeNode and adds a child to the tree

**Arguments**

 - name: the name of the new node

 - label: the label of the new node (should be an integer)

 - data: the data to be stored in the new node

 - isTerminal: a toggle to indicate whether or not the new node is
   a terminal (leaf) node.

**Returns*

  the _TreeNode_ which is constructed
  

PruneChild(self, child)

source code 
Removes the child node

**Arguments**

  - child: a TreeNode

ReplaceChildIndex(self, index, newChild)

source code 
Replaces a given child with a new one

**Arguments**

  - index: an integer
  
  - child: a TreeNode

Print(self, level=0, showData=0)

source code 
Pretty prints the tree

**Arguments**

  - level: sets the number of spaces to be added at the beginning of the output

  - showData: if this is nonzero, the node's _data_ value will be printed as well

**Note**

  this works recursively

__str__(self)
(Informal representation operator)

source code 
returns a string representation of the tree

**Note**

  this works recursively

__cmp__(self, other)
(Comparison operator)

source code 
allows tree1 == tree2

**Note**

  This works recursively