Re: limit per resource rethought...

> "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 UTC