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

Re: limit per resource rethought...

From: Axel Polleres <axel.polleres@deri.org>
Date: Wed, 11 Aug 2010 17:59:32 +0100
Message-Id: <4B9077B3-54B5-42DD-935B-F9B320BCC70D@deri.org>
To: Steve Harris <steve.harris@garlik.com>, SPARQL Working Group <public-rdf-dawg@w3.org>
> "Give me all persons and the first 3 (alphabetically by name) of their friends"


An awkward workaround for that query... I think it could be done, ugly, something like as follows:

  SELECT ?P ?F
  { ?P a :Person . 
    OPTIONAL { ?P :knows ?F FILTER ( NOT EXISTS {?P :knows ?F1,?F2,?F3 FILTER (?F1 <?F && ?F2 < ? F && ?F3 < ?F ) } )   
  } ORDER BY ?P,?F


not yet tested... but BRRRRRRRRRRRRRRRRRRR! ;-\

I don't see a way to do this at all with LIMIT so far...

Axel


On 11 Aug 2010, at 11:23, Steve Harris wrote:

> On 2010-08-11, at 10:56, Axel Polleres wrote:
> 
> > Hi all again,
> >
> > in the course of my last mail, I also thought about adding another example:
> >
> > E)  "Give me all persons and the first 3 (alphabetically by name) of their friends"
> >
> > but I couldn't find any way to write this in an intuitive manner... ideas anyone?
> > I am afraid, that - by the scoping we have imposed for subqueries - that one might be difficult/impossible?
> >
> > The following naive writing  does't work obviously:
> >
> >  SELECT ?P ?F
> >  { ?P a :Person .
> >    {SELECT ?P ?F { ?P :knows ?F . ?F name ?N } ORDER BY ?N LIMIT 3 }
> >  }
> >
> > I also think I recall that we had this discussion already some time back in some other form,
> > but I can't recall the outcome :-|
> 
> This doesn't work because bindings happen bottom up, so the subSELECT is bound before the outer SELECT, I find this counter-intuative, but there are technical reasons why it has to be that way round, as I understand it.
> 
> Another thing that also doesn't quite work is:
> 
> SELECT ?p (SAMPLE(?f) AS ?f1) (SAMPLE(?f) AS ?f2) (SAMPLE(?f) AS ?f3)
> WHERE {
>    ?p a :Person .
>    ?p :knows ?f .
> } GROUP BY ?p
> 
> The problem is that by the definition of the Sample set function, you get the same binding of ?f each time.
> 
> We could have a form of SAMPLE() like SAMPLE(?var ; offset=N), which takes the Nth value, rather than the 0th.
> 
> - Steve
> 
> PS look, no commas :)
> 
> --
> Steve Harris, CTO, Garlik Limited
> 1-3 Halford Road, Richmond, TW10 6AW, UK
> +44 20 8439 8203  http://www.garlik.com/
> Registered in England and Wales 535 7233 VAT # 849 0517 11
> Registered office: Thames House, Portsmouth Road, Esher, Surrey, KT10 9AD
> 
> 
Received on Wednesday, 11 August 2010 17:00:04 GMT

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