Skip to content

BaseHypergraphDB Class

hyperdb.base.BaseHypergraphDB dataclass

BaseHypergraphDB(
    storage_file: Union[str, Path] = "my_hypergraph.hgdb",
)

Base class for hypergraph database.

Attributes

storage_file class-attribute instance-attribute

storage_file: Union[str, Path] = field(
    default="my_hypergraph.hgdb", compare=False
)

all_v cached property

all_v: List[str]

Return a list of all vertices in the hypergraph.

all_e cached property

all_e: List[Tuple]

Return a list of all hyperedges in the hypergraph.

num_v cached property

num_v: int

Return the number of vertices in the hypergraph.

num_e cached property

num_e: int

Return the number of hyperedges in the hypergraph.

Functions

save

save(file_path: Union[str, Path])

Save the hypergraph to a file.

Args: file_path (Union[str, Path]): The file path to save the hypergraph.

Source code in hyperdb/base.py
def save(self, file_path: Union[str, Path]):
    r"""
    Save the hypergraph to a file.

    Args:
        ``file_path`` (``Union[str, Path]``): The file path to save the hypergraph.
    """
    raise NotImplementedError

save_as

save_as(format: str, file_path: Union[str, Path])

Save the hypergraph to a specific format.

Args: format (str): The export format (e.g., "json", "csv", "graphml"). file_path (Union[str, Path]): The file path to export the hypergraph.

Source code in hyperdb/base.py
def save_as(self, format: str, file_path: Union[str, Path]):
    r"""
    Save the hypergraph to a specific format.

    Args:
        ``format`` (``str``): The export format (e.g., "json", "csv", "graphml").
        ``file_path`` (``Union[str, Path]``): The file path to export the hypergraph.
    """
    raise NotImplementedError

load staticmethod

load(file_path: Union[str, Path])

Load the hypergraph from a file.

Args: file_path (Union[str, Path]): The file path to load the hypergraph from.

Source code in hyperdb/base.py
@staticmethod
def load(self, file_path: Union[str, Path]):
    r"""
    Load the hypergraph from a file.

    Args:
        ``file_path`` (``Union[str, Path]``): The file path to load the hypergraph from.
    """
    raise NotImplementedError

load_from

load_from(format: str, file_path: Union[str, Path])

Load a hypergraph from a specific format.

Args: format (str): The import format (e.g., "json", "csv", "graphml"). file_path (Union[str, Path]): The file path to import the hypergraph from.

Source code in hyperdb/base.py
def load_from(self, format: str, file_path: Union[str, Path]):
    r"""
    Load a hypergraph from a specific format.

    Args:
        ``format`` (``str``): The import format (e.g., "json", "csv", "graphml").
        ``file_path`` (``Union[str, Path]``): The file path to import the hypergraph from.
    """
    raise NotImplementedError

v

v(v_id: Any, default: Any = None) -> dict

Return the vertex data.

Args: v_id (Any): The vertex id. default (Any): The default value if the vertex does not exist.

Source code in hyperdb/base.py
def v(self, v_id: Any, default: Any = None) -> dict:
    r"""
    Return the vertex data.

    Args:
        ``v_id`` (``Any``): The vertex id.
        ``default`` (``Any``): The default value if the vertex does not exist.
    """
    raise NotImplementedError

e

e(
    e_tuple: Union[List, Set, Tuple], default: Any = None
) -> dict

Return the hyperedge data.

Args: e_tuple (Union[List, Set, Tuple]): The hyperedge tuple: (v1_name, v2_name, ..., vn_name). default (Any): The default value if the hyperedge does not exist.

Source code in hyperdb/base.py
def e(self, e_tuple: Union[List, Set, Tuple], default: Any = None) -> dict:
    r"""
    Return the hyperedge data.

    Args:
        ``e_tuple`` (``Union[List, Set, Tuple]``): The hyperedge tuple: (v1_name, v2_name, ..., vn_name).
        ``default`` (``Any``): The default value if the hyperedge does not exist.
    """
    raise NotImplementedError

encode_e

encode_e(e_tuple: Union[List, Set, Tuple]) -> Tuple

Sort and check the hyperedge tuple.

Args: e_tuple (Union[List, Set, Tuple]): The hyperedge tuple: (v1_name, v2_name, ..., vn_name).

Source code in hyperdb/base.py
def encode_e(self, e_tuple: Union[List, Set, Tuple]) -> Tuple:
    r"""
    Sort and check the hyperedge tuple.

    Args:
        ``e_tuple`` (``Union[List, Set, Tuple]``): The hyperedge tuple: (v1_name, v2_name, ..., vn_name).
    """
    raise NotImplementedError

add_v

