sh:in

46 views
Skip to first unread message

Kasia Kryczka

unread,
Jun 29, 2023, 9:22:30 AM6/29/23
to TopBraid Suite Users
Hi everyone,
I want insert a list of types to sh:in which would be :

<uri>
  sh:in (
      "aaa"
      "bbb"
      "ccc"
    ) ;


my query doesn't work :
INSERT{
<URI> sh:in ?product
  }

WHERE {
  SELECT  ?product
#  (GROUP_CONCAT(?product; SEPARATOR=', ') AS ?result)
  {

    BIND(teamwork:currentMasterGraph() as ?cGraph)

GRAPH ?cGraph
  {?cGraph owl:imports ?import}

  GRAPH ?import{
        ?d a skos:Concept.
        ?d skos:hasTopConcept ?Concept.
          ?ProductT skos:broader ?Concept.
        ?ProductT uri:product ?product .
          }
  FILTER(CONTAINS(STR(?Concept),"service"))

##    BIND (ui:label(?product) AS ?label) .
 
  }GROUP BY ?product }

the result with concat_group is <uri>
  sh:in (
      "aaa,bbb, ccc"
    ) ;

and this is not what I need. 

Could you give me a hint how to resolve this?

Thanks,

Kasia

Holger Knublauch

unread,
Jun 29, 2023, 10:36:41 AM6/29/23
to topbrai...@googlegroups.com
The value of sh:in is an rdf:List. Lists consist of intermediate notes that are linked into a chain using rdf:first and rdf:rest. The usual trick to walk such chains is to use a SPARQL path expression. The following may work for you:L

SELECT ?item
WHERE {
<uri> sh:in ?list .
?list rdf:rest*/rdf:first ?item .
}

where rdf:rest* is walking through all list elements and rdf:first fetches the actual value of each element.

HTH
Holger


--
The topics of this mailing list include TopBraid EDG and related technologies such as SHACL.
To post to this group, send email to topbrai...@googlegroups.com
---
You received this message because you are subscribed to the Google Groups "TopBraid Suite Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to topbraid-user...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/topbraid-users/ead4c18d-f520-47f3-8664-022c51c6c286n%40googlegroups.com.

Kasia Kryczka

unread,
Jun 30, 2023, 10:18:40 AM6/30/23
to TopBraid Suite Users
Hi Holger, 

Thank you. 

Just to clarify so I fully understand because now I don't have  a sh:in list  but I want to create one from  the imports that are included in the cGraph:

SELECT  ?product
#  (GROUP_CONCAT(?product; SEPARATOR=', ') AS ?result)
  {
    BIND(teamwork:currentMasterGraph() as ?cGraph)
GRAPH ?cGraph
  {?cGraph owl:imports ?import}
  GRAPH ?import{
        ?d a skos:Concept.
        ?d skos:hasTopConcept ?Concept.
          ?ProductT skos:broader ?Concept.
        ?ProductT uri:product ?product .
          }
  FILTER(CONTAINS(STR(?Concept),"service"))

##    BIND (ui:label(?product) AS ?label) .
 
  }GROUP BY ?product }


but I don't know how to insert that. 

Thanks, 

Kasia

Holger Knublauch

unread,
Jun 30, 2023, 11:25:58 AM6/30/23
to topbrai...@googlegroups.com
Ok thanks, I now understand the question better.

The problem of generating rdf:Lists with SPARQL has been observed by other users too and is an inherent limitation of SPARQL. It cannot be done in general, although you could write INSERTs for certain list lengths, e.g. produce all BNODE() for each list item up to length of three and then link them together. But even that would be a terrible syntax. One problem is SPARQL’s lack or recursion.

To generate RDF lists or similarly complex structures, you would need to use a scripting language. TopBraid EDG includes JavaScript support from its Script Editor panel, see


where you can produce even the most complex structures and use JavaScript to orchestrate arbitrary SPARQL queries too.

If that’s an option for you, feel free to ask follow-up questions.

Holger


Kasia Kryczka

unread,
Jul 6, 2023, 9:46:47 AM7/6/23
to TopBraid Suite Users
Hi Holger,

thank you for the explanation.

I'll try to create sth on my own and surely I will come back to you with some additional questions :)

Br,

Kasia

Reply all
Reply to author
Forward
0 new messages