babylon.engine.adapters.subgraph_view
SubgraphView for read-only graph iteration.
Extracted from inmemory_adapter to reduce file size and improve modularity. Provides iteration over nodes and edges in a subgraph.
Classes
|
Read-only view of a subgraph. |
- class babylon.engine.adapters.subgraph_view.SubgraphView(subgraph)[source]
Bases:
objectRead-only view of a subgraph.
Provides iteration over nodes in a subgraph returned by neighborhood queries. Wraps the underlying NetworkX subgraph to provide GraphNode iteration.
- _subgraph
The underlying NetworkX subgraph.
Example
>>> from babylon.engine.adapters.inmemory_adapter import NetworkXAdapter >>> adapter = NetworkXAdapter() >>> adapter.add_node("C001", "social_class", wealth=100.0) >>> adapter.add_node("C002", "social_class", wealth=50.0) >>> adapter.add_edge("C001", "C002", "SOLIDARITY") >>> view = adapter.get_neighborhood("C001") >>> list(view.nodes()) [GraphNode(...), GraphNode(...)]
- __init__(subgraph)[source]
Initialize with a NetworkX subgraph.
- Parameters:
subgraph – The NetworkX subgraph to wrap. Can be DiGraph or subgraph view.