Skip to content

ragraph.edge

Edge class module

Edge

Edge(
    source: Node,
    target: Node,
    name: Optional[str] = None,
    kind: str = "edge",
    labels: Optional[List[str]] = None,
    weights: Optional[Dict[str, Union[int, float]]] = None,
    annotations: Union[
        Annotations, Dict[str, Any], None
    ] = None,
    uuid: Optional[Union[str, UUID]] = None,
)

Bases: Metadata

Edge between a source Node and a target Node.

Parameters:

Name Type Description Default
source Node

Source Node of this edge.

required
target Node

Target Node of this edge.

required
name Optional[str]

Instance name. Given a UUID if none provided.

None
kind str

Kind or main category of this instance.

'edge'
labels Optional[List[str]]

Labels categorizing this instance.

None
weights Optional[Dict[str, Union[int, float]]]

Dictionary of weights attached to this instance.

None
annotations Union[Annotations, Dict[str, Any], None]

Miscellaneous properties of this instance.

None
uuid Optional[Union[str, UUID]]

Fixed UUID if desired, generated when left set to None.

None
Source code in ragraph/edge.py
def __init__(
    self,
    source: Node,
    target: Node,
    name: Optional[str] = None,
    kind: str = "edge",
    labels: Optional[List[str]] = None,
    weights: Optional[Dict[str, Union[int, float]]] = None,
    annotations: Union[Annotations, Dict[str, Any], None] = None,
    uuid: Optional[Union[str, UUID]] = None,
):
    Metadata.__init__(
        self,
        name=name,
        kind=kind,
        labels=labels,
        weights=weights,
        annotations=annotations,
        uuid=uuid,
    )
    self._source: Node
    self._target: Node
    setattr(self, "source", source)
    setattr(self, "target", target)

json_dict property

json_dict: Dict[str, Any]

JSON dictionary representation.

Returns:

Name Type Description
source Dict[str, Any]

Source node UUID (not Node) as str.

target Dict[str, Any]

Target node UUID (not Node) as str.

kind Dict[str, Any]

Kind as str.

labels Dict[str, Any]

Labels as list of str.

weights Dict[str, Any]

Weights as dict.

annotations Dict[str, Any]

Annotations as a dictionary.

source property writable

source: Node

Edge source node.

target property writable

target: Node

Edge target node.

as_dict

as_dict(use_uuid: bool = False) -> Dict[str, Any]

Return a copy as a (serializable) dictionary.

Parameters:

Name Type Description Default
use_uuid bool

Whether to use UUIDs instead of names.

False

Returns:

Name Type Description
source Dict[str, Any]

Source node name or UUID (not Node) as str.

target Dict[str, Any]

Target node name or UUID (not Node) as str.

kind Dict[str, Any]

Kind as str.

labels Dict[str, Any]

Labels as list of str.

weights Dict[str, Any]

Weights as dict.

annotations Dict[str, Any]

Annotations as a dictionary.

uuid Dict[str, Any]

UUID as str if toggled.

Source code in ragraph/edge.py
def as_dict(self, use_uuid: bool = False) -> Dict[str, Any]:
    """Return a copy as a (serializable) dictionary.

    Arguments:
        use_uuid: Whether to use UUIDs instead of names.

    Returns:
        source: Source node name or UUID (not Node) as str.
        target: Target node name or UUID (not Node) as str.
        kind: Kind as str.
        labels: Labels as list of str.
        weights: Weights as dict.
        annotations: Annotations as a dictionary.
        uuid: UUID as str if toggled.
    """
    if use_uuid:
        return dict(
            source=str(self.source.uuid),
            target=str(self.target.uuid),
            name=self.name,
            kind=self.kind,
            labels=self.labels,
            weights=self.weights,
            annotations=self.annotations.as_dict(),
            uuid=str(self.uuid),
        )
    else:
        return dict(
            source=self.source.name,
            target=self.target.name,
            name=self.name,
            kind=self.kind,
            labels=self.labels,
            weights=self.weights,
            annotations=self.annotations.as_dict(),
        )