@@ -555,7 +555,7 @@ Below are the tables of attributes available to `BaseNode` and `Node` classes.
555555| Get parent | ` node_e.parent ` | Node(/a/b, ) |
556556| Get siblings | ` node_e.siblings ` | (Node(/a/b/d, ), Node(/a/b/f, )) |
557557| Get left sibling | ` node_e.left_sibling ` | Node(/a/b/d, ) |
558- | Get right sibling | ` node_e.left_sibling ` | Node(/a/b/f, ) |
558+ | Get right sibling | ` node_e.right_sibling ` | Node(/a/b/f, ) |
559559| Get ancestors (lazy evaluation) | ` list(node_e.ancestors) ` | [ Node(/a/b, ), Node(/a, )] |
560560| Get descendants (lazy evaluation) | ` list(node_b.descendants) ` | [ Node(/a/b/d, ), Node(/a/b/e, ), Node(/a/b/f, ), Node(/a/b/f/h, ), Node(/a/b/f/i, )] |
561561| Get leaves (lazy evaluation) | ` list(node_b.leaves) ` | [ Node(/a/b/d, ), Node(/a/b/e, ), Node(/a/b/f/h, ), Node(/a/b/f/i, )] |
@@ -1151,8 +1151,10 @@ Compared to nodes in tree, nodes in DAG are able to have multiple parents.
11511151
115211521 . ** From ` DAGNode ` **
11531153
1154- DAGNode can be linked to each other with ` parents ` and ` children ` setter methods,
1155- or using bitshift operator with the convention ` parent_node >> child_node ` or ` child_node << parent_node ` .
1154+ DAGNodes can be linked to each other in the following ways:
1155+ - Using ` parents ` and ` children ` setter methods
1156+ - Directly passing ` parents ` or ` children ` argument
1157+ - Using bitshift operator with the convention ` parent_node >> child_node ` or ` child_node << parent_node `
11561158
11571159{emphasize-lines="5-8,10"}
11581160``` python
@@ -1238,6 +1240,55 @@ print([(parent.node_name, child.node_name) for parent, child in dag_iterator(dag
12381240# [('a', 'd'), ('c', 'd'), ('d', 'e'), ('a', 'c'), ('b', 'c')]
12391241```
12401242
1243+ ### DAG Attributes and Operations
1244+
1245+ Note that using ` DAGNode ` as superclass inherits the default class attributes (properties) and operations (methods).
1246+
1247+ ``` python
1248+ from bigtree import list_to_dag
1249+
1250+ relations_list = [
1251+ (" a" , " c" ),
1252+ (" a" , " d" ),
1253+ (" b" , " c" ),
1254+ (" c" , " d" ),
1255+ (" d" , " e" )
1256+ ]
1257+ dag = list_to_dag(relations_list)
1258+ dag
1259+ # DAGNode(d, )
1260+
1261+ # Accessing children
1262+ node_e = dag[" e" ]
1263+ node_a = dag.parents[0 ]
1264+ ```
1265+
1266+ Below are the tables of attributes available to ` DAGNode ` class.
1267+
1268+ | Attributes wrt self | Code | Returns |
1269+ | --------------------------------------| ------------------| ---------|
1270+ | Check if root | ` node_a.is_root ` | True |
1271+ | Check if leaf node | ` dag.is_leaf ` | False |
1272+ | Get node name (only for ` Node ` ) | ` dag.node_name ` | 'd' |
1273+
1274+ | Attributes wrt structure | Code | Returns |
1275+ | ------------------------------| -----------------------| ----------------------------------------------------------------------|
1276+ | Get child/children | ` node_a.children ` | (DAGNode(c, ), DAGNode(d, )) |
1277+ | Get parents | ` dag.parents ` | (DAGNode(a, ), DAGNode(c, )) |
1278+ | Get siblings | ` dag.siblings ` | (DAGNode(c, ),) |
1279+ | Get ancestors | ` dag.ancestors ` | [ DAGNode(a, ), DAGNode(b, ), DAGNode(c, )] |
1280+ | Get descendants | ` dag.descendants ` | [ DAGNode(e, )] |
1281+
1282+ Below is the table of operations available to ` DAGNode ` class.
1283+
1284+ | Operations | Code | Returns |
1285+ | ---------------------------------------| ------------------------------------------------------------| ------------------------------------------------------------------------------------------------------------------|
1286+ | Get node information | ` dag.describe(exclude_prefix="_") ` | [ ('name', 'd')] |
1287+ | Find path(s) from one node to another | ` node_a.go_to(dag) ` | [[ DAGNode(a, ), DAGNode(c, ), DAGNode(d, description=dag-tag)] , [ DAGNode(a, ), DAGNode(d, description=dag-tag)]] |
1288+ | Set attribute(s) | ` dag.set_attrs({"description": "dag-tag"}) ` | None |
1289+ | Get attribute | ` dag.get_attr("description") ` | 'dag-tag' |
1290+ | Copy DAG | ` dag.copy() ` | None |
1291+
12411292----
12421293
12431294## Demo Usage
0 commit comments