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
6 changes: 3 additions & 3 deletions frontend/src/App.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -1431,8 +1431,8 @@ describe("App, authenticated", () => {
{
node_id: "corp-1",
node_type_code: "node_corporate_entity",
ontology_iri: "https://contextualwisdomlab.github.io/LineageWeave/ontology#Organization",
ontology_label: "Organization",
ontology_iri: "https://contextualwisdomlab.github.io/LineageWeave/ontology#CorporateEntity",
ontology_label: "Corporate entity",
Comment thread
seonghobae marked this conversation as resolved.
label: "Demo Corp",
relevance: 0.2,
...demoOrgAlias,
Expand Down Expand Up @@ -2843,7 +2843,7 @@ describe("App, authenticated", () => {
await userEvent.click(screen.getByRole("button", { name: "Related nodes for Ada West" }));
await waitFor(() => expect(screen.getByText("Related to Ada West")).toBeInTheDocument());
await userEvent.click(
screen.getByRole("button", { name: "Related nodes for Demo Corp (Organization)" }),
screen.getByRole("button", { name: "Related nodes for Demo Corp (Corporate entity)" }),
);
await waitFor(() => expect(screen.getByText("Related to Demo Corp")).toBeInTheDocument());
expect(screen.getByText("Related to Demo Corp").closest(".related-keymen")).toHaveTextContent(
Expand Down
24 changes: 11 additions & 13 deletions scripts/publish_ontology_site.py
Comment thread
seonghobae marked this conversation as resolved.
Original file line number Diff line number Diff line change
Expand Up @@ -159,36 +159,34 @@ def validate_shapes_graph(shapes: Graph, canonical: Graph) -> None:
raise ValueError(
f"SHACL {kind} target outside the canonical namespace: {value}"
)
declared = {
declared_classes = {
subject
for subject in canonical.subjects(RDF.type, OWL.Class)
if isinstance(subject, URIRef)
}
declared.update(
# Entailed classes: anything with a subclass assertion is a class.
declared_classes.update(
subject
for subject in canonical.subjects(RDF.type, SKOS.Concept)
for subject, _ in canonical.subject_objects(RDFS.subClassOf)
if isinstance(subject, URIRef)
)
declared.update(
declared_properties = {
subject
for subject in canonical.subjects(RDF.type, OWL.ObjectProperty)
if isinstance(subject, URIRef)
)
declared.update(
}
declared_properties.update(
subject
for subject in canonical.subjects(RDF.type, OWL.DatatypeProperty)
if isinstance(subject, URIRef)
)
# Entailed classes: anything with a subclass assertion is a class.
declared.update(str(subject) for subject, _ in canonical.subject_objects(RDFS.subClassOf))
declared = {str(subject) for subject in declared}
declared.update(map(str, STANDARD_SHACL_PATHS))
declared_properties.update(STANDARD_SHACL_PATHS)
for target in shapes.objects(None, SH.targetClass):
if str(target) not in declared:
if target not in declared_classes:
raise ValueError(f"SHACL targetClass is not an ontology class: {target}")
for path in shapes.objects(None, SH.path):
if str(path) not in declared:
raise ValueError(f"SHACL property path is not an ontology term: {path}")
if path not in declared_properties:
raise ValueError(f"SHACL property path is not an ontology property: {path}")


def _validate_output_directory(output_dir: Path, source: Path, profile: Path) -> Path:
Expand Down
19 changes: 18 additions & 1 deletion tests/test_publish_ontology_site.py
Original file line number Diff line number Diff line change
Expand Up @@ -271,9 +271,26 @@ def test_shapes_validation_rejects_dangling_targets_and_outside_namespace() -> N
dangling_path.add((shape, RDF.type, SH.NodeShape))
dangling_path.add((shape, SH.targetClass, URIRef(f"{publisher.CANONICAL_NAMESPACE}Post")))
dangling_path.add((shape, SH.path, URIRef(f"{publisher.CANONICAL_NAMESPACE}ghostColumn")))
with pytest.raises(ValueError, match="not an ontology term"):
with pytest.raises(ValueError, match="not an ontology property"):
publisher.validate_shapes_graph(dangling_path, canonical)

wrong_kind_target = Graph()
wrong_kind_target.add((shape, RDF.type, SH.NodeShape))
wrong_kind_target.add(
(shape, SH.targetClass, URIRef(f"{publisher.CANONICAL_NAMESPACE}postTitle"))
)
with pytest.raises(ValueError, match="not an ontology class"):
publisher.validate_shapes_graph(wrong_kind_target, canonical)

wrong_kind_path = Graph()
wrong_kind_path.add((shape, RDF.type, SH.NodeShape))
wrong_kind_path.add(
(shape, SH.targetClass, URIRef(f"{publisher.CANONICAL_NAMESPACE}Post"))
)
wrong_kind_path.add((shape, SH.path, URIRef(f"{publisher.CANONICAL_NAMESPACE}Post")))
with pytest.raises(ValueError, match="not an ontology property"):
publisher.validate_shapes_graph(wrong_kind_path, canonical)

publisher.validate_shapes_graph(
Graph().parse(ROOT / "docs" / "ontology" / "lineageweave-kg-shapes.ttl", format="turtle"),
canonical,
Expand Down
Loading