Conditional logic
What this is
Express "if condition then produce derived output" rules with SHACL-AF.
When to use it
Use conditional logic when pass/fail alone is not enough and you need derived operational state:
- classify work orders (for example criticality/status buckets)
- create context-specific findings only when predicates are met
- produce machine-readable outputs for downstream automation
Industrial examples
- If a maintenance order status is
Completed, thenendTimemust exist. - If priority is
Highand due date is in the past, emit anOverdueHighPriorityinference. - If inspection findings exceed a threshold, emit a derived
NeedsImmediateReviewoutput.
Example (SHACL-AF rule)
@prefix sh: <http://www.w3.org/ns/shacl#> .
@prefix dqs: <http://purl.org/cognite/dqs#> .
@prefix ex: <https://example.com/dm/> .
ex:CompletedWithoutEndTimeRule
a sh:NodeShape ;
sh:targetClass ex:WorkOrder ;
sh:rule [
a sh:SPARQLRule ;
dqs:ruleId "CompletedMissingEndTime" ;
sh:construct """
CONSTRUCT {
?result a dqs:RuleEngineResult ;
dqs:focusNode $this ;
dqs:ruleId "CompletedMissingEndTime" ;
dqs:resultType "Inference" ;
dqs:resultValue "NeedsReview" .
}
WHERE {
$this ex:status "Completed" .
FILTER NOT EXISTS { $this ex:endTime ?endTime }
BIND(IRI(CONCAT("urn:result:completed-missing-endtime:", ENCODE_FOR_URI(STR($this)))) AS ?result)
}
""" ;
] .