Skip to content

link

Bases: Memory

A memory that can have a parent and children Links, forming a hierarchical structure of interconnected memories.

The content can be either a [Notion][silverlingua.core.molecules.notion.Notion] or a [Memory][silverlingua.core.atoms.memory.Memory]. (You can still use the content as a string via str(link.content).)

content instance-attribute

content: Union[Notion, Memory]

parent class-attribute instance-attribute

parent: Optional[Link] = None

children class-attribute instance-attribute

children: List[Link] = Field(default_factory=list)

path property

path: List[Link]

Returns the path from the root to this Link.

root property

root: Link

Returns the root Link of this Link.

depth property

depth: int

Returns 1 based depth of this Link.

is_root property

is_root: bool

Returns whether this Link is a root Link.

is_leaf property

is_leaf: bool

Returns whether this Link is a leaf Link.

is_branch property

is_branch: bool

Returns whether this Link is a branch Link.

path_string property

path_string: str

Returns the path from the root to this Link as a string.

Example: "root>child>grandchild"

add_child

add_child(child: Link) -> None
Source code in src/SilverLingua/core/molecules/link.py
def add_child(self, child: "Link") -> None:
    self.children.append(child)
    child.parent = self

remove_child

remove_child(child: Link) -> None
Source code in src/SilverLingua/core/molecules/link.py
def remove_child(self, child: "Link") -> None:
    self.children.remove(child)
    child.parent = None