Tree

class shajara.Tree(root=None)

Bases: object

Generic tree representation

Parameters:
  • value (ANY) – the value of the root node
  • label (ANY) – the label of the root node
root

The root node

Type:Node
node_stack

the stack for browsing nodes

Type:array

Methods Summary

add_child(label, node) Adds a child to the current node.
current_node() Returns the current node
get_root() Returns the root of the tree
process([processor]) Short summary.
select_child(label) Select a child node of the current one, using its label.
up() Select the parent of the current node.

Methods Documentation

add_child(label, node)

Adds a child to the current node. To browse the nodes use select_child and up

Parameters:
  • label (str or int) – The label of the arc
  • node (Node) – The node to add as a child
Returns:

this object

Return type:

Tree

current_node()

Returns the current node

Returns:The current node
Return type:Node
get_root()

Returns the root of the tree

Returns:The root of the tree if it exists or None
Return type:Node
process(processor=<shajara.NodeProcessor object>)

Short summary.

Parameters:processor (NodeProcessor) – the processor used to manipulate the tree starting from its root
Returns:The result of processing, it can be None, a node, a string, etc.
Return type:type
select_child(label)

Select a child node of the current one, using its label. Used to browsing the tree down.

Parameters:label (str or int) – the label of the label of the arc
Returns:this object
Return type:Tree
up()

Select the parent of the current node. Used to browsing the tree up.

Returns:this object
Return type:type