text
stringlengths
0
828
database.session.commit()"
4438,"def get_edge(self, source: Node, target: Node) -> Optional[Edge]:
""""""
Returns the edge connection the given nodes if such an edge exists.
Arguments:
source (Node): One of the endpoints of the queried edge.
target (Node): The other endpoint of the queried edge.
Returns:
Returns the edge connection the given nodes
or `None` if no such node exists.
""""""
return self.get_edge_by_index(source.index, target.index)"
4439,"def get_edge_by_index(self, source_index: int, target_index: int) -> Optional[Edge]:
""""""
Returns the edge connecting the nodes with the specified indices if such an edge exists.
Arguments:
source_index (int): The index of one of the endpoints of queried edge.
target_index (int): The index of the other endpoint of the queried edge.
Returns:
The edge connecting the nodes with the specified indices
or `None` if no such node exists.
""""""
edge = self._edges.get((source_index, target_index))
if edge is not None:
return edge
return self._edges.get((target_index, source_index))"
4440,"def get_edge_by_name(self, source_name: str, target_name: str) -> Optional[Edge]:
""""""
Returns the edge connecting the nodes with the specified names if such an edge exists.
Arguments:
source_name (str): The name of one of the endpoints of queried edge.
target_name (str): The name of the other endpoint of the queried edge.
Returns:
The edge connecting the nodes with the specified names
or `None` if no such node exists.
""""""
nodes: NodeList = self._graph.nodes
source: Optional[Node] = nodes.get_node_by_name(source_name)
if source is None:
return None
target: Optional[Node] = nodes.get_node_by_name(target_name)
if target is None:
return None
return self.get_edge_by_index(source.index, target.index)"
4441,"def add_edge(self, source: Node,
target: Node,
weight: float = 1,
save_to_cache: bool = True) -> None:
""""""
Adds an edge between the specified nodes of the graph.
Arguments:
source (Node): The source node of the edge to add.
target (Node): The target node of the edge to add.
weight (float): The weight of the edge.
save_to_cache (bool): Whether the edge should be saved to the local database. This
argument is necessary (and `False`) when we load edges from
the local cache.
""""""
if self._edges.get_edge(source, target) is not None:
return
self._edges.add_edge(
source=source,
target=target,
weight=weight,
save_to_cache=save_to_cache
)"
4442,"def add_edge_by_index(self, source_index: int, target_index: int,
weight: float, save_to_cache: bool = True) -> None:
""""""
Adds an edge between the nodes with the specified indices to the graph.
Arguments:
source_index (int): The index of the source node of the edge to add.
target_index (int): The index of the target node of the edge to add.
weight (float): The weight of the edge.
save_to_cache (bool): Whether the edge should be saved to the local database. This
argument is necessary (and `False`) when we load edges from
the local cache.
""""""
source: Node = self._nodes.get_node(source_index)
target: Node = self._nodes.get_node(target_index)
if source is None or target is None:
return
self.add_edge(
source=source,
target=target,
weight=weight,
save_to_cache=save_to_cache
)"
4443,"def add_node(self, node_name: str, external_id: Optional[str] = None) -> None:
""""""