ragraph.node
#
Node module. Contains Node class definitions.
Module Contents#
Classes#
Generic node class. |
- class ragraph.node.Node(name: Optional[str] = None, parent: Optional[Node] = None, children: Optional[Iterable[Node]] = None, is_bus: bool = False, kind: str = 'node', labels: Optional[List[str]] = None, weights: Optional[Dict[str, Union[int, float]]] = None, annotations: Union[ragraph.generic.Annotations, Dict[str, Any], None] = None, uuid: Optional[Union[str, uuid.UUID]] = None)#
Bases:
ragraph.generic.Metadata
Generic node class.
- Parameters:
name – Instance name. Given a UUID if none provided.
parent – Parent node.
children – List of child nodes.
kind – Kind or main category of this instance.
labels – Labels categorizing this instance.
weights – Dictionary of weights attached to this instance.
annotations – Miscellaneous properties of this instance.
uuid – Fixed UUID if desired, generated when left set to None.
- property is_bus#
Whether this node is a bus node for its parent.
- property depth: int#
Depth of this node, e.g. the number of levels from the node to the root.
- property height: int#
Height of this node, e.g. the longest simple path to a leaf node.
- property width: int#
Width of this node, e.g. the number of leaf nodes in this node’s branch.
- property is_leaf: bool#
Whether this node is a leaf node (has no children).
- property is_root: bool#
Whether this node is a root node (has no parent).
- property json_dict: Dict[str, Any]#
JSON dictionary representation.
- Returns:
Name as str. parent: Parent name (not Node) as str. children: Children names (not Nodes) as str. is_bus: is_bus as bool. kind: Kind as str. labels: Labels as a list of strings. weights: Weights as dict. annotations: Annotations as per
ragraph.generic.Mapping.as_dict()
.- Return type:
name
- __str__() str #
Return str(self).
- __repr__() str #
Return repr(self).
- as_dict(use_uuid: bool = False) Dict[str, Any] #
Return a copy as a (serializable) dictionary.
- Returns:
Name as str. parent: Parent name or UUID (not Node) as str. children: Children names (not Nodes) as str. is_bus: is_bus as bool. kind: Kind as str. labels: Labels as a list of strings. weights: Weights as dict. annotations: Annotations as per
ragraph.generic.Mapping.as_dict()
. uuid: UUID as str if toggled.- Return type:
name