Hi Felix,
constructing rdf:Lists from SPARQL is notoriously hard. We have a work-around "magic property" that works for some use cases but not others, but I mention it here:
/**
<span class="style1">tops:constructRDFList</span>
<p>(Experimental) This function binds variables for
constructing an RDF list.
It can be best used in a CONSTRUCT query. It is an experimental
function, so it may work
only in certain cases.</p>
<ul>
<li><i>Syntax:</i> <span
class="style1">(?list ?subList ?element ?rest)
tops:constructRDFList (?s ?p ?o) .</span></li>
<li><i>Description:</i> The function iterates
through <span class="style1">?s ?p ?o</span> to
bind variables for constructing a list. Currently, only one
variable in <span class="style1">?s ?p ?o</span>
should be unassigned, and the other two should be assigned. Also
the property "rdf:type" should be used instead of "a".
<span class="style1">?list</span> variable is used as
the head
of the list and stays constant throughout the iteration, <span
class="style1">?subList</span>
is used as the sub heads of the list and changes with each
iteration, <span class="style1">?element</span>
is the unbound variable in <span class="style1">?s ?p
?o</span> and changes with each iteration,
and <span class="style1">?rest</span> is the bound
<span class="style1">?subList</span> of the
next iteration, which the current iteration points to.</li>
<li><i>Example:</i> In the following query,
<span class="style1">tops:constructRDFList</span>
constructs
an <span class="style1">owl:oneOf</span> list of
colleges. Here is the query and its usage in kennedys
ontology:</li>
<pre>
CONSTRUCT {
kennedys:College owl:oneOf ?list .
?subList rdf:first ?element .
?subList rdf:rest ?rest .
}
WHERE {
(?list ?subList ?element ?rest) tops:constructRDFList (?s
rdf:type kennedys:College) .
}
</pre>
</ul>
<p><b>Known limitations:</b> Only one variable
in <span class="style1">?s ?p ?o</span>
should be unassigned, and the other two should be assigned. The
property "rdf:type" should be used instead of "a" in the
function.</p>
*/
It depends on how the WHERE clause looks like whether this could
be used in your scenario. The tops namespace is
http://www.topbraid.org/tops
But for complex tasks involving recursive data structures such as rdf:Lists you'll be better off using a generic scripting language such as TopBraid's ADS JavaScript support.
Holger
--
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/CAL58czrLFr-496KOMKEMFoBj-Awh36XM-7QPtCMbjqRNMhkWOQ%40mail.gmail.com.
Hi Holger,
thanks, that is very helpful for me and for deciding how to move forward. One follow-up question: I would like to generate a complete SHACL query via Wikidata, see an example here
in the example query, I don't create one RDF list, but several sh:in predicates. Would that work as well, for SHACL validation?
No, the values of sh:in are expected to be rdf:Lists, i.e. a
single, closed list for all states in your example. If you want to
have an extensible list of values, and you had control over the
data, you could create a class such as schema:GermanState and just
use sh:class to point at it.
Holger
To view this discussion on the web visit https://groups.google.com/d/msgid/topbraid-users/01dbca04-6b1f-4e96-89d5-aa085561de69n%40googlegroups.com.