Node module#
Sub-module that contains information about Node.
- class galaxy_graph.node.Node(identifier: str = <factory>, data: T | None = None)#
Singular element storing data.
Can be connected to other node and be a part of a Graph.
- connect(connection: Connection[__annotationlib_name_1__], destination: Node) Connection[__annotationlib_name_2__]#
Connect this node to another one with a specific connection.
If the graph of the node is not directed, the other node will have the same connection.
Notes#
Node must be in a graph. A Node can connect to itself.
Parameters#
- connection: Connection
Connection not already connected to nodes.
- destination: Node
Node already in the Graph or not.
Raises#
- NodeOfflineError
If the Node is not in a graph.
- get_incoming_neighbors_by_connection_data(predicate: Callable[[__annotationlib_name_1__], __annotationlib_name_2__]) set[Node]#
Get incoming neighbors node via connections matching a filter.
Notes#
Node must be in a graph.
Parameters#
- predicate: Callable[[ConnectionData | None], bool]
Filter function, determine if the connected Node is kept.
Raises#
- NodeOfflineError
If the Node is not in a graph.
- get_incoming_neighbors_by_connection_type(type_: type[Connection]) set[Node]#
Get incoming neighbors node via connections of a specific type.
Notes#
Node must be in a graph.
Parameters#
- type_: type[Connection]
Type of the connection to look at.
- get_incoming_neighbors_by_node_data(predicate: Callable[[__annotationlib_name_1__], __annotationlib_name_2__]) set[Node[NodeData | None]]#
Get incoming neighbors node matching a data filter.
Notes#
Node must be in a graph.
Parameters#
- predicate: Callable[[NodeData | None], bool]
Filter function, determine if the connected Node is kept.
Raises#
- NodeOfflineError
If the Node is not in a graph.
- get_incoming_neighbors_by_node_type(type_: type[Node]) set[Node]#
Get incoming neighbors node of a specific type.
Notes#
Node must be in a graph.
Parameters#
- type_: type[Node]
Type of the node to look at.
Raises#
- NodeOfflineError
If the Node is not in a graph.
- get_neighbors_by_connection_data(predicate: Callable[[__annotationlib_name_1__], __annotationlib_name_2__], direction: Literal['all', 'outgoing', 'incoming']) set[Node]#
Get neighbors node via connections matching a data filter.
Notes#
Node must be in a graph.
Parameters#
- predicate: Callable[[Any], bool]
Filter function, determine if the connected Node is kept.
- direction: Literal[“all” | “outgoing” | “incoming”]
Direction of the connection.
Raises#
- NodeOfflineError
If the Node is not in a graph.
- get_neighbors_by_connection_type(type_: type[Connection], direction: Literal['all', 'outgoing', 'incoming']) set[Node]#
Get neighbors node via connections of a specific type.
Notes#
Node must be in a graph.
Parameters#
- type_: type[Connection]
Type of the connection to look at.
- direction: Literal[“all”, “outgoing”, “incoming”]
Direction of the connection.
Raises#
- NodeOfflineError
If the Node is not in a graph.
- get_neighbors_by_node_data(predicate: Callable[[__annotationlib_name_1__], __annotationlib_name_2__], direction: Literal['all', 'incoming', 'outgoing']) set[Node[NodeData | None]]#
Get neighbors node matching a data filter.
Notes#
Node must be in a graph.
Parameters#
- predicate: Callable[[NodeData | None], bool]
Filter function, determine if the connected Node is kept.
- direction: Literal[“all”, “incoming”, “outgoing”]
Direction of the connection.
Raises#
- NodeOfflineError
If the Node is not in a graph.
- get_neighbors_by_node_type(type_: type[Node], direction: Literal['all', 'incoming', 'outgoing']) set[Node]#
Get neighbors node of a specific type.
Notes#
Node must be in a graph.
Parameters#
- type_: type[Node]
Type of the node to look at.
- direction: Literal[“all”, “incoming”, “outgoing”]
Direction of the connection.
Raises#
- NodeOfflineError
If the Node is not in a graph.
- get_outgoing_neighbors_by_connection_data(predicate: Callable[[__annotationlib_name_1__], __annotationlib_name_2__]) set[Node]#
Get outgoing neighbors node via connections matching a filter.
Notes#
Node must be in a graph.
Parameters#
- predicate: Callable[[ConnectionData | None], bool]
Filter function, determine if the connected Node is kept.
Raises#
- NodeOfflineError
If the Node is not in a graph.
- get_outgoing_neighbors_by_connection_type(type_: type[Connection]) set[Node]#
Get outgoing neighbors node via connections of a specific type.
Notes#
Node must be in a graph.
Parameters#
- type_: type[Connection]
Type of the connection to look at.
- get_outgoing_neighbors_by_node_data(predicate: Callable[[__annotationlib_name_1__], __annotationlib_name_2__]) set[Node[NodeData | None]]#
Get outgoing neighbors node matching a data filter.
Notes#
Node must be in a graph.
Parameters#
- predicate: Callable[[NodeData | None], bool]
Filter function, determine if the connected Node is kept.
Raises#
- NodeOfflineError
If the Node is not in a graph.
- get_outgoing_neighbors_by_node_type(type_: type[Node]) set[Node]#
Get outgoing neighbors node of a specific type.
Notes#
Node must be in a graph.
Parameters#
- type_: type[Node]
Type of the node to look at.
Raises#
- NodeOfflineError
If the Node is not in a graph.
- property incoming_connections: set[Connection]#
Get incoming connections to this node.
Notes#
Node must be in a graph.
Raises#
- NodeOfflineError
If the Node is not in a graph.
- property outgoing_connections: set[Connection]#
Get outgoing connections from this node.
Notes#
Node must be in a graph.
Raises#
- NodeOfflineError
If the Node is not in a graph.
- class galaxy_graph.node.NodeIsOffline(state: NodeState[__annotationlib_name_1__])#
The Node is not in a Graph.
- is_online() bool#
Check if the Node is associated to a Graph.
- class galaxy_graph.node.NodeIsOnline(state: NodeState[__annotationlib_name_1__], graph: Graph[__annotationlib_name_1__], outgoing_connections: set[Connection] = <factory>, incoming_connections: set[Connection] = <factory>)#
The Node is in a Graph.
- check_connection_state(connection: Connection) None#
Check if the connection is setup and is not already used.
- connect(connection: Connection[__annotationlib_name_1__], destination: Node, *, force_directed: bool = False) Connection[__annotationlib_name_2__]#
Connect this node to another one with a specific connection.
If the graph of the node is not directed, the other node will have the same connection.
Notes#
A Node can connect to itself.
Parameters#
- connection: Connection
Connection not already connected to nodes.
- destination: Node
Node already in a Graph or not.
- force_directed: bool = False
Force the graph to be considered as directed to avoid creating another connection in the other direction if the graph is not directed.
- delete_incoming_connections_by_node(node: Node) int#
Delete incoming connections with a given node.
Used by Graph class to remove a node and its associated connections.
- delete_outgoing_connections_by_node(node: Node) int#
Delete outgoing connections with a given node.
Used by Graph class to remove a node and its associated connections.
- get_incoming_neighbors_by_connection_data(predicate: Callable[[__annotationlib_name_1__], __annotationlib_name_2__]) set[Node]#
Get nodes with incoming connections respecting a filter on data.
The filter function will be applied to the data of every connections of this node. If the filter return true, the node associated to the connection is included in the returned set.
Parameters#
- predicate: Callable[[T | None], bool]
Filter function, determine if the connected Node is kept.
Examples#
>>> node = Node() >>> node_1 = Node() >>> node_2 = Node() >>> node.connect(Connection, node_1, 2) >>> node.connect(Connection, node_2, 14) >>> online_state = node.state.online >>> online_state.get_incoming_neighbors_by_connection_data( >>> predicate=lambda x: x < 10 >>> if isinstance(x, int) else False, >>> ) { node_1 }
- get_incoming_neighbors_by_connection_type(type_: type[Connection]) set[Node]#
Get nodes with incoming connections of the given types.
Parameters#
- type_: type[Connection]
Type of the connection to look at.
- get_incoming_neighbors_by_node_data(predicate: Callable[[__annotationlib_name_1__], __annotationlib_name_2__]) set[Node[__annotationlib_name_3__]]#
Get incoming linked nodes with data respecting a given filter.
The filter function will be applied to the data of every nodes connected to this node. If the filter return true, the node is included in the returned set.
Parameters#
- predicate: Callable[[T | None], bool]
Filter function, determine if the connected Node is kept.
Examples#
>>> node = Node() >>> node_1 = Node(data=5) >>> node_2 = Node(data=12) >>> node.connect(Connection, node_1) >>> node.connect(Connection, node_2) >>> online_state = node.state.online >>> online_state.get_incoming_neighbors_by_node_data( >>> filter=lambda x: x < 9 if isinstance(x, int) else False, >>> ) { node_1 }
- get_incoming_neighbors_by_node_type(type_: type[Node]) set[Node]#
Get incoming linked node with a given type.
Parameters#
- type_: type[Node]
Type of the node to look at.
- get_outgoing_neighbors_by_connection_data(predicate: Callable[[__annotationlib_name_1__], __annotationlib_name_2__]) set[Node]#
Get nodes with outgoing connections respecting a filter on data.
The filter function will be applied to the data of every connections of this node. If the filter return true, the node associated to the connection is included in the returned set.
Parameters#
- predicate: Callable[[Any | None], bool]
Filter function, determine if the connected Node is kept.
Examples#
>>> node = Node() >>> node_1 = Node() >>> node_2 = Node() >>> node.connect(Connection, node_1, 2) >>> node.connect(Connection, node_2, 14) >>> online_state = node.state.online >>> online_state.get_outgoing_neighbors_by_connection_data( >>> predicate=lambda x: x < 10 >>> if isinstance(x, int) else False, >>> ) { node_1 }
- get_outgoing_neighbors_by_connection_type(type_: type[Connection]) set[Node]#
Get nodes with outgoing connections of the given types.
Parameters#
- type_: type[Connection]
Type of the connection to look at.
- get_outgoing_neighbors_by_node_data(predicate: Callable[[__annotationlib_name_1__], __annotationlib_name_2__]) set[Node[__annotationlib_name_3__]]#
Get outgoing linked nodes with data respecting a given filter.
The filter function will be applied to the data of every nodes connected to this node. If the filter return true, the node is included in the returned set.
Parameters#
- predicate: Callable[[T | None], bool]
Filter function, determine if the connected Node is kept.
Examples#
>>> node = Node() >>> node_1 = Node(data=5) >>> node_2 = Node(data=12) >>> node.connect(Connection, node_1) >>> node.connect(Connection, node_2) >>> online_state = node.state.online >>> online_state.get_outgoing_neighbors_by_node_data( >>> filter=lambda x: x < 9 if isinstance(x, int) else False, >>> ) { node_1 }
- get_outgoing_neighbors_by_node_type(type_: type) set[Node]#
Get outgoing linked node with a given type.
Parameters#
- type_: type[Node]
Type of the node to look at.
- is_online() bool#
Check if the Node is associated to a Graph.