Skip to main content

Repairing SHACL Constraint Violations Using Answer Set Programming

  • Conference paper
  • First Online:

Part of the book series: Lecture Notes in Computer Science ((LNCS,volume 13489))

Abstract

The Shapes Constraint Language (SHACL) is a recent W3C recommendation for validating RDF graphs against shape constraints to be checked on target nodes of the data graph. The standard also describes the notion of validation reports for data graphs that violate given constraints, which aims to provide feedback on how the data graph can be fixed to satisfy the constraints. Since the specification left it open to SHACL processors to define such explanations, a recent work proposed the use of explanations in the style of database repairs, where a repair is a set of additions to or deletions from the data graph so that the resulting graph validates against the constraints. In this paper, we study such repairs for non-recursive SHACL, the largest fragment of SHACL that is fully defined in the specification. We propose an algorithm to compute repairs by encoding the explanation problem – using Answer Set Programming (ASP) – into a logic program, the answer sets of which correspond to (minimal) repairs. We then study a scenario where it is not possible to simultaneously repair all the targets, which may be often the case due to overall unsatisfiability or conflicting constraints. We introduce a relaxed notion of validation, which allows to validate a (maximal) subset of the targets and adapt the ASP translation to take into account this relaxation. Our implementation in Clingo is – to the best of our knowledge – the first implementation of a repair generator for SHACL.

This is a preview of subscription content, log in via an institution.

Buying options

Chapter
USD   29.95
Price excludes VAT (USA)
  • Available as PDF
  • Read on any device
  • Instant download
  • Own it forever
eBook
USD   84.99
Price excludes VAT (USA)
  • Available as EPUB and PDF
  • Read on any device
  • Instant download
  • Own it forever
Softcover Book
USD   109.99
Price excludes VAT (USA)
  • Compact, lightweight edition
  • Dispatched in 3 to 5 business days
  • Free shipping worldwide - see info

Tax calculation will be finalised at checkout

Purchases are for personal use only

Learn about institutional subscriptions

Notes

  1. 1.

    https://www.w3.org/TR/shacl/#data-graph.

  2. 2.

    https://www.w3.org/TR/shacl/#shapes-graph.

  3. 3.

    https://potassco.org/clingo/.

  4. 4.

    Technically speaking, the repair rules above may be recursive. However, if the annotation constants \(t,f,t^*,t^{**}\) are seen as part of the predicate’s name (instead of being a fixed value in the last position), then the rules are non-recursive.

  5. 5.

    https://w3c.github.io/data-shapes/data-shapes-test-suite/.

  6. 6.

    Our prototype, test suites, and statistics are available from the authors upon request.

References

  1. Shapes constraint language (SHACL). Tech. rep., W3C, Jul 2017. https://www.w3.org/TR/shacl/

  2. Ahmetaj, S., David, R., Ortiz, M., Polleres, A., Shehu, B., Simkus, M.: Reasoning about explanations for non-validation in SHACL. In: Bienvenu, M., Lakemeyer, G., Erdem, E. (eds.) Proceedings of the 18th International Conference on Principles of Knowledge Representation and Reasoning, KR 2021, Online event, 3–12 November 2021, pp. 12–21 (2021). https://doi.org/10.24963/kr.2021/2

  3. Andresel, M., et al.: Stable model semantics for recursive SHACL. In: Proceedings of the Web Conference 2020, WWW 2020, pp. 1570–1580. ACM (2020). https://doi.org/10.1145/3366423.3380229

  4. Bertossi, L.: Database Repairing and Consistent Query Answering. Morgan & Claypool Publishers (2011). https://doi.org/10.2200/S00379ED1V01Y201108DTM020

  5. Bertossi, L.E.: Database Repairing and Consistent Query Answering. Synthesis Lectures on Data Management. Morgan & Claypool Publishers (2011). https://doi.org/10.2200/S00379ED1V01Y201108DTM020

  6. Corman, J., Reutter, J.L., Savković, O.: Semantics and validation of recursive SHACL. In: Vrandečić, D., et al. (eds.) ISWC 2018. LNCS, vol. 11136, pp. 318–336. Springer, Cham (2018). https://doi.org/10.1007/978-3-030-00671-6_19

    Chapter  Google Scholar 

  7. Eiter, T., Ianni, G., Krennwallner, T.: Answer set programming: a primer. In: Tessaris, S., et al. (eds.) Reasoning Web 2009. LNCS, vol. 5689, pp. 40–110. Springer, Heidelberg (2009). https://doi.org/10.1007/978-3-642-03754-2_2

    Chapter  Google Scholar 

  8. Gayo, J.E.L., Prud’hommeaux, E., Boneva, I., Kontokostas, D.: Validating RDF Data. Synthesis Lectures on the Semantic Web: Theory and Technology. Morgan & Claypool Publishers (2017). https://doi.org/10.2200/S00786ED1V01Y201707WBE016

  9. Gebser, M., Kaminski, R., Kaufmann, B., Schaub, T.: Multi-shot asp solving with clingo. Theory Pract. Logic Program. 19(1), 27–82 (2019). https://doi.org/10.1017/S1471068418000054

    Article  MathSciNet  MATH  Google Scholar 

  10. Hogan, A., et al.: Knowledge Graphs. Synthesis Lectures on Data, Semantics, and Knowledge. Morgan & Claypool Publishers (2021). https://doi.org/10.2200/S01125ED1V01Y202109DSK022

  11. Marileo, M.C., Bertossi, L.E.: The consistency extractor system: answer set programs for consistent query answering in databases. Data Knowl. Eng. 69, 545–572 (2010). https://doi.org/10.1016/j.datak.2010.01.005

    Article  Google Scholar 

Download references

Acknowledgements

Supported by the Austrian Science Fund (FWF) and netidee SCIENCE project T 1349-N, and the FWF projects P30360 and P30873. Polleres is supported by funding in the European Commission’s Horizon 2020 Research Program under Grant Agreement Number 957402 (TEAMING.AI).

Author information

Authors and Affiliations

Authors

Corresponding author

Correspondence to Robert David .

Editor information

Editors and Affiliations

Rights and permissions

Reprints and permissions

Copyright information

© 2022 The Author(s), under exclusive license to Springer Nature Switzerland AG

About this paper

Check for updates. Verify currency and authenticity via CrossMark

Cite this paper

Ahmetaj, S., David, R., Polleres, A., Šimkus, M. (2022). Repairing SHACL Constraint Violations Using Answer Set Programming. In: Sattler, U., et al. The Semantic Web – ISWC 2022. ISWC 2022. Lecture Notes in Computer Science, vol 13489. Springer, Cham. https://doi.org/10.1007/978-3-031-19433-7_22

Download citation

  • DOI: https://doi.org/10.1007/978-3-031-19433-7_22

  • Published:

  • Publisher Name: Springer, Cham

  • Print ISBN: 978-3-031-19432-0

  • Online ISBN: 978-3-031-19433-7

  • eBook Packages: Computer ScienceComputer Science (R0)

Publish with us

Policies and ethics