4

I have a specific situation where I need to automatically generate SPARQL queries based on the SHACL schemas of the incoming data. I wonder if Jena or any other semantic tool/library can help do that?

I saw something on the Jena code based but nothing official from the documentation.

Before I start trying to develop my own solution, I wonder if there is already some existing libraries on that or else initiative going on.

TallTed
  • 9,069
  • 2
  • 22
  • 37
MaatDeamon
  • 9,532
  • 9
  • 60
  • 127
  • afaik, there is no such built-in converter in Jena directly. You could ask on the [mailing list](https://groups.google.com/forum/#!forum/topbraid-users) of the [Java API](https://github.com/TopQuadrant/shacl) if there is such a utility method. – UninformedUser Aug 20 '18 at 06:19
  • 1
    Could you elaborate on your use case? What are generated SPARQL queries expected to do? Validate previously uploaded data, identify resources matching a given SHACL shape, …? – A'B Aug 21 '18 at 16:59
  • 1
    We are trying to build a generic data extractor. We get the data, and instead of writing in hard queries for that particular data, we want to use the shacl model of that data to build the query for that data. This way our process will be completely model driven. The alternative is we look at the shacl model and then, write specific query for each entity in each model we get. So in a sense we want to go as far as a the validator does, but for the purpose of getting the actually data, rather than making a valaidation – MaatDeamon Aug 21 '18 at 23:59
  • @MaatDeamon I've only given this about 5 seconds of thought, but given that SHACL is RDF, you could just load it into a store and query it. The results of those queries could then drive the writing of the actual data queries that you want to do. Should be possible with RDF4J, or with Jena, or any rdf framework/database for that matter. – Jeen Broekstra Aug 23 '18 at 05:19
  • Something to explore, but by anticipation given how shacl can be complex, that might now always be easy, but if i keep my shacl ontology simple, that might indeed work. – MaatDeamon Aug 23 '18 at 19:50
  • 1
    I've been working on something like that over the past few months and I can confirm that direct SHACL to SPARQL translation can be tricky: we introduced an intermediate representation based on a constraint tree with a more regular structure, amenable to automated optimisation and translation through the visitor pattern. – A'B Aug 28 '18 at 07:55
  • @A'B @MaatDeamon fwiw in RDF4J there is a `ShapeFactory` that create AST objects for SHACL shapes from the rdf data found in the triplestore. It's not really _intended_ to be used directly but perhaps it's something that can help you out. – Jeen Broekstra Aug 29 '18 at 03:14
  • Thanks will look into that. – MaatDeamon Aug 29 '18 at 15:35

0 Answers0