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

Re: GROUP_CONCAT DISTINCT

From: Axel Polleres <axel.polleres@deri.org>
Date: Mon, 20 Sep 2010 00:48:51 +0100
Message-Id: <DA32E8E1-217D-4A59-A3A0-604B15185864@deri.org>
To: Axel Polleres <axel.polleres@deri.org>, SPARQL Working Group <public-rdf-dawg@w3.org>
> Does anybody have that implemented/running yet?


Alright, got it running on greg's endpoint 

http://myrdf.us/sparql11?query=PREFIX+foaf%3A+%3Chttp%3A%2F%2Fxmlns.com%2Ffoaf%2F0.1%2F%3E%0D%0APREFIX+foaf%3A+%3Chttp%3A%2F%2Fxmlns.com%2Ffoaf%2F0.1%2F%3E+%0D%0ASELECT+%28+SAMPLE%28%3FN%29+AS+%3FName%29+%0D%0A+++++++%28+GROUP_CONCAT%28+DISTINCT+%3FM+%3B+SEPERATOR%3D%22%2C+%22%29+AS+%3FNicknames+%29%0D%0AFROM+%3Chttp%3A%2F%2Faxel.deri.ie%2F~axepol%2FRR2010_SPARQL11_Tutorial%2Fdata4.rdf%3E%0D%0AWHERE+{+%3FP+a+foaf%3APerson+%3B+%0D%0A+++++++++++foaf%3Aname+%3FN+%3B%0D%0A+++++++++++foaf%3Anick+%3FM+.+}%0D%0AGROUP+BY+%3FP+&media-type=text%2Fhtml&submit=Submit


cheers,
Axel

On 20 Sep 2010, at 00:17, 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:49:26 GMT

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