Skip to content

Hypergraph is more powerful. Transform unstructured text into structured knowledge with LLMs. Graphs, hypergraphs, and spatio-temporal extractions — with one command.

fix: honor relation_members field mapping and preserve edge direction

Frankie-Xu03d41ce3c4e3
diff --git a/hyperextract/templates/DESIGN_GUIDE.md b/hyperextract/templates/DESIGN_GUIDE.md
index 961d8cd..40084fd 100644
--- a/hyperextract/templates/DESIGN_GUIDE.md
+++ b/hyperextract/templates/DESIGN_GUIDE.md
@@ -571,6 +571,10 @@ identifiers:
target: target
```
+The dict values name the relation fields that hold each endpoint, so custom
+field names work too (e.g. `source: subject` / `target: object`). Endpoint
+order is preserved as `(source, target)` for directed edges.
+
#### For hypergraph (simple)
```yaml
diff --git a/hyperextract/templates/DESIGN_GUIDE_zh.md b/hyperextract/templates/DESIGN_GUIDE_zh.md
index 747bfb8..bffcbaf 100644
--- a/hyperextract/templates/DESIGN_GUIDE_zh.md
+++ b/hyperextract/templates/DESIGN_GUIDE_zh.md
@@ -571,6 +571,10 @@ identifiers:
target: target
```
+字典的值指向关系中存放两个端点的字段名,因此自定义字段名同样有效
+(例如 `source: subject` / `target: object`)。有向边的端点顺序保持为
+`(source, target)`。
+
#### hypergraph(简单)
```yaml
diff --git a/hyperextract/utils/template_engine/parsers/identifiers.py b/hyperextract/utils/template_engine/parsers/identifiers.py
index e68738b..d6721b1 100644
--- a/hyperextract/utils/template_engine/parsers/identifiers.py
+++ b/hyperextract/utils/template_engine/parsers/identifiers.py
@@ -49,17 +49,18 @@ def _members_extractor(
Hypergraph: 'members' -> lambda x: tuple(sorted(x.members)) or
'members' -> lambda x: tuple(sorted(x.m) for m in x.members)
"""
- # Handle Graph
+ # Handle Graph: preserve (source, target) order for directed edges
if isinstance(members, dict):
+ source_field = members["source"]
+ target_field = members["target"]
def extractor(item: Any) -> tuple[str, str]:
- return tuple(
- sorted(
- [
- str(item.source),
- str(item.target),
- ]
- )
+ missing = [f for f in (source_field, target_field) if not hasattr(item, f)]
+ if missing:
+ raise AttributeError(f"Missing fields: {missing}")
+ return (
+ str(getattr(item, source_field)),
+ str(getattr(item, target_field)),
)
return extractor