Skip to content

Plan, apply and roll back changes to a production ontology, with a blast radius report and a proof an auditor can re-check.

fix: reuse reported blank-node graph names in Horn selection

Rudy Celekli01cd3ab0f7b6
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 6646495d..6150e292 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -6,6 +6,8 @@ All notable changes to Open Ontologies are documented here.
### Fixed
+- Python: accept reported blank-node graph names when selecting asserted graphs for Horn reasoning; preserve ordinary graph-name forms and inferred-graph refusal.
+
- Keep the last active ontology intact when parsing a replacement source, cache, or refresh fails; publish successful replacements in one graph transaction.
- Bound wildcard repository filtering to pattern/filename pairs so repeated stars cannot stall `onto_repo_list`.
- Sanitize quotes and ASCII control bytes in mapped IRI components so valid structured data does not fail RDF ingestion.
diff --git a/python/src/open_ontologies_lite/horn/reason.py b/python/src/open_ontologies_lite/horn/reason.py
index 9c408699..6beac438 100644
--- a/python/src/open_ontologies_lite/horn/reason.py
+++ b/python/src/open_ontologies_lite/horn/reason.py
@@ -220,10 +220,12 @@ def _graph_label(graph_name) -> str:
def _named_graph(name: str):
"""Accept a graph either bare (`http://x/g`) or in its N-Triples spelling
- (`<http://x/g>`), because a user reading `asserted_graphs` out of a previous
+ (`<http://x/g>` or `_:blank`), because a user reading `asserted_graphs` out of a previous
report will paste back the spelled form."""
if name == "default":
return ox.DefaultGraph()
+ if name.startswith("_:"):
+ return ox.BlankNode(name[2:])
iri = name[1:-1] if name.startswith("<") and name.endswith(">") else name
return ox.NamedNode(iri)
diff --git a/python/tests/test_horn_blank_graph_selection.py b/python/tests/test_horn_blank_graph_selection.py
new file mode 100644
index 00000000..ad07a74c
--- /dev/null
+++ b/python/tests/test_horn_blank_graph_selection.py
@@ -0,0 +1,30 @@
+import pytest
+from open_ontologies_lite import OntologyEngine
+from open_ontologies_lite.horn.reason import AssertedGraphError, INFERRED_GRAPH
+
[email protected]('with_default',[False,True])
+def test_reported_blank_graph_names_can_be_selected(tmp_path,with_default):
+ engine=OntologyEngine()
+ engine.load('<http://x/s> <http://x/p> <http://x/o> _:g .','nquads')
+ if with_default:engine.load('<http://x/default> <http://x/p> <http://x/o> .')
+ report=engine.reason_horn(certificate_dir=tmp_path/'all',graphs='all',check=False)
+ assert any(label.startswith('_:') for label in report['asserted_graphs'])
+ selected=engine.reason_horn(certificate_dir=tmp_path/'selected',graphs=report['asserted_graphs'],check=False)
+ assert selected['asserted_graphs']==report['asserted_graphs']
+ assert selected['asserted_triples']==report['asserted_triples']==1+int(with_default)
+ assert set((tmp_path/'selected'/'asserted.tsv').read_text().splitlines())==set((tmp_path/'all'/'asserted.tsv').read_text().splitlines())
+ assert selected['check']['status']=='not_requested'
+
[email protected]('graphs',[['http://x/g'],['<http://x/g>'],['default']])
+def test_existing_graph_name_forms_control(tmp_path,graphs):
+ engine=OntologyEngine()
+ engine.load('<http://x/s> <http://x/p> <http://x/o> <http://x/g> .','nquads')
+ engine.load('<http://x/default> <http://x/p> <http://x/o> .')
+ report=engine.reason_horn(certificate_dir=tmp_path/'control',graphs=graphs,check=False)
+ assert report['asserted_triples']==1
+ assert report['asserted_graphs']==(['default'] if graphs==['default'] else ['<http://x/g>'])
+
[email protected]('graphs',[[INFERRED_GRAPH],['<'+INFERRED_GRAPH+'>']])
+def test_inferred_graph_refusal_control(tmp_path,graphs):
+ engine=OntologyEngine()
+ with pytest.raises(AssertedGraphError):engine.reason_horn(certificate_dir=tmp_path/'refused',graphs=graphs,check=False)