@@ -103,7 +103,7 @@ $ brew install gprof2dot
103
103
104
104
## Tree Demonstration
105
105
106
- Here are some codes to getting started.
106
+ Here are some codes to get started.
107
107
108
108
### Construct Tree
109
109
@@ -349,7 +349,7 @@ print_tree(root, attr_list=["age"])
349
349
# │ └── e [age=35]
350
350
# └── c [age=60]
351
351
352
- print_tree(root, attr_list = [" age" ], attr_bracket_open = " *(" , attr_bracket_close = " )" )
352
+ print_tree(root, attr_list = [" age" ], attr_bracket = [ " *(" , " )" ] )
353
353
# a *(age=90)
354
354
# ├── b *(age=65)
355
355
# │ ├── d *(age=40)
@@ -400,8 +400,9 @@ print_tree(root, style="double")
400
400
# ╚══ c
401
401
402
402
print_tree(
403
- root, style = " custom" ,
404
- style_stem = " | " , style_branch = " |-- " , style_stem_final = " +-- "
403
+ root,
404
+ style = " custom" ,
405
+ custom_style = (" | " , " |-- " , " +-- " ),
405
406
)
406
407
# a
407
408
# |-- b
@@ -535,22 +536,22 @@ To find multiple nodes,
535
536
from bigtree import Node, print_tree, findall, find_names, find_paths, find_attrs
536
537
root = Node(" a" , age = 90 )
537
538
b = Node(" b" , age = 65 , parent = root)
538
- c = Node(" c" , age = 65 , parent = root)
539
+ c = Node(" c" , age = 60 , parent = root)
539
540
d = Node(" c" , age = 40 , parent = c)
540
541
print_tree(root, attr_list = [" age" ])
541
542
# a [age=90]
542
543
# ├── b [age=65]
543
544
# └── c [age=65]
544
545
# └── c [age=40]
545
546
546
- findall(root, lambda node : node.age = = 65 )
547
- # (Node(/a/b , age=65 ), Node(/a/c , age=65))
547
+ findall(root, lambda node : node.age > = 65 )
548
+ # (Node(/a, age=90 ), Node(/a/b , age=65))
548
549
549
550
find_names(root, " c" )
550
- # (Node(/a/c, age=65 ), Node(/a/c/c, age=40))
551
+ # (Node(/a/c, age=60 ), Node(/a/c/c, age=40))
551
552
552
553
find_paths(root, " /c" ) # partial path
553
- # (Node(/a/c, age=65 ), Node(/a/c/c, age=40))
554
+ # (Node(/a/c, age=60 ), Node(/a/c/c, age=40))
554
555
555
556
find_attrs(root, " age" , 40 )
556
557
# (Node(/a/c/c, age=40),)
@@ -603,6 +604,12 @@ tree_diff = get_tree_diff(root, root_other)
603
604
print_tree(tree_diff)
604
605
# a
605
606
# └── c (-)
607
+
608
+ tree_diff = get_tree_diff(root, root_other, only_diff = False )
609
+ print_tree(tree_diff)
610
+ # a
611
+ # ├── b
612
+ # └── c (-)
606
613
```
607
614
608
615
### Export Tree
@@ -802,11 +809,11 @@ from bigtree import dict_to_dag, dag_iterator
802
809
relation_dict = {
803
810
" a" : {" step" : 1 },
804
811
" b" : {" step" : 1 },
805
- " c" : {" parent " : [" a" , " b" ], " step" : 2 },
806
- " d" : {" parent " : [" a" , " c" ], " step" : 2 },
807
- " e" : {" parent " : [" d" ], " step" : 3 },
812
+ " c" : {" parents " : [" a" , " b" ], " step" : 2 },
813
+ " d" : {" parents " : [" a" , " c" ], " step" : 2 },
814
+ " e" : {" parents " : [" d" ], " step" : 3 },
808
815
}
809
- dag = dict_to_dag(relation_dict, parent_key = " parent " )
816
+ dag = dict_to_dag(relation_dict, parent_key = " parents " )
810
817
print ([(parent.node_name, child.node_name) for parent, child in dag_iterator(dag)])
811
818
# [('a', 'd'), ('c', 'd'), ('d', 'e'), ('a', 'c'), ('b', 'c')]
812
819
```
0 commit comments