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

SubgraphView(subgraph)

Read-only view of a subgraph.

class babylon.engine.adapters.subgraph_view.SubgraphView(subgraph)[source]

Bases: object

Read-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.

nodes()[source]

Iterate over nodes in the subgraph.

Yields:

GraphNode models for each node in the subgraph.

Return type:

Iterator[GraphNode]

edges()[source]

Iterate over edges in the subgraph.

Yields:

GraphEdge models for each edge in the subgraph.

Return type:

Iterator[GraphEdge]