MCPcopy Create free account
hub / github.com/VectifyAI/PageIndex / get_leaf_nodes

Function get_leaf_nodes

pageindex/utils.py:173–189  ·  view source on GitHub ↗
(structure)

Source from the content-addressed store, hash-verified

171
172
173def get_leaf_nodes(structure):
174 if isinstance(structure, dict):
175 if not structure['nodes']:
176 structure_node = copy.deepcopy(structure)
177 structure_node.pop('nodes', None)
178 return [structure_node]
179 else:
180 leaf_nodes = []
181 for key in list(structure.keys()):
182 if 'nodes' in key:
183 leaf_nodes.extend(get_leaf_nodes(structure[key]))
184 return leaf_nodes
185 elif isinstance(structure, list):
186 leaf_nodes = []
187 for item in structure:
188 leaf_nodes.extend(get_leaf_nodes(item))
189 return leaf_nodes
190
191def is_leaf_node(data, node_id):
192 # Helper function to find the node by its node_id

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected