From 252078c5b48a3a705ddc42679189021b35f16bc1 Mon Sep 17 00:00:00 2001 From: Sebastian Tramp Date: Tue, 8 Sep 2026 14:59:39 +0200 Subject: [PATCH 1/2] offer ontology graphs as context graph GraphParameterType filters its autocompletion by graph class and defaults to di:Dataset, void:Dataset and shui:QueryCatalog when no classes are passed. Ontology graphs carry owl:Ontology only, so none of them was offered for the context graph parameter, although validating an ontology against SHACL shapes is a normal thing to do. The IRI could still be typed by hand, since the parameter does not require an autocompleted value. The class list is now passed explicitly and adds owl:Ontology. The result graph keeps the previous set on purpose: it is a write target which clear_result_graph can wipe, so it has no business offering vocabularies. Co-Authored-By: Claude Opus 5 (1M context) Claude-Session: https://claude.ai/code/session_01SxhW9xhADjcpzFezfXBBDk --- CHANGELOG.md | 4 ++ cmem_plugin_validation/validate_graph/task.py | 7 +++ tests/fixtures/ontology.ttl | 10 +++++ tests/test_validate_graph.py | 43 ++++++++++++++++++- 4 files changed, 62 insertions(+), 2 deletions(-) create mode 100644 tests/fixtures/ontology.ttl diff --git a/CHANGELOG.md b/CHANGELOG.md index 9243cb4..7e2b13b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,10 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/) and this p ## [Unreleased] +### Fixed + +- Ontology graphs can now be selected as the context graph + ### Changed - updated dependencies and template diff --git a/cmem_plugin_validation/validate_graph/task.py b/cmem_plugin_validation/validate_graph/task.py index 40fd2e4..6a990a3 100644 --- a/cmem_plugin_validation/validate_graph/task.py +++ b/cmem_plugin_validation/validate_graph/task.py @@ -31,6 +31,12 @@ according to the node shapes in a shape catalog graph. """ +CONTEXT_GRAPH_CLASSES = [ + "https://vocab.eccenca.com/di/Dataset", + "http://rdfs.org/ns/void#Dataset", + "https://vocab.eccenca.com/shui/QueryCatalog", + "http://www.w3.org/2002/07/owl#Ontology", +] DEFAULT_SHAPE_GRAPH = "https://vocab.eccenca.com/shacl/" DEFAULT_RESULT_GRAPH = "" DEFAULT_CLEAR_RESULT_GRAPH = False @@ -54,6 +60,7 @@ label="Context Graph", description="This graph holds the resources you want to validate.", param_type=GraphParameterType( + classes=CONTEXT_GRAPH_CLASSES, show_di_graphs=False, show_graphs_without_class=True, show_system_graphs=True, diff --git a/tests/fixtures/ontology.ttl b/tests/fixtures/ontology.ttl new file mode 100644 index 0000000..7f138f0 --- /dev/null +++ b/tests/fixtures/ontology.ttl @@ -0,0 +1,10 @@ +@prefix owl: . +@prefix rdfs: . + + + a owl:Ontology ; + rdfs:label "Ontology for Persons" . + + + a owl:Class ; + rdfs:label "Person" . diff --git a/tests/test_validate_graph.py b/tests/test_validate_graph.py index 89d8419..29698cb 100644 --- a/tests/test_validate_graph.py +++ b/tests/test_validate_graph.py @@ -13,13 +13,19 @@ from cmem_client.repositories.graphs import GraphExportConfig, GraphsRepository from cmem_client.repositories.protocols.import_item import ImportConflictPolicy from cmem_plugin_base.dataintegration.entity import Entities -from cmem_plugin_base.testing import TestExecutionContext +from cmem_plugin_base.dataintegration.parameter.graph import GraphParameterType +from cmem_plugin_base.testing import TestExecutionContext, TestPluginContext -from cmem_plugin_validation.validate_graph.task import ValidateGraph +from cmem_plugin_validation.validate_graph.task import CONTEXT_GRAPH_CLASSES, ValidateGraph from tests.fixtures import FIXTURE_DIR N_TRIPLES = GraphExportConfig(serialization=GraphsRepository.formats["n-triples"]) +needs_cmem = pytest.mark.skipif( + environ.get("CMEM_BASE_URI", "") == "", + reason="Needs eccenca Corporate Memory configuration", +) + def get_client() -> Client: """Get a fresh client @@ -60,6 +66,8 @@ class TestSetup: shapes_graph = "http://docker.localhost/shapes-for-persons/" shapes_file = FIXTURE_DIR / "shapes.ttl" result_graph = "http://docker.localhost/results/" + ontology_graph = "http://docker.localhost/ontology-for-persons/" + ontology_file = FIXTURE_DIR / "ontology.ttl" @pytest.fixture @@ -77,6 +85,18 @@ def test_setup() -> Generator[TestSetup, Any]: _delete_graphs(_.persons_graph, _.shapes_graph, _.result_graph) +@pytest.fixture +def ontology_graph() -> Generator[str, Any]: + """Provide a graph which is typed as an owl:Ontology""" + _ = TestSetup() + client = get_client() + client.graphs.import_item( + path=_.ontology_file, key=_.ontology_graph, on_conflict=ImportConflictPolicy.REPLACE + ) + yield _.ontology_graph + _delete_graphs(_.ontology_graph) + + def test_fails(test_setup: TestSetup) -> None: """Test failing task execution""" _ = test_setup @@ -165,3 +185,22 @@ def test_different_query(test_setup: TestSetup) -> None: assert task.execute(context=TestExecutionContext(), inputs=[]) is None, ( "Should no violations, since no person was validated" ) + + +@needs_cmem +def test_ontology_as_context_graph(ontology_graph: str) -> None: + """Test that an ontology graph is offered as a context graph""" + parameter_type = GraphParameterType( + classes=CONTEXT_GRAPH_CLASSES, + show_di_graphs=False, + show_graphs_without_class=True, + show_system_graphs=True, + allow_only_autocompleted_values=False, + ) + values = { + _.value + for _ in parameter_type.autocomplete( + query_terms=[], depend_on_parameter_values=[], context=TestPluginContext() + ) + } + assert ontology_graph in values From 72318fc581ea5f6fba2c039ebe08fd5871d82fdc Mon Sep 17 00:00:00 2001 From: Sebastian Tramp Date: Tue, 8 Sep 2026 15:02:21 +0200 Subject: [PATCH 2/2] add idea --- .idea/inspectionProfiles/Project_Default.xml | 88 +++++++++++++++++++ .../inspectionProfiles/profiles_settings.xml | 6 ++ .idea/modules.xml | 8 ++ .idea/ruff.xml | 8 ++ .idea/vcs.xml | 6 ++ 5 files changed, 116 insertions(+) create mode 100644 .idea/inspectionProfiles/Project_Default.xml create mode 100644 .idea/inspectionProfiles/profiles_settings.xml create mode 100644 .idea/modules.xml create mode 100644 .idea/ruff.xml create mode 100644 .idea/vcs.xml diff --git a/.idea/inspectionProfiles/Project_Default.xml b/.idea/inspectionProfiles/Project_Default.xml new file mode 100644 index 0000000..c76fd19 --- /dev/null +++ b/.idea/inspectionProfiles/Project_Default.xml @@ -0,0 +1,88 @@ + + + + \ No newline at end of file diff --git a/.idea/inspectionProfiles/profiles_settings.xml b/.idea/inspectionProfiles/profiles_settings.xml new file mode 100644 index 0000000..105ce2d --- /dev/null +++ b/.idea/inspectionProfiles/profiles_settings.xml @@ -0,0 +1,6 @@ + + + + \ No newline at end of file diff --git a/.idea/modules.xml b/.idea/modules.xml new file mode 100644 index 0000000..874f6c7 --- /dev/null +++ b/.idea/modules.xml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/.idea/ruff.xml b/.idea/ruff.xml new file mode 100644 index 0000000..d0d27da --- /dev/null +++ b/.idea/ruff.xml @@ -0,0 +1,8 @@ + + + + + \ No newline at end of file diff --git a/.idea/vcs.xml b/.idea/vcs.xml new file mode 100644 index 0000000..35eb1dd --- /dev/null +++ b/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file