Extending SHACL Rules and Defining SHACL Rules Dialects - "minutes" from the Task Force meeting on 7/10/2025 #603
Replies: 5 comments 12 replies
-
I know this is tangentially related, but this issue is why I suggested this addition to SPARQL a couple years ago, but I don't think anything will come of it. I don't know if that would be sufficient to solve that particular issue or not. |
Beta Was this translation helpful? Give feedback.
-
|
Re: 1, 2, 6, 7. The current draft describes a datalog-based system applied to a collection of rules. This can be defined for stable, repeated iteration (including recursion) without needing explicitly controlling rule order. Re: 4. Property paths I don't completely follow figure 3. Reversing properties can be done with What is also possible, if property paths are allowed in rules, is to have another rule that defines one step along a path to infer a triple, then write the path expression be in terms of this inferred triple. Also possibility is to classify the intermediate terms being of type Directly using property paths is not naturally part of core datalog. Some property paths can be expanded into triple patterns; One lesson is that there may be inferred triples that might go back into the base graph and other are more like "work space" during the running of a rule set. i.e. we define the system based on n-ary named tuples, one special kind being a triple. Re: 5, 1, -- rules attached to shapes We have use cases where rules (and in node expressions with default values) would be executed once to infer new triples from a shape. But what does it mean to have arbitrary iteration for a rule attached to a shape if that rule itself depends on other rules not attached to the shape? One possibility is to define "attached" as meaning the rule body evaluation starts with a set of |
Beta Was this translation helpful? Give feedback.
-
Do you mean "SPARQL rules" SHACL-AF or the SPARQL-like language compact rules. The SHACL Rule language covers both point 1 and point 2.
!!??!! https://www.w3.org/TR/sparql12-query/#SparqlOps
They are aggregates. Some triple stores already have statistical aggregates (and custom aggregates are allowed in SPARQL - implementation language neutral). |
Beta Was this translation helpful? Give feedback.
-
I think this would be a good addition, perhaps with a name other than DELETE to separate it from SPARQL. I can't find where we have an agenda for the rules TF - will bring this up next meeting. |
Beta Was this translation helpful? Give feedback.
-
Look at N3. |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
At the last meeting of the SHACL Inference Rules Task Force, we had an interesting discussion about SHACL rules. In particular, I shared my experience developing SHACL shapes and rules for the Time Ontology (https://www.w3.org/TR/owl-time), which is currently a W3C Candidate Recommendation Draft implemented in OWL. It is widely regarded, at least in academia, as the "de facto" standard for representing temporal information on the Web.
The OWL axioms currently defined for the Time Ontology are not very effective for reasoning about temporal relations. For this reason, I have been working on a paper proposing a SHACL-based replacement for OWL. The latest draft is available here:
https://www.liviorobaldo.com/SHACLTimeOntology.pdf
Let me summarize the key points we discussed at the meeting. Andy suggested that I open a discussion thread here:
Grouping rules and shapes: Rules should be organized into sets using a RuleSet tag. For validation, a set of rules should be associated with a corresponding set of shapes. This is not specified in the current WG Note 08 June 2017, where rule sets can only be associated with individual shapes.
Iterative execution: Rules must be executed iteratively until no further triples are inferred, similar to OWL axioms.
Handling inferred triples: Inferred triples should not be automatically merged with the initially asserted ones. Whether to merge them should depend on the task. For example, merging is useful in validation, where the complete knowledge (asserted + inferred) must be checked. However, for tasks involving provenance tracking, it is better to keep inferred triples separate, since they have a different provenance.
Limitations of SHACL shapes: the current SHACL language is insufficient to validate even simple knowledge graphs. See Figure 3 (p. 16) and related discussion in SHACLTimeOntology.pdf. The figure shows a graph that uses only one class and two properties from the Time Ontology. It is not possible to define a SHACL shape that validates such graphs in the general case, i.e., over an arbitrary number of nodes. The specific reason is that SPARQL property paths can define regular expressions over properties, but cannot impose additional constraints on the intermediate nodes traversed by those paths.
Two-step validation process: based on point 4, ontology validation should proceed in two stages:
(a) compute the inferred knowledge graph using a set of SHACL rules, and
(b) validate the inferred graph using a corresponding set of SHACL shapes.
Hence, a set of rules must be linked to a set of shapes (see point 1).
Order of execution (which came first, the chicken or the egg? :-)): the previous point raises the question of execution order: should rules be applied after shape validation (i.e., validate → infer), or should validation occur after rule application (infer → validate)? Perhaps the two processes could alternate: first validate, then infer, then validate again, etc. until no new triples are inferred. However, this could be computationally expensive. A practical compromise might be three steps:
Risks with SHACL-SPARQL rules: unlike OWL axioms, SHACL-SPARQL rules can (1) produce infinite loops and (2) lead to non-deterministic outcomes. These issues are discussed in detail in Section 8 (p. 27) of the paper SHACLTimeOntology.pdf, along with illustrative examples, so I won’t repeat them here.
Ensuring determinism and termination: as argued in the paper’s conclusions, anyone proposing a SHACL axiomatization involving SHACL-SPARQL rules must demonstrate that the rules cannot produce infinite loops or non-deterministic results (or, at least, that non-determinism does not affect the outcome of the target task). In my paper, I show that the proposed SHACL axiomatization for the Time Ontology is safe with respect to validation. This was straightforward to verify since only one rule could potentially introduce such problems. However, in more complex ontologies, the analysis can easily become much harder.
Need for SHACL dialects/profiles: given the concerns in point 8, we should consider defining SHACL dialects or profiles, similar to what was done in OWL (OWL Lite, OWL DL, etc.). The academic community is well-equipped to lead this effort, as it has done for OWL; there is a vast body of literature on inference complexity, termination, and determinism dating back to Turing’s foundational work. We can adapt those formal results to the context of SHACL-SPARQL rules.
Extending SPARQL expressivity: SPARQL lacks built-in operators for certain domain-specific computations (e.g., analytical functions in finance). Implementing such logic purely with CONSTRUCT/WHERE rules can be impractical. Users should therefore be able to define custom functions and invoke them from SPARQL. A promising approach in this direction is SHACL-X (https://github.com/SHACL-X), which integrates SHACL with JavaScript. SHACL-X allows the definition of complex JavaScript functions, which enable loops and conditional logic, which can then be invoked from SHACL. This could inspire a dedicated SHACL dialect supporting embedded procedural logic.
Optional DELETE rules: it might also be useful to allow rules of the form DELETE WHERE to "compact" RDF graphs by removing redundant triples. Naturally, this would exacerbate the risks of infinite loops and non-determinism. However, this is a secondary issue compared to the points above.
Final remarks
Last but not least, I believe we should promote the development of general-purpose SHACL ontologies. At present, I’m focusing on the SHACL formalization of the Time Ontology, but in the future I/we could also develop further general-purpose SHACL ontologies for spatial relations, compliance checking, natural language quantifiers, and similar. This would greatly help the dissemination of SHACL, and promote the Semantic Web principles of sharing, reusability, interoperability, etc. I realize, however, that such work may go beyond the remit of the SHACL Inference Rules Task Force... or even that of the Data Shapes Working Group.
Beta Was this translation helpful? Give feedback.
All reactions