1

I have a ttl file that looks like this:

ex:Shape1
    a sh:NodeShape ;
    sh:property ex:Property-1
    rdfs:label "Shape 1"

ex:Property-1
    a sh:PropertyShape ;
    sh:path ex:property1
    sh:in (
        "Option 1"
        "Option 2"
    ) ;
    sh:name "Property 1"

ex:property1
    a owl:DatatypeProperty

After loading the above data into my triple store (which contains many shapes already), what query can I use to retrieve the same data back?

This query gets everything I need except for the list. For the list it only gives a blank node.

PREFIX sh: <http://www.w3.org/ns/shacl#>
PREFIX ex: <http://example.com/#>

CONSTRUCT {
  ?subject ?predicate ?object
}
WHERE {
  {
    bind(ex:Shape1 as ?subject)
    ex:Shape1 ?predicate ?object
  }
  UNION
  {
     ex:Shape1 sh:property ?subject .
    ?subject ?predicate ?object
  }
  UNION
  {
    ex:Shape1 sh:property/sh:path ?subject .
    ?subject ?predicate ?object
  }
}
agustaf
  • 683
  • 1
  • 6
  • 19
  • see the Turtle specs how a list is internally serialized in RDF as a set of RDF triples: https://www.w3.org/TR/turtle/#collections – UninformedUser Jun 07 '22 at 04:52
  • I've read that, and saw this similar question: https://stackoverflow.com/questions/4422197 but It is not clear to me how to construct the list when it is nested into another property. – agustaf Jun 07 '22 at 19:26

1 Answers1

0

First of all, why do you need to query to get the same data back? Do you mean you need to get it in the same syntax and formatting?

  • to get the same data in the form of triples, you can simply execute SELECT * from ?s ?p ?o and it will give you all the triples. It also depends on your triplestore.

  • The standard query to fetch the items in your list would be the following:

    PREFIX sh: <http://www.w3.org/ns/shacl#>
    PREFIX ex: <http://example.com/#>
    PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
    SELECT ?item
    WHERE {
      ex:Property-1 sh:in/rdf:rest*/rdf:first ?item
    }
    

You can read more about how the list items are stored internally. This link will be helpful. You can bind the ex:Property-1 in the same way in UNION or WHERE clause in your construct query to get the desired result.

I hope it is helpful. Good luck.

  • This question is related to another one: https://stackoverflow.com/q/72521705/3727991. I am trying to reconstruct a SHACL shape in a store with many other SHACL shapes. – agustaf Jun 15 '22 at 16:36