Skip to main content

Type Checking Program Code Using SHACL

Part of the Lecture Notes in Computer Science book series (LNISA,volume 11778)


It is a strength of graph-based data formats, like RDF, that they are very flexible with representing data. To avoid run-time errors, program code that processes highly-flexible data representations exhibits the difficulty that it must always include the most general case, in which attributes might be set-valued or possibly not available. The Shapes Constraint Language (SHACL) has been devised to enforce constraints on otherwise random data structures. We present our approach, Type checking using SHACL (TyCuS), for type checking code that queries RDF data graphs validated by a SHACL shape graph. To this end, we derive SHACL shapes from queries and integrate data shapes and query shapes as types into a \(\lambda \)-calculus. We provide the formal underpinnings and a proof of type safety for TyCuS. A programmer can use our method in order to process RDF data with simplified, type checked code that will not encounter run-time errors (with usual exceptions as type checking cannot prevent accessing empty lists).


  • Programming with RDF
  • Type checking

This is a preview of subscription content, access via your institution.

Buying options

USD   29.95
Price excludes VAT (USA)
  • DOI: 10.1007/978-3-030-30793-6_23
  • Chapter length: 19 pages
  • Instant PDF download
  • Readable on all devices
  • Own it forever
  • Exclusive offer for individuals only
  • Tax calculation will be finalised during checkout
USD   89.00
Price excludes VAT (USA)
  • ISBN: 978-3-030-30793-6
  • Instant PDF download
  • Readable on all devices
  • Own it forever
  • Exclusive offer for individuals only
  • Tax calculation will be finalised during checkout
