Note that there are some explanatory texts on larger screens.

plurals
  1. POSPARQL get more than one subitem
    text
    copied!<p>I query an API with a simple SPARQL query:</p> <pre><code>PREFIX ... SELECT DISTINCT * WHERE { ?item dct:date ?date . ?item dct:title ?title . ?item rdfs:info ?info . } </code></pre> <p>And this returns me an xml </p> <pre><code>&lt;results&gt; &lt;result&gt; &lt;binding name='title'&gt; &lt;literal&gt;titletitle&lt;/literal&gt; &lt;/binding&gt; &lt;binding name='info'&gt; &lt;uri&gt;link&lt;/uri&gt; &lt;/binding&gt; &lt;binding name='date'&gt; &lt;literal datatype='http://www.w3.org/2001/XMLSchema#dateTime'&gt;2012-12-21T02:26:00+00:00&lt;/literal&gt; &lt;/binding&gt; &lt;binding name='item'&gt; &lt;uri&gt;link&lt;/uri&gt; &lt;/binding&gt; &lt;/result&gt; ... &lt;/results&gt; </code></pre> <p>But the problem is: I know, that there are more than one links of rdfs:info matched to this item. How can I query such that I get </p> <pre><code>... &lt;binding name='info'&gt; &lt;uri&gt;link1&lt;/uri&gt; &lt;/binding&gt; &lt;binding name='info'&gt; &lt;uri&gt;link2&lt;/uri&gt; &lt;/binding&gt; &lt;binding name='info'&gt; &lt;uri&gt;link3&lt;/uri&gt; &lt;/binding&gt; ... </code></pre> <p>? Is this simple, or do I need a subquery or some strange <code>UNION</code>? If I just try</p> <pre><code> PREFIX ... SELECT DISTINCT * WHERE { ?item dct:date ?date . ?item dct:title ?title . OPTIONAL (?item rdfs:info ?info1 ). OPTIONAL (?item rdfs:info ?info2 ). } </code></pre> <p>that would return all possible permutations of the values of <code>?info1</code> and <code>?info2</code>. Plus, I don't know the number of info items.</p> <p>If I add <code>FILTER (?info1 != ?info2)</code>, I still get some permutations. I think from an algebraic point of view it would be possible to <code>FILTER (?info1 &lt; ?info2)</code>, to discard permutations. But how can I apply <code>&lt;</code> on uris? </p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload