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.

A node-level sh:or result carries the node shape's sh:severity instead of always Violation

FABIOTESSa818fdeec7a6
diff --git a/CHANGELOG.md b/CHANGELOG.md
index e5276591..86312115 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -61,6 +61,11 @@ All notable changes to Open Ontologies are documented here.
datatype on a property inside the referenced shape and not on the shape
itself, so every value the store had widened was reported. The `sh:node` is
now recorded as not evaluated. W3C columns unchanged.
+- **A node-level `sh:or` result carries the node shape's `sh:severity`.** It
+ was written `"Violation"` whatever the shape declared, and the RDF report
+ followed it with `sh:resultSeverity sh:Violation`; it now uses the declared
+ term, through the same `severity_name` as every other path (#334). W3C
+ columns unchanged.
- **A custom `sh:severity` keeps its namespace in the JSON report** (#334).
Every path set `severity` to the text after the last `#` of the declared
IRI, and every reader takes a bare name as `sh:`, so W3C
diff --git a/src/shacl.rs b/src/shacl.rs
index abce2d00..4c4dc483 100644
--- a/src/shacl.rs
+++ b/src/shacl.rs
@@ -1119,20 +1119,30 @@ impl ShaclValidator {
.collect();
members.sort();
let disjunction = members.join(" || ");
- let node_message_term = query_solutions(
+ let node_terms = query_solutions(
&shapes_store,
&format!(
r#"PREFIX sh: <http://www.w3.org/ns/shacl#>
- SELECT ?m WHERE {{ {} sh:message ?m }}"#,
- shape_term
+ SELECT ?m ?sev WHERE {{
+ OPTIONAL {{ {shape_term} sh:message ?m }}
+ OPTIONAL {{ {shape_term} sh:severity ?sev }}
+ }}"#
),
- )?
- .first()
- .and_then(|r| r.get("m").cloned());
+ )?;
+ let node_term = |k: &str| node_terms.first().and_then(|r| r.get(k).cloned());
+ let node_message_term = node_term("m");
let node_message =
node_message_term.as_deref().map(strip_quotes).unwrap_or_default();
+ // The node shape's sh:severity, as on every other path.
+ // This one wrote "Violation" whatever was declared, and
+ // the RDF report followed it with sh:Violation.
+ let node_severity_term = node_term("sev");
+ let node_severity = node_severity_term
+ .as_deref()
+ .map(severity_name)
+ .unwrap_or_else(|| "Violation".to_string());
let node_or_rdf = RdfTerms::new(
- None,
+ node_severity_term,
node_message_term.filter(|_| !node_message.is_empty()),
);
let query = format!(
@@ -1149,7 +1159,7 @@ impl ShaclValidator {
node_message.clone()
};
violations.push(attribute(&shape_iri, &shape_iri, &node_or_rdf, serde_json::json!({
- "severity": "Violation",
+ "severity": node_severity,
"focus_node": strip_angle_brackets(focus),
"value": strip_angle_brackets(focus),
"constraint": "or",
diff --git a/tests/shacl_validation_report_test.rs b/tests/shacl_validation_report_test.rs
index 498cc1b4..cc2ae4bd 100644
--- a/tests/shacl_validation_report_test.rs
+++ b/tests/shacl_validation_report_test.rs
@@ -285,6 +285,40 @@ ex:SparqlLevel a sh:NodeShape ; sh:targetClass ex:Person ;
assert_eq!(got, want, "{j}");
}
+/// `sh:or` asserted on a node shape over member shapes wrote every result as
+/// `"Violation"` whatever the shape declared, and the RDF report followed it
+/// with `sh:resultSeverity sh:Violation`. The node shape's `sh:severity` is
+/// the result's severity (SHACL 3.6.2) as on every other path.
+#[test]
+fn a_node_level_or_result_carries_the_shapes_declared_severity() {
+ for (declared, json, rdf) in [
+ ("sh:Warning", "Warning", "sh:Warning"),
+ ("sev:MySeverity", "http://ex.org/sev#MySeverity", "<http://ex.org/sev#MySeverity>"),
+ ("", "Violation", "sh:Violation"),
+ ] {
+ let severity = if declared.is_empty() { String::new() } else { format!("sh:severity {declared} ;") };
+ let shapes = format!(
+ r#"
+@prefix sh: <http://www.w3.org/ns/shacl#> .
+@prefix ex: <http://ex.org/> .
+@prefix sev: <http://ex.org/sev#> .
+ex:S a sh:NodeShape ; sh:targetClass ex:Person ; {severity}
+ sh:or ( [ sh:property [ sh:path ex:email ; sh:minCount 1 ] ]
+ [ sh:property [ sh:path ex:phone ; sh:minCount 1 ] ] ) .
+"#
+ );
+ let j = json_report(DATA, &shapes);
+ assert_eq!(j["violation_count"], 1, "{declared}: {j}");
+ assert_eq!(j["violations"][0]["constraint"], "or", "{declared}: {j}");
+ assert_eq!(j["violations"][0]["severity"], json, "{declared}: {j}");
+ let s = parsed(&rdf_report(DATA, &shapes, ReportFormat::Turtle), RdfFormat::Turtle);
+ assert!(
+ ask(&s, &format!("?x sh:sourceConstraintComponent sh:OrConstraintComponent ; sh:resultSeverity {rdf}")),
+ "{declared}: the RDF report must carry {rdf}"
+ );
+ }
+}
+
/// #335, MEASURED AND NOT FIXED IN THIS REPOSITORY. This test pins the loss
/// so that it cannot be mistaken for a report-writer bug, and so that it fails,
/// by name, on the day the store starts keeping lexical forms.