add_v(v_id: Any, v_data: Optional[Dict] = None)

Add a vertex to the hypergraph.

Args: v_id (Any): The vertex id. v_data (Dict, optional): The vertex data. Defaults to None.

Source code in hyperdb/base.py
def add_v(self, v_id: Any, v_data: Optional[Dict] = None):
    r"""
    Add a vertex to the hypergraph.

    Args:
        ``v_id`` (``Any``): The vertex id.
        ``v_data`` (``Dict``, optional): The vertex data. Defaults to None.
    """
    raise NotImplementedError

add_e

add_e(e_tuple: Tuple, e_data: Optional[Dict] = None)

Add a hyperedge to the hypergraph.

Args: e_tuple (Tuple): The hyperedge tuple: (v1_name, v2_name, ..., vn_name). e_data (Dict, optional): The hyperedge data.

Source code in hyperdb/base.py
def add_e(self, e_tuple: Tuple, e_data: Optional[Dict] = None):
    r"""
    Add a hyperedge to the hypergraph.

    Args:
        ``e_tuple`` (``Tuple``): The hyperedge tuple: (v1_name, v2_name, ..., vn_name).
        ``e_data`` (``Dict``, optional): The hyperedge data.
    """
    raise NotImplementedError

remove_v

remove_v(v_id: Any)

Remove a vertex from the hypergraph.

Args: v_id (Any): The vertex id.

Source code in hyperdb/base.py
def remove_v(self, v_id: Any):
    r"""
    Remove a vertex from the hypergraph.

    Args:
        ``v_id`` (``Any``): The vertex id.
    """
    raise NotImplementedError

remove_e

remove_e(e_tuple: Tuple)

Remove a hyperedge from the hypergraph.

Args: e_tuple (Tuple): The hyperedge tuple: (v1_name, v2_name, ..., vn_name).

Source code in hyperdb/base.py
def remove_e(self, e_tuple: Tuple):
    r"""
    Remove a hyperedge from the hypergraph.

    Args:
        ``e_tuple`` (``Tuple``): The hyperedge tuple: (v1_name, v2_name, ..., vn_name).
    """
    raise NotImplementedError

update_v

update_v(v_id: Any)

Update the vertex data.

Args: v_id (Any): The vertex id.

Source code in hyperdb/base.py
def update_v(self, v_id: Any):
    r"""
    Update the vertex data.

    Args:
        ``v_id`` (``Any``): The vertex id.
    """
    raise NotImplementedError

update_e

update_e(e_tuple: Tuple)

Update the hyperedge data.

Args: e_tuple (Tuple): The hyperedge tuple: (v1_name, v2_name, ..., vn_name).

Source code in hyperdb/base.py
def update_e(self, e_tuple: Tuple):
    r"""
    Update the hyperedge data.

    Args:
        ``e_tuple`` (``Tuple``): The hyperedge tuple: (v1_name, v2_name, ..., vn_name).
    """
    raise NotImplementedError

has_v

has_v(v_id: Any) -> bool

Return True if the vertex exists in the hypergraph.

Args: v_id (Any): The vertex id.

Source code in hyperdb/base.py
def has_v(self, v_id: Any) -> bool:
    r"""
    Return True if the vertex exists in the hypergraph.

    Args:
        ``v_id`` (``Any``): The vertex id.
    """
    raise NotImplementedError

has_e

has_e(e_tuple: Tuple) -> bool

Return True if the hyperedge exists in the hypergraph.

Args: e_tuple (Tuple): The hyperedge tuple: (v1_name, v2_name, ..., vn_name).

Source code in hyperdb/base.py
def has_e(self, e_tuple: Tuple) -> bool:
    r"""
    Return True if the hyperedge exists in the hypergraph.

    Args:
        ``e_tuple`` (``Tuple``): The hyperedge tuple: (v1_name, v2_name, ..., vn_name).
    """
    raise NotImplementedError

degree_v

degree_v(v_id: Any) -> int

Return the degree of the vertex.

Args: v_id (Any): The vertex id.

Source code in hyperdb/base.py
def degree_v(self, v_id: Any) -> int:
    r"""
    Return the degree of the vertex.

    Args:
        ``v_id`` (``Any``): The vertex id.
    """
    raise NotImplementedError

degree_e

degree_e(e_tuple: Tuple) -> int

Return the degree of the hyperedge.

Args: e_tuple (Tuple): The hyperedge tuple: (v1_name, v2_name, ..., vn_name).

Source code in hyperdb/base.py
def degree_e(self, e_tuple: Tuple) -> int:
    r"""
    Return the degree of the hyperedge.

    Args:
        ``e_tuple`` (``Tuple``): The hyperedge tuple: (v1_name, v2_name, ..., vn_name).
    """
    raise NotImplementedError

