I query an API with a simple SPARQL query:

PREFIX ...
SELECT DISTINCT *
    WHERE {
    ?item dct:date ?date .
    ?item dct:title ?title .
    ?item rdfs:info ?info .
    }

And this returns me an xml

<results>
    <result>
    <binding name='title'>
            <literal>titletitle</literal>
        </binding>
        <binding name='info'>
            <uri>link</uri>
        </binding>
        <binding name='date'>
            <literal datatype='http://www.w3.org/2001/XMLSchema#dateTime'>
                2012-12-21T02:26:00+00:00
            </literal>
        </binding>
        <binding name='item'>
            <uri>link</uri>
        </binding>
    </result>
    ...
</results>

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

...
<binding name='info'>
    <uri>link1</uri>
</binding>
<binding name='info'>
    <uri>link2</uri>
</binding>
<binding name='info'>
    <uri>link3</uri>
</binding>
...

? Is this simple, or do I need a subquery or some strange UNION? If I just try

    PREFIX ...
SELECT DISTINCT *
    WHERE {
    ?item dct:date ?date .
    ?item dct:title ?title .
    OPTIONAL (?item rdfs:info ?info1 ).
    OPTIONAL (?item rdfs:info ?info2 ).
    }

that would return all possible permutations of the values of ?info1 and ?info2. Plus, I don't know the number of info items.

If I add FILTER (?info1 != ?info2), I still get some permutations. I think from an algebraic point of view it would be possible to FILTER (?info1<?info2), to discard permutations. But how can I apply < on uris?

asked 15 Jan '13, 05:23

Milla%20Well's gravatar image

Milla Well
336
accept rate: 0%

edited 15 Jan '13, 05:45

Antoine%20Zimmermann's gravatar image

Antoine Zimm... ♦
10.3k514

I also could imagine a DISTINCT ON which ignores the optional parameters, but google couldn't find such a thing. Could you?

(15 Jan '13, 05:28) Milla Well Milla%20Well's gravatar image
1

Asked on Stack Overflow http://stackoverflow.com/questions/14334252/sparql-get-more-than-one-subitem . Please avoid broadcasting your questions everywhere. You are using contributors' time, free of charge. Don't spend multiple audience's time. In general be assured that you'll get good responses on answers.semanticweb.com for anything Semantic-Webish. Most of the time, the people who are likely to answer you on Stack Overflow (for SemWeb questions) are the very same as the ones who answer you here. Advice: ask the question here first and if you don't get an answer after few days, try SO.

(15 Jan '13, 05:39) Antoine Zimm... ♦ Antoine%20Zimmermann's gravatar image
2

I did, and had almost no reaction, then, as I already commented on stackoverflow: voted for closing there, because I just found this site. Thanks for voting for closing on SO

(15 Jan '13, 05:40) Milla Well Milla%20Well's gravatar image

Ok, good that you posted a link from SO. My comment is also for other readers who may be tempted to ask the question wherever they can. We get this often and not many have the diligence to put a link as you did.

(15 Jan '13, 05:50) Antoine Zimm... ♦ Antoine%20Zimmermann's gravatar image

BTW, there is an answer on Stack Overflow.

(15 Jan '13, 05:50) Antoine Zimm... ♦ Antoine%20Zimmermann's gravatar image
1

@Milla Well You really need to be prepared to wait a bit longer than an hour to get an answer! As @Antoine Zimmerman said sites like Answers and SO are not paid support services, they run by people donating their time to answer questions. And don't forget many people are likely in very different time zones from you, you should be prepared to wait a day or two to get answers particularly when posting on a relatively niche topic like Semantic Web

(15 Jan '13, 06:31) Rob Vesse ♦ Rob%20Vesse's gravatar image
showing 5 of 6 show 1 more comments

Here is something you can do:

SELECT ?item ?date ?title (GROUP_CONCAT(?title ; SEPARATOR = ', ') AS ?infos)
WHERE {
    ?item dct:date ?date .
    ?item dct:title ?title .
    ?item rdfs:info ?info .
}
GROUP BY ?item ?date ?title
permanent link

answered 15 Jan '13, 05:58

Antoine%20Zimmermann's gravatar image

Antoine Zimm... ♦
10.3k514
accept rate: 32%

there is a GROUP_CONCAT? this is just awesome! I will try it

(15 Jan '13, 06:44) Milla Well Milla%20Well's gravatar image

GROUP_CONCAT was introduced in SPARQL 1.1, which is on the verge of being standardised. Most SPARQL engines support SPARQL 1.1 now.

(15 Jan '13, 07:03) Antoine Zimm... ♦ Antoine%20Zimmermann's gravatar image

today I finally tried it. This gives me a speedup compared to subqueries, of about a factor of 500.000. this ist just the best thing happend today.

(06 Feb '13, 12:18) Milla Well Milla%20Well's gravatar image
Your answer
toggle preview

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Markdown Basics

  • *italic* or _italic_
  • **bold** or __bold__
  • link:[text](http://url.com/ "title")
  • image?![alt text](/path/img.jpg "title")
  • numbered list: 1. Foo 2. Bar
  • to add a line break simply add two spaces to where you would like the new line to be.
  • basic HTML tags are also supported

Question tags:

×1,302
×46

question asked: 15 Jan '13, 05:23

question was seen: 1,414 times

last updated: 06 Feb '13, 12:18