Skip to content

Interlinks

Proxy for linking.

Source code in abses/links.py
def __init__(self, node: LinkingNode, model: MainModel) -> None:
    self.node: LinkingNode = node
    self.model: MainModel = model
    self.human: _LinkContainer = model.human

owning

owning(direction=None)

Links that this object has.

Parameters:

Name Type Description Default
direction Direction

The direction of the link ('in' or 'out'). If None, return both out links and in links.

None

Returns:

Type Description
Tuple[str, ...]

The links that this object has.

Source code in abses/links.py
def owning(self, direction: Direction = None) -> Tuple[str, ...]:
    """Links that this object has.

    Parameters:
        direction:
            The direction of the link ('in' or 'out').
            If None, return both out links and in links.

    Returns:
        The links that this object has.
    """
    return self.human.owns_links(self.node, direction=direction)

get

get(link_name=None, direction='out', default=False)

Get the linked nodes.

Source code in abses/links.py
def get(
    self,
    link_name: Optional[str] = None,
    direction: Direction = "out",
    default: bool = False,
) -> ActorsList[LinkingNode]:
    """Get the linked nodes."""
    agents = self.human.linked(
        self.node, link_name, direction=direction, default=default
    )
    return ActorsList(self.model, agents)

has

has(link_name, node=None)

Check if the node has the link.

Parameters:

Name Type Description Default
link_name str

The name of the link.

required
node Optional[LinkingNode]

The node to check if it has the link with the current node. If None, check if the current node has any link.

None

Returns:

Name Type Description
tuple Tuple[bool, bool]

A tuple of two booleans. The first element is True if the link exists from me to other. The second element is True if the link exists from other to me.

Source code in abses/links.py
def has(
    self, link_name: str, node: Optional[LinkingNode] = None
) -> Tuple[bool, bool]:
    """Check if the node has the link.

    Parameters:
        link_name:
            The name of the link.
        node:
            The node to check if it has the link with the current node.
            If None, check if the current node has any link.

    Returns:
        tuple:
            A tuple of two booleans.
            The first element is True if the link exists from me to other.
            The second element is True if the link exists from other to me.
    """
    if node is None:
        has_in = link_name in self.owning("in")
        has_out = link_name in self.owning("out")
        return has_out, has_in
    return self.human.has_link(link_name, self.node, node)

to

to(node, link_name, mutual=False)

Link to another node.

Parameters:

Name Type Description Default
node LinkingNode

The node to link to.

required
link_name str

The name of the link.

required
mutual bool

If the link is mutual. Defaults to False.

False
Source code in abses/links.py
def to(
    self, node: LinkingNode, link_name: str, mutual: bool = False
) -> None:
    """Link to another node.

    Parameters:
        node:
            The node to link to.
        link_name:
            The name of the link.
        mutual:
            If the link is mutual. Defaults to False.
    """
    self.human.add_a_link(
        link_name=link_name, source=self.node, target=node, mutual=mutual
    )

by

by(node, link_name, mutual=False)

Make this node linked by another node.

Parameters:

Name Type Description Default
node LinkingNode

The node to link by.

required
link_name str

The name of the link.

required
mutual bool

If the link is mutual. Defaults to False.

False
Source code in abses/links.py
def by(
    self, node: LinkingNode, link_name: str, mutual: bool = False
) -> None:
    """Make this node linked by another node.

    Parameters:
        node:
            The node to link by.
        link_name:
            The name of the link.
        mutual:
            If the link is mutual. Defaults to False.
    """
    self.human.add_a_link(
        link_name=link_name, source=node, target=self.node, mutual=mutual
    )
unlink(node, link_name, mutual=False)

Remove the link between me and another node.

Parameters:

Name Type Description Default
node LinkingNode

The node to unlink with.

required
link_name str

The name of the link.

required
mutual bool

If delete link mutually. Defaults to False.

False

Raises:

Type Description
ABSESpyError

If the link from source to target does not exist.

Source code in abses/links.py
def unlink(self, node: LinkingNode, link_name: str, mutual: bool = False):
    """Remove the link between me and another node.

    Parameters:
        node:
            The node to unlink with.
        link_name:
            The name of the link.
        mutual:
            If delete link mutually. Defaults to False.

    Raises:
        ABSESpyError:
            If the link from source to target does not exist.
    """
    self.human.remove_a_link(
        link_name=link_name, source=self.node, target=node, mutual=mutual
    )

clean

clean(link_name=None, direction=None)

Clean all the related links from this node.

Parameters:

Name Type Description Default
link_name Optional[str]

The name of the link. If None, clean all related links for the node.

None
direction Direction

The direction of the link ('in' or 'out'). If None, clean both directions (both out links and in links).

None

Raises:

Type Description
ValueError

If the direction is not 'in' or 'out'.

Source code in abses/links.py
def clean(
    self, link_name: Optional[str] = None, direction: Direction = None
):
    """Clean all the related links from this node.

    Parameters:
        link_name:
            The name of the link.
            If None, clean all related links for the node.
        direction:
            The direction of the link ('in' or 'out').
            If None, clean both directions (both out links and in links).

    Raises:
        ValueError:
            If the direction is not 'in' or 'out'.
    """
    self.human.clean_links_of(
        self.node, link_name=link_name, direction=direction
    )