caesar0301/treelib

add a tree to a node of another tree as a subtree

Freakwill opened this issue · 0 comments

How do I add a tree to a node of another tree as a subtree? I need a method add_tree(tree, parent) to do it like add_node.
Sometimes, I also want to merge the root of subtree to the parent node.

The definition would be

def add_tree(self, tree, parent=None):
    if not isinstance(node, Tree):
            raise OSError("First parameter must be object of Tree")
    # tree is a subtree of self and the parent of its root is `parent`

I think, a node is a special tree, regarded as a Tree object (or define a subclass of Tree with only one node). In the sense, add_node is a special case of add_tree.

PS: the issue is from when I create a decision tree for machine learning.