feat: add HIF format support for hypergraph export and import#9
Merged
yifanfeng97 merged 1 commit intoiMoonLab:mainfrom Nov 5, 2025
Merged
feat: add HIF format support for hypergraph export and import#9yifanfeng97 merged 1 commit intoiMoonLab:mainfrom
yifanfeng97 merged 1 commit intoiMoonLab:mainfrom
Conversation
There was a problem hiding this comment.
Pull Request Overview
This PR adds support for HIF (Hypergraph Interchange Format) import/export functionality to the HypergraphDB class, enabling standardized data exchange with other hypergraph tools.
- Implements
to_hif(),save_as_hif(),from_hif(), andload_from_hif()methods for HIF format support - Adds comprehensive test coverage for HIF export/import, roundtrip conversion, and attribute preservation
- Updates documentation in README and API docs to describe the new HIF functionality
Reviewed Changes
Copilot reviewed 5 out of 5 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| hyperdb/hypergraph.py | Adds HIF format export/import methods with incidence-based format handling |
| tests/test_hypergraph.py | Adds three test functions covering HIF export/import, roundtrip, and attribute preservation |
| docs/api/index.md | Documents new HIF-related methods in persistence operations table |
| docs/api/index.zh.md | Chinese documentation for HIF functionality with usage examples |
| README.md | Adds HIF format save/load examples to the persistence section |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
|
|
||
| # Find edge in edges array | ||
| edge_12 = next( | ||
| (e for e in hif_data["edges"] if "1" in str(e["edge"]) and "2" in str(e["edge"])), |
There was a problem hiding this comment.
String-based edge matching is fragile and could produce false positives. For example, edge IDs '10_11' and '21_22' would both match when looking for edges containing '1' and '2'. Use exact comparison instead: if e['edge'] == '1_2' or set(str(e['edge']).split('_')) == {'1', '2'}.
Suggested change
| (e for e in hif_data["edges"] if "1" in str(e["edge"]) and "2" in str(e["edge"])), | |
| ( | |
| e | |
| for e in hif_data["edges"] | |
| if ( | |
| (isinstance(e["edge"], (tuple, list)) and set(e["edge"]) == {1, 2}) | |
| or | |
| (isinstance(e["edge"], str) and set(e["edge"].split("_")) == {"1", "2"}) | |
| ) | |
| ), |
| e_data = self._e_data[e_tuple] | ||
|
|
||
| # Extract attrs (all fields except weight) | ||
| e_attrs = {k: v for k, v in e_data.items() if k != "weight"} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
No description provided.