Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
88 changes: 88 additions & 0 deletions .idea/inspectionProfiles/Project_Default.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions .idea/inspectionProfiles/profiles_settings.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions .idea/modules.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions .idea/ruff.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions .idea/vcs.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
7 changes: 7 additions & 0 deletions cmem_plugin_validation/validate_graph/task.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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,
Expand Down
10 changes: 10 additions & 0 deletions tests/fixtures/ontology.ttl
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
@prefix owl: <http://www.w3.org/2002/07/owl#> .
@prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> .

<http://docker.localhost/ontology-for-persons/>
a owl:Ontology ;
rdfs:label "Ontology for Persons" .

<http://example.org/persons/Person>
a owl:Class ;
rdfs:label "Person" .
43 changes: 41 additions & 2 deletions tests/test_validate_graph.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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
Loading