HypergraphDB Class¶
hyperdb.hypergraph.HypergraphDB
dataclass
¶
HypergraphDB(
storage_file: Union[str, Path] = "my_hypergraph.hgdb",
_v_data: Dict[Any, Any] = dict(),
_e_data: Dict[Tuple, Any] = dict(),
_v_inci: Dict[Any, Set[Tuple]] = (
lambda: defaultdict(set)
)(),
)
Bases: BaseHypergraphDB
Hypergraph database.
Attributes¶
Functions¶
__post_init__ ¶
load ¶
Load the hypergraph database from the storage file.
Source code in hyperdb/hypergraph.py
save ¶
Save the hypergraph database to the storage file.
Source code in hyperdb/hypergraph.py
v ¶
Return the vertex data.
Args:
v_id (str): The vertex id.
default (Any): The default value if the vertex does not exist.
Source code in hyperdb/hypergraph.py
e ¶
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/hypergraph.py
encode_e ¶
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/hypergraph.py
add_v ¶
Add a vertex to the hypergraph.
Args:
v_id (Any): The vertex id.
v_data (dict, optional): The vertex data.
Source code in hyperdb/hypergraph.py
add_e ¶
Add a hyperedge to the hypergraph.
Args:
e_tuple (Union[List, Set, Tuple]): The hyperedge tuple: (v1_name, v2_name, ..., vn_name).
e_data (dict, optional): The hyperedge data.
Source code in hyperdb/hypergraph.py
remove_v ¶
Remove a vertex from the hypergraph.
Args:
v_id (Any): The vertex id.
Source code in hyperdb/hypergraph.py
remove_e ¶
Remove a hyperedge from the hypergraph.
Args:
e_tuple (Union[List, Set, Tuple]): The hyperedge tuple: (v1_name, v2_name, ..., vn_name).
Source code in hyperdb/hypergraph.py
update_v ¶
Update the vertex data.
Args:
v_id (Any): The vertex id.
v_data (dict): The vertex data.
Source code in hyperdb/hypergraph.py
update_e ¶
Update the hyperedge data.
Args:
e_tuple (Union[List, Set, Tuple]): The hyperedge tuple: (v1_name, v2_name, ..., vn_name).
e_data (dict): The hyperedge data.
Source code in hyperdb/hypergraph.py
has_v ¶
Check if the vertex exists.
Args:
v_id (Any): The vertex id.
has_e ¶
Check if the hyperedge exists.
Args:
e_tuple (Union[List, Set, Tuple]): The hyperedge tuple: (v1_name, v2_name, ..., vn_name).
Source code in hyperdb/hypergraph.py
degree_v ¶
Return the degree of the vertex.
Args:
v_id (Any): The vertex id.
Source code in hyperdb/hypergraph.py
degree_e ¶
Return the degree of the hyperedge.
Args:
e_tuple (Union[List, Set, Tuple]): The hyperedge tuple: (v1_name, v2_name, ..., vn_name).
Source code in hyperdb/hypergraph.py
nbr_e_of_v ¶
Return the incident hyperedges of the vertex.
Args:
v_id (Any): The vertex id.
Source code in hyperdb/hypergraph.py
nbr_v_of_e ¶
Return the incident vertices of the hyperedge.
Args:
e_tuple (Union[List, Set, Tuple]): The hyperedge tuple: (v1_name, v2_name, ..., vn_name).
Source code in hyperdb/hypergraph.py
nbr_v ¶
Return the neighbors of the vertex.
Args:
v_id (Any): The vertex id.
Source code in hyperdb/hypergraph.py
to_hif ¶
Export the hypergraph to HIF (Hypergraph Interchange Format) format.
Args:
file_path (Union[str, Path], optional): If provided, save to file. Otherwise return dict.
Returns:
Dict[str, Any]: HIF format dictionary.
Source code in hyperdb/hypergraph.py
341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 | |
save_as_hif ¶
Save the hypergraph to HIF format JSON file.
Args:
file_path (Union[str, Path]): The file path to save the HIF file.
Returns:
bool: True if successful, False otherwise.
Source code in hyperdb/hypergraph.py
from_hif ¶
Load hypergraph from HIF format data.
Args:
hif_data (Union[str, Path, Dict]): HIF data as dict, file path, or JSON string.
Returns:
bool: True if successful, False otherwise.
Source code in hyperdb/hypergraph.py
456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 | |
load_from_hif ¶
Load hypergraph from HIF format JSON file.
Args:
file_path (Union[str, Path]): The file path to load the HIF file from.
Returns:
bool: True if successful, False otherwise.