nbr_e_of_v

nbr_e_of_v(v_id: Any) -> list

Return the hyperedge neighbors of the vertex.

Args: v_id (Any): The vertex id.

Source code in hyperdb/base.py
def nbr_e_of_v(self, v_id: Any) -> list:
    r"""
    Return the hyperedge neighbors of the vertex.

    Args:
        ``v_id`` (``Any``): The vertex id.
    """
    raise NotImplementedError

nbr_v_of_e

nbr_v_of_e(e_tuple: Tuple) -> list

Return the vertex neighbors of the hyperedge.

Args: e_tuple (Tuple): The hyperedge tuple: (v1_name, v2_name, ..., vn_name).

Source code in hyperdb/base.py
def nbr_v_of_e(self, e_tuple: Tuple) -> list:
    r"""
    Return the vertex neighbors of the hyperedge.

    Args:
        ``e_tuple`` (``Tuple``): The hyperedge tuple: (v1_name, v2_name, ..., vn_name).
    """
    raise NotImplementedError

nbr_v

nbr_v(v_id: Any) -> list

Return the vertex neighbors of the vertex.

Args: v_id (Any): The vertex id.

Source code in hyperdb/base.py
def nbr_v(self, v_id: Any) -> list:
    r"""
    Return the vertex neighbors of the vertex.

    Args:
        ``v_id`` (``Any``): The vertex id.
    """
    raise NotImplementedError

sub

sub(v_name_list: List[str])

Return the sub-hypergraph.

Args: v_name_list (List[str]): The list of vertex ids.

Source code in hyperdb/base.py
def sub(self, v_name_list: List[str]):
    r"""
    Return the sub-hypergraph.

    Args:
        ``v_name_list`` (``List[str]``): The list of vertex ids.
    """
    raise NotImplementedError

sub_from_v

sub_from_v(v_id: Any, depth: int)

Return the sub-hypergraph from the vertex.

Args: v_id (Any): The vertex id. depth (int): The depth of the sub-hypergraph.

Source code in hyperdb/base.py
def sub_from_v(self, v_id: Any, depth: int):
    r"""
    Return the sub-hypergraph from the vertex.

    Args:
        ``v_id`` (``Any``): The vertex id.
        ``depth`` (``int``): The depth of the sub-hypergraph.
    """
    raise NotImplementedError

query_v

query_v(filters: Dict[str, Any]) -> List[str]

Query and return vertices that match the given filters.

Args: filters (Dict[str, Any]): A dictionary of conditions to filter vertices.

Source code in hyperdb/base.py
def query_v(self, filters: Dict[str, Any]) -> List[str]:
    r"""
    Query and return vertices that match the given filters.

    Args:
        ``filters`` (``Dict[str, Any]``): A dictionary of conditions to filter vertices.
    """
    raise NotImplementedError

query_e

query_e(filters: Dict[str, Any]) -> List[Tuple]

Query and return hyperedges that match the given filters.

Args: filters (Dict[str, Any]): A dictionary of conditions to filter hyperedges.

Source code in hyperdb/base.py
def query_e(self, filters: Dict[str, Any]) -> List[Tuple]:
    r"""
    Query and return hyperedges that match the given filters.

    Args:
        ``filters`` (``Dict[str, Any]``): A dictionary of conditions to filter hyperedges.
    """
    raise NotImplementedError

stats

stats() -> dict

Return basic statistics of the hypergraph.

Source code in hyperdb/base.py
def stats(self) -> dict:
    r"""
    Return basic statistics of the hypergraph.
    """
    raise NotImplementedError

draw

draw(
    port: int = 8080,
    open_browser: bool = True,
    blocking: bool = True,
)

Draw the hypergraph data of the current HyperDB instance

Args:
port: Server port number, defaults to 8080
open_browser: Whether to automatically open the browser, defaults to True blocking: Whether to block the main thread, defaults to True. Set to False for non-blocking mode.

Returns: HypergraphViewer instance

Source code in hyperdb/base.py
def draw(self, port: int = 8080, open_browser: bool = True, blocking: bool = True):
    """
    Draw the hypergraph data of the current HyperDB instance

    Args:  
        ``port``: Server port number, defaults to 8080  
        ``open_browser``: Whether to automatically open the browser, defaults to True
        ``blocking``: Whether to block the main thread, defaults to True. Set to False for non-blocking mode.

    Returns:
        HypergraphViewer instance
    """
    from .draw import draw_hypergraph

    return draw_hypergraph(
        hypergraph_db=self,
        port=port,
        open_browser=open_browser,
        blocking=blocking
    )