Ascend the FP-Tree from a leaf node to its root, adding item names to the prefix path. Args: leaf_node: The leaf node to start ascending from. prefix_path: A list to store the item as they are ascended. Example: >>> data_set = [ ... ['A', 'B', 'C'],
(leaf_node: TreeNode, prefix_path: list[str])
| 211 | |
| 212 | |
| 213 | def ascend_tree(leaf_node: TreeNode, prefix_path: list[str]) -> None: |
| 214 | """ |
| 215 | Ascend the FP-Tree from a leaf node to its root, adding item names to the prefix |
| 216 | path. |
| 217 | |
| 218 | Args: |
| 219 | leaf_node: The leaf node to start ascending from. |
| 220 | prefix_path: A list to store the item as they are ascended. |
| 221 | |
| 222 | Example: |
| 223 | >>> data_set = [ |
| 224 | ... ['A', 'B', 'C'], |
| 225 | ... ['A', 'C'], |
| 226 | ... ['A', 'B', 'E'], |
| 227 | ... ['A', 'B', 'C', 'E'], |
| 228 | ... ['B', 'E'] |
| 229 | ... ] |
| 230 | >>> min_sup = 2 |
| 231 | >>> fp_tree, header_table = create_tree(data_set, min_sup) |
| 232 | |
| 233 | >>> path = [] |
| 234 | >>> ascend_tree(fp_tree.children['A'], path) |
| 235 | >>> path # ascending from a leaf node 'A' |
| 236 | ['A'] |
| 237 | """ |
| 238 | if leaf_node.parent is not None: |
| 239 | prefix_path.append(leaf_node.name) |
| 240 | ascend_tree(leaf_node.parent, prefix_path) |
| 241 | |
| 242 | |
| 243 | def find_prefix_path(base_pat: frozenset, tree_node: TreeNode | None) -> dict: # noqa: ARG001 |
no test coverage detected