simple_hierarchy.tree

A module for a tree structure for a class hierarchy.

class simple_hierarchy.tree.Node(name, n_classes, parent)[source]

Bases: object

Stores a node with name and number of classes.

Used to store a node with a name of number of classes. This class is inteded for storing class heiarchies, as such, their is both a name and number of classes per node. The node is linked to a list of children and its parent.

Parameters
  • name (str) – The name of the node.

  • n_classes (int) – The number of classes for this class that node represents.

  • parent (Optional[Node]) – The parent of the node, if its the root, then the parent is None.

name

The name of the node.

n_classes

The number of classes for this class that node represents.

parent

The parent of the node, if its the root, then the parent is None.

children

A list of nodes that are children of this node.

add_child(child)[source]

Adds a child node.

Adds a child node to current node. This child is added to a list of children.

Parameters

child (Node) – A node to add the current node..

Return type

None

get_tuple()[source]

Get tuple of name, n_classes for each node.

Return type

Tuple[str, int]

class simple_hierarchy.tree.Tree(root)[source]

Bases: object

Stores a root node.

Creates a Tree oject to store a root node as defined with the Node class.

Parameters

root (Node) – The root node to store as a tree.

root

The root node of the tree.