mirror of
https://github.com/trustgraph-ai/trustgraph.git
synced 2026-04-29 10:26:21 +02:00
Fixes #826. Addresses all five points the maintainer called out in the follow-up to #825. Source change (trustgraph-flow/trustgraph/extract/kg/ontology/extract.py): - Added `_is_subclass_of(cls, target, ontology_subset, max_depth=100)` helper with visited-set cycle detection + a defensive depth cap. LLM-generated ontologies may emit cycles (A subclass_of B, B subclass_of A); the prior while-loop would infinite-loop on that. - Replaced both near-identical domain and range subclass walks in `is_valid_triple` with a single call to the new helper. Net is -20 duplicated lines + 26-line helper. Tests (tests/unit/test_extract/test_ontology/test_prompt_and_extraction.py): - test_is_valid_triple_subclass_is_accepted: domain expects Recipe, actual type is Cake (subclass), validates. - test_is_valid_triple_handles_subclass_cycle_without_infinite_loop: A subclass_of B, B subclass_of A; call returns False within the depth cap rather than hanging. - test_parse_and_validate_triples_collects_entity_types_from_rdf_type: end-to-end path: rdf:type triples build the entity_types dict, subsequent domain-check triples validate against it. - test_is_valid_triple_entity_types_none_default: the None default path now has explicit coverage. 156 existing tests in tests/unit/test_extract/test_ontology still pass. |
||
|---|---|---|
| .. | ||
| trustgraph | ||
| pyproject.toml | ||
| README.md | ||