Skip to content

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

Merge origin/main into resolve-185: keep both member-form and relations-section tests

yifanfeng97190dbf561df2
diff --cc hyperextract/utils/template_engine/parsers/identifiers.py
index cfd9038,4a35e6e..0ffcb51
--- a/hyperextract/utils/template_engine/parsers/identifiers.py
+++ b/hyperextract/utils/template_engine/parsers/identifiers.py
@@@ -145,25 -144,15 +145,37 @@@ def validate_identifiers_fields
f"relation_members['{role}'] references '{{{field}}}' but "
f"relations.fields does not declare '{field}'"
)
++<<<<<<< HEAD
+ else:
+ # Hypergraph member fields: a single field name or a list of them.
+ member_fields = [members] if isinstance(members, str) else (members or [])
+ for field in member_fields:
+ if field not in relation_fields:
+ problems.append(
+ f"relation_members references '{{{field}}}' but "
+ f"relations.fields does not declare '{field}'"
+ )
+ for attr, field in (
+ ("time_field", identifiers.time_field),
+ ("location_field", identifiers.location_field),
+ ):
+ if field:
+ for placeholder in _placeholders(field):
+ if placeholder not in relation_fields:
+ problems.append(
+ f"{attr} references '{{{placeholder}}}' but "
+ f"relations.fields does not declare '{placeholder}'"
++=======
+ # time/location live on relations (see validator HE-T006 and the presets).
+ for attr in ("time_field", "location_field"):
+ value = getattr(identifiers, attr, None)
+ if value:
+ for field in _placeholders(value):
+ if field not in relation_fields:
+ problems.append(
+ f"{attr} references '{{{field}}}' but "
+ f"relations.fields does not declare '{field}'"
++>>>>>>> origin/main
)
if problems:
diff --cc tests/template_engine/test_parser_identifiers.py
index 98e424d,3468ee1..8cfe056
--- a/tests/template_engine/test_parser_identifiers.py
+++ b/tests/template_engine/test_parser_identifiers.py
@@@ -133,47 -133,53 +133,97 @@@ class TestHypergraphRelationMembers
assert extractor(edge) == (("X", "Y"), ("A", "B"))
+class TestValidateHypergraphMembers:
+ """Hypergraph relation_members (string / list) must be field-checked too."""
+
+ @staticmethod
+ def _identifiers(members):
+ return GraphIdentifiersSchema(
+ entity_id="name",
+ relation_id="{name}|{type}",
+ relation_members=members,
+ )
+
+ @staticmethod
+ def _declared(relations):
+ return {"entities": {"name"}, "relations": set(relations)}
+
+ def test_string_members_must_be_declared(self):
+ with pytest.raises(ValueError, match="attendees"):
+ validate_identifiers_fields(
+ self._identifiers("attendees"),
+ "hypergraph",
+ self._declared(["name", "type", "participants"]),
+ )
+
+ def test_list_members_must_be_declared(self):
+ with pytest.raises(ValueError, match="group_b"):
+ validate_identifiers_fields(
+ self._identifiers(["group_a", "group_b"]),
+ "hypergraph",
+ self._declared(["name", "type", "group_a"]),
+ )
+
+ def test_declared_string_members_accepted(self):
+ validate_identifiers_fields(
+ self._identifiers("participants"),
+ "hypergraph",
+ self._declared(["name", "type", "participants"]),
+ )
+
+ def test_declared_list_members_accepted(self):
+ validate_identifiers_fields(
+ self._identifiers(["group_a", "group_b"]),
+ "hypergraph",
+ self._declared(["name", "type", "group_a", "group_b"]),
+ )
+ class TestValidateIdentifiersFields:
+ """Load-time field check: time/location live on relations (HE-T006)."""
+
+ @staticmethod
+ def _declared(entities, relations):
+ return {"entities": set(entities), "relations": set(relations)}
+
+ def test_relation_level_time_field_accepted(self):
+ """Every shipped temporal preset declares `time` under relations."""
+ identifiers = GraphIdentifiersSchema(
+ entity_id="name",
+ relation_id="{source}|{type}|{target}|{time}",
+ relation_members={"source": "source", "target": "target"},
+ time_field="time",
+ )
+
+ validate_identifiers_fields(
+ identifiers,
+ "temporal_graph",
+ self._declared(["name"], ["source", "target", "type", "time"]),
+ )
+
+ def test_relation_level_location_field_accepted(self):
+ identifiers = GraphIdentifiersSchema(
+ entity_id="name",
+ relation_id="{source}|{target}",
+ relation_members={"source": "source", "target": "target"},
+ location_field="location",
+ )
+
+ validate_identifiers_fields(
+ identifiers,
+ "spatial_graph",
+ self._declared(["name"], ["source", "target", "location"]),
+ )
+
+ def test_undeclared_time_field_still_rejected(self):
+ identifiers = GraphIdentifiersSchema(
+ entity_id="name",
+ relation_id="{source}|{target}",
+ relation_members={"source": "source", "target": "target"},
+ time_field="when",
+ )
+
+ with pytest.raises(ValueError, match="when"):
+ validate_identifiers_fields(
+ identifiers,
+ "temporal_graph",
+ self._declared(["name"], ["source", "target"]),
+ )