GraphAdapter
GraphAdapter()Abstract base class providing a unified API to any graph engine.
A node or edge that is not on the graph is a GraphError from every method that takes one, except get_node, which answers None for an unknown id. Backend exceptions never pass through the adapter boundary.
Methods
| Name | Description |
|---|---|
| add_node | Add a node to the graph. |
| add_edge | Add an edge from source to target to the graph. |
| remove_node | Remove a node (and its incident edges) from the graph. |
| remove_edge | Remove an edge from the graph. |
| get_node | Return the node with the given id, or None if there is no such node. |
| get_edge | Return the edge of the given type from source to target; raises GraphError if there is none. |
| filter_edges | Returns a list of all edges for which filter_function(edge) returns True. |
| filter_nodes | Returns a list of all nodes for which filter_function(node) returns True. |
| get_edge_endpoints | Return the source and target nodes of the given edge as a tuple (source, target). |
| get_source_of_edge | Return the source node of the given edge. |
| get_target_of_edge | Return the target node of the given edge. |
| has_node | Return True if node is present in the graph. |
| has_edge | Return True if an edge (optionally of the given type) exists from source to target. |
| num_nodes | Return the total number of nodes in the graph. |
| num_edges | Return the total number of edges in the graph. |
| nodes | Iterate over nodes, optionally filtered by node_type and/or predicate. |
| edges | Iterate over edges, optionally filtered by edge_type and/or predicate. |
| edges_between | Iterate over edges from source to target, optionally filtered by edge_type. |
| successors | Iterate over nodes reachable from node via an outgoing edge, optionally filtered. |
| predecessors | Iterate over nodes that have an outgoing edge to node, optionally filtered. |
| get_next | Return the next node connected by an edge of type NEXT from the given node, if it exists. |
| get_previous | Return the previous node connected by an edge of type NEXT to the given node, if it exists. |
| neighbors | Iterate over all nodes adjacent to node (predecessors and successors), optionally filtered. |
| out_edges | Iterate over edges originating from node, optionally filtered by edge_type. |
| in_edges | Iterate over edges terminating at node, optionally filtered by edge_type. |
| incident_edges | Iterate over all edges touching node (incoming and outgoing), optionally filtered by edge_type. |
| degree | Return the total number of edges incident to node. |
| in_degree | Return the number of edges terminating at node. |
| out_degree | Return the number of edges originating from node. |
add_node
add_node(node: OmkObject)Add a node to the graph.
add_edge
add_edge(source: OmkObject, target: OmkObject, edge: OmkEdge)Add an edge from source to target to the graph.
Raises GraphError if there is already an edge of the same type between source and target, or if the edge is a NEXT and the source already has one out or the target one in.
remove_node
remove_node(node: OmkObject)Remove a node (and its incident edges) from the graph.
remove_edge
remove_edge(edge: OmkEdge)Remove an edge from the graph.
get_node
get_node(node_id: UUID | str)Return the node with the given id, or None if there is no such node.
get_edge
get_edge(source: OmkObject, target: OmkObject, edge_type: EdgeType)Return the edge of the given type from source to target; raises GraphError if there is none.
filter_edges
filter_edges(filter_function: Callable[[OmkEdge], bool])Returns a list of all edges for which filter_function(edge) returns True.
filter_nodes
filter_nodes(filter_function: Callable[[OmkObject], bool])Returns a list of all nodes for which filter_function(node) returns True.
get_edge_endpoints
get_edge_endpoints(edge: OmkEdge)Return the source and target nodes of the given edge as a tuple (source, target).
get_source_of_edge
get_source_of_edge(edge: OmkEdge)Return the source node of the given edge.
get_target_of_edge
get_target_of_edge(edge: OmkEdge)Return the target node of the given edge.
has_node
has_node(node: OmkObject)Return True if node is present in the graph.
has_edge
has_edge(
source: OmkObject,
target: OmkObject,
edge_type: EdgeType | None = None,
)Return True if an edge (optionally of the given type) exists from source to target.
num_nodes
num_nodes()Return the total number of nodes in the graph.
num_edges
num_edges()Return the total number of edges in the graph.
nodes
nodes(
node_type: type[OmkObject] | None = None,
predicate: Callable[[OmkObject], bool] | None = None,
)Iterate over nodes, optionally filtered by node_type and/or predicate.
edges
edges(
edge_type: EdgeType | None = None,
predicate: Callable[[OmkEdge], bool] | None = None,
)Iterate over edges, optionally filtered by edge_type and/or predicate.
edges_between
edges_between(
source: OmkObject,
target: OmkObject,
edge_type: EdgeType | None = None,
)Iterate over edges from source to target, optionally filtered by edge_type.
successors
successors(
node: OmkObject,
node_type: type[OmkObject] | None = None,
edge_type: EdgeType | None = None,
predicate: Callable[[OmkObject], bool] | None = None,
)Iterate over nodes reachable from node via an outgoing edge, optionally filtered.
predecessors
predecessors(
node: OmkObject,
node_type: type[OmkObject] | None = None,
edge_type: EdgeType | None = None,
predicate: Callable[[OmkObject], bool] | None = None,
)Iterate over nodes that have an outgoing edge to node, optionally filtered.
get_next
get_next(node: OmkObject)Return the next node connected by an edge of type NEXT from the given node, if it exists.
get_previous
get_previous(node: OmkObject)Return the previous node connected by an edge of type NEXT to the given node, if it exists.
neighbors
neighbors(
node: OmkObject,
node_type: type[OmkObject] | None = None,
edge_type: EdgeType | None = None,
predicate: Callable[[OmkObject], bool] | None = None,
)Iterate over all nodes adjacent to node (predecessors and successors), optionally filtered.
out_edges
out_edges(node: OmkObject, edge_type: EdgeType | None = None)Iterate over edges originating from node, optionally filtered by edge_type.
in_edges
in_edges(node: OmkObject, edge_type: EdgeType | None = None)Iterate over edges terminating at node, optionally filtered by edge_type.
incident_edges
incident_edges(node: OmkObject, edge_type: EdgeType | None = None)Iterate over all edges touching node (incoming and outgoing), optionally filtered by edge_type.
degree
degree(node: OmkObject)Return the total number of edges incident to node.
in_degree
in_degree(node: OmkObject)Return the number of edges terminating at node.
out_degree
out_degree(node: OmkObject)Return the number of edges originating from node.