W3C home > Mailing lists > Public > public-rdf-dawg@w3.org > July to September 2010

Re: GROUP_CONCAT DISTINCT

From: Lee Feigenbaum <lee@thefigtrees.net>
Date: Sun, 19 Sep 2010 19:46:51 -0400
Message-ID: <4C96A0EB.3070709@thefigtrees.net>
To: Axel Polleres <axel.polleres@deri.org>
CC: SPARQL Working Group <public-rdf-dawg@w3.org>
Glitter implements that, though I need to update the syntax for SEPARATOR.

Lee

On 9/19/2010 7:17 PM, Axel Polleres wrote:
> It seems DISTINCT might be quite important for GROUP_CONCAT ...
> I was just playing with the following use case
>
>
> Data:
> @prefix ex:<http://example.org/>  .
> @prefix foaf:<http://xmlns.com/foaf/0.1/>  .
>
> ex:alice a foaf:Person; foaf:name "Alice Wonderland";
>             foaf:nick "Alice", "The real Alice".
>
> ex:bob a foaf:Person;
>         foaf:name "Robert Doe", "Robert Charles Doe", "Robert C. Doe";
>         foaf:nick "Bob","Bobby","RobC","BobDoe".
>
> ex:charles a foaf:Person;
>         foaf:name "Charles Charles";
>         foaf:nick "Charlie" .
> =============
>
> My query should do the following:
> pick one sample name per person, plus a concatenated list of nicknames
>
> query, first version:
>
> =============
>
> PREFIX foaf:<http://xmlns.com/foaf/0.1/>
> SELECT ( SAMPLE(?N) as ?Name)
>         ( GROUP_CONCAT(?M; SEPARATOR = ",") AS ?Nicknames )
> WHERE { ?P a foaf:Person ;
>             foaf:name ?N ;
>             foaf:nick ?M . }
> GROUP BY ?P
>
> =============
>
> doesn't work, since the nicknames appear repeated... I suppose this is where I'd need DISTINCT, but I couldn't get that
> following version running yet with any implementation:
>
> =============
> PREFIX foaf:<http://xmlns.com/foaf/0.1/>
> SELECT ( SAMPLE(?N) as ?Name)
>         ( GROUP_CONCAT( DISTINCT ?M; SEPARATOR = ",") AS ?Nicknames )
> WHERE { ?P a foaf:Person ;
>             foaf:name ?N ;
>             foaf:nick ?M . }
> GROUP BY ?P
>
> =============
>
> My expected result for the latter query was something like:
> --------------------------------------------------------------------------------------------
> | Name               | Nicknames                                                           |
> ============================================================================================
> | "Robert C. Doe"    | "BobDoe,RobC,Bobby,Bob" |
> | "Alice Wonderland" | "The real Alice,Alice"                                              |
> | "Charles Charles"  | "Charlie"                                                           |
> --------------------------------------------------------------------------------------------
>
> Does anybody have that implemented/running yet?
>
> best,
> Axel
>
Received on Sunday, 19 September 2010 23:47:29 GMT

This archive was generated by hypermail 2.3.1 : Tuesday, 26 March 2013 16:15:43 GMT