trudag.dotstop.core.graph.base_graph
BaseGraph
Bases: ABC
A base abstract class that describes abstract methods that must be implemented for a class to serve as the backend for TrustableGraph.
add_edge
abstractmethod
Add the edge parent_id -> child_id to the graph.
adjacency_matrix
The unweighted adjacency matrix of the graph.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
node_order
|
Iterable[str]
|
The order of nodes in the adjacency matrix. |
required |
edges
abstractmethod
Returns all edges in the graph.
Returns:
| Type | Description |
|---|---|
list[tuple[str, str]]
|
A list of tuples representing edges where the first element is the source node and the second element is the destination node. |
empty
abstractmethod
classmethod
empty() -> BaseGraph
Create an instance of BaseGraph with no nodes or edges.
from_file
abstractmethod
classmethod
from_file(path: Path) -> BaseGraph
Construct an instance of BaseGraph from a file.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
path
|
Path
|
Path to file to build graph from |
required |
from_string
abstractmethod
classmethod
from_string(src: str) -> BaseGraph
Construct an instance of BaseGraph from a string source.
get_edge_attr
abstractmethod
Get the attribute associated with key from edge parent_id -> child_id.
Returns:
| Type | Description |
|---|---|
Attribute
|
String if attribute exists, otherwise None. |
get_edge_attrs
abstractmethod
Get all attributes of edge parent_id -> child_id.
get_graph_attr
abstractmethod
Get the attribute associated with key from graph.
Returns:
| Type | Description |
|---|---|
Attribute
|
String if value exists, otherwise None |
get_graph_attrs
abstractmethod
Get all attributes for graph.
get_node_attr
abstractmethod
Get the attribute associated with key from node with node_id.
Returns:
| Type | Description |
|---|---|
Attribute
|
String if value exists, otherwise None |
get_node_attrs
abstractmethod
Get all attributes for node with node_id.
has_edge
abstractmethod
True if the edge parent_id -> child_id exists in the graph.
predecessors
Returns nodes which have an outgoing edge to the specified node.
remove_edge
abstractmethod
Remove the edge parent_id -> child_id from the graph.
remove_node
abstractmethod
Remove a node with node_id from the graph.
set_edge_attrs
abstractmethod
Set the attributes for each key-value pair in attrs for edge parent_id -> child_id.
Attributes should operate like a dictionary, existing attributes are updated, new attributes are appended.
set_graph_attrs
abstractmethod
Set the attributes for each key-value pair in attrs for graph.
set_node_attrs
abstractmethod
Set the attributes for each key-value pair in attrs for node with node_id.
successors
Returns nodes which have an incoming edge from the specified node.