Softcover Book
USD   119.99
Price excludes VAT (USA)
Fig. 1.
Fig. 2.
Fig. 3.
Fig. 4.
Fig. 5.
Fig. 6.
Fig. 7.
Fig. 8.
Fig. 9.


  1. 1.

    As we use plain RDF, we do not differentiate between distinguished and existential variables.

  2. 2.

    Available at

  3. 3.

    We simplified target queries in the example—in reality, the target queries should query for Student or any of its subclasses. We simplified this as we do not use any RDFS subclass relations in our examples.

  4. 4.

    Since they show no interesting effects, let statements and a fixpoint operator allowing for recursion, e.g., as necessary to define a map function are omitted. They are contained in the extended version.


  1. Baader, F., et al. (eds.): The Description Logic Handbook: Theory, Implementation, and Applications. Cambridge University Press, Cambridge (2003)

    MATH  Google Scholar 

  2. Bierman, G., Meijer, E., Schulte, W.: The essence of data access in C\(\omega \). In: Black, A.P. (ed.) ECOOP 2005. LNCS, vol. 3586, pp. 287–311. Springer, Heidelberg (2005).

    CrossRef  Google Scholar 

  3. Bischof, S., Krötzsch, M., Polleres, A., Rudolph, S.: Schema-agnostic query rewriting in SPARQL 1.1. In: Mika, P., et al. (eds.) ISWC 2014. LNCS, vol. 8796, pp. 584–600. Springer, Cham (2014).

    CrossRef  Google Scholar 

  4. Boneva, I., Labra Gayo, J.E., Prud’hommeaux, E.G.: Semantics and validation of shapes schemas for RDF. In: d’Amato, C., et al. (eds.) ISWC 2017. LNCS, vol. 10587, pp. 104–120. Springer, Cham (2017).

    CrossRef  Google Scholar 

  5. Carroll, J.J., et al.: Jena: implementing the semantic web recommendations. In: Proceedings WWW 2004, pp. 74–83. ACM (2004)

    Google Scholar 

  6. Ciobanu, G., et al.: Minimal type inference for linked data consumers. J. Log. Algebr. Meth. Program. 84(4), 485–504 (2015)

    MathSciNet  CrossRef  Google Scholar 

  7. 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).

    CrossRef  Google Scholar 

  8. Horne, R., et al.: A verified algebra for read-write linked data. Sci. Comput. Program. 89, Part A, 2–22 (2014)

    CrossRef  Google Scholar 

  9. Horridge, M., et al.: The OWL API: a Java API for OWL ontologies. Semant. Web 2(1), 11–21 (2011)

    Google Scholar 

  10. Igarashi, A., et al.: Featherweight Java: a minimal core calculus for Java and GJ. ACM Trans. Program. Lang. Syst. 23(3), 396–450 (2001)

    CrossRef  Google Scholar 

  11. Käfer, T., et al.: Rule-based programming of user agents for linked data. In: Proceedings Linked Data on the Web. CEUR Workshop Proceedings, (2018)

    Google Scholar 

  12. Kalyanpur, A., et al.: Automatic mapping of OWL ontologies into Java. In: Proceedings Software Engineering & Knowledge Engineering (SEKE) 2004, pp. 98–103 (2004)

    Google Scholar 

  13. Knublauch, H., et al.: Shapes constraint language (SHACL). W3C Recommendation (2017).

  14. Leinberger, M., Scheglmann, S., Lämmel, R., Staab, S., Thimm, M., Viegas, E.: Semantic web application development with LITEQ. In: Mika, P., et al. (eds.) ISWC 2014. LNCS, vol. 8797, pp. 212–227. Springer, Cham (2014).

    CrossRef  Google Scholar 

  15. Leinberger, M., Lämmel, R., Staab, S.: The essence of functional programming on semantic data. In: Yang, H. (ed.) ESOP 2017. LNCS, vol. 10201, pp. 750–776. Springer, Heidelberg (2017).

    CrossRef  MATH  Google Scholar 

  16. Motik, B., et al.: Adding integrity constraints to OWL. In: Proceedings OWLED 2007. CEUR Workshop Proceedings, vol. 258. (2007)

    Google Scholar 

  17. Paar, A., Vrandečić, D.: Zhi# – OWL aware compilation. In: Antoniou, G., et al. (eds.) ESWC 2011. LNCS, vol. 6644, pp. 315–329. Springer, Heidelberg (2011).

    CrossRef  Google Scholar 

  18. Picalausa, F., Luo, Y., Fletcher, G.H.L., Hidders, J., Vansummeren, S.: A structural approach to indexing triples. In: Simperl, E., Cimiano, P., Polleres, A., Corcho, O., Presutti, V. (eds.) ESWC 2012. LNCS, vol. 7295, pp. 406–421. Springer, Heidelberg (2012).

    CrossRef  Google Scholar 

  19. Pierce, B.C.: Types and Programming Languages. The MIT Press, Cambridge (2002)

    MATH  Google Scholar 

  20. Prud’hommeaux, E., et al.: SPARQL query language for RDF. W3C Rec. November 2013.

  21. Prud’hommeaux, E., et al.: Shape expressions: an RDF validation and transformation language. In: Proceedings SEMANTICS 2014, pp. 32–40. ACM (2014)

    Google Scholar 

  22. Seifer, P., et al.: Semantic query integration with reason. Program. J. 3(3), 13 (2019)

    CrossRef  Google Scholar 

  23. Tao, J., et al.: Integrity constraints in OWL. In: Proceedings of the AAAI 2010. AAAI Press (2010)

    Google Scholar 

Download references

Author information

Authors and Affiliations


Corresponding author

Correspondence to Martin Leinberger .

Editor information

Editors and Affiliations

Rights and permissions

Reprints and Permissions

Copyright information

© 2019 Springer Nature Switzerland AG

About this paper

Verify currency and authenticity via CrossMark

Cite this paper

Leinberger, M., Seifer, P., Schon, C., Lämmel, R., Staab, S. (2019). Type Checking Program Code Using SHACL. In: , et al. The Semantic Web – ISWC 2019. ISWC 2019. Lecture Notes in Computer Science(), vol 11778. Springer, Cham.

Download citation

  • DOI:

  • Published:

  • Publisher Name: Springer, Cham

  • Print ISBN: 978-3-030-30792-9

  • Online ISBN: 978-3-030-30793-6

  • eBook Packages: Computer ScienceComputer Science (R0)