In [7]:
import sys
import json
sys.path.append("../")
from tag2hierarchy.hierarchy import HTMLPLOT
from tag2hierarchy.hierarchy import tree2Dict
from tag2hierarchy.hierarchy import treeHandlers
In [8]:
dictTree = json.load(open("../data/myTree.json"))
In [30]:
dictTree
Out[30]:
In [40]:
# We create an objectTree, this is a list of trees from
objectTree = tree2Dict.fromDictTreeToObjectTree([dictTree])
# We can generate a plot for the tree with
HTMLPLOT.vizualizeObjectTree("../visualization/", objectTree, plotName='fromNotebook', dynamic=False)
In [13]:
actual = treeHandlers.nodeNames(objectTree)
treeHandlers.setBranch(objectTree)
#Obtain a Branch for a particular node
branchesActual = {}
for n in treeHandlers.transverseTree(objectTree):
branchesActual[n.name] = n.myBranch
branchesActual
Out[13]:
In [31]:
descendants = treeHandlers.obtainDescendantsFromNode(objectTree,"B")
nodesPerLevel = treeHandlers.obtainNodesPerLevel(objectTree)
nodesAtMyLevel = treeHandlers.obtainsNodesAtMyLevel(objectTree,"F",nodesPerLevel=None)
descendantsPerLevel = treeHandlers.obtainDescendantsPerLevel(objectTree,"A")
leaves = treeHandlers.obtainLeavesFromNode(objectTree,"A")
nonLeaves = treeHandlers.obtainNonLeaves(objectTree)
In [32]:
descendantsActual
Out[32]:
In [33]:
nodesPerLevel
Out[33]:
In [34]:
nodesAtMyLevel
Out[34]:
In [35]:
descendantsPerLevel
Out[35]:
In [36]:
leaves
Out[36]:
In [37]:
nonLeaves
Out[37]: