You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@jena.apache.org by mark <ma...@metarelate.net> on 2014/02/27 14:29:50 UTC

Fuskei: ordering in Construct

Hello

SPARQL and fuseki support results ordering using the 'order by'
statements.

Fuseki implement the ordering of results for SELECT queries
in exactly the way I expect.

However, if I put the same WHERE clause into a CONSTRUCT query
(output="text") the results I get back are not ordered in a way I expect
at all.

The results appear to be consistently ordered for identical tdb content
but any change to the tdb appears to lead to changes in ordering of the
.ttl output.

I do not see how this may be controlled or managed.  I tripped over
this, it came as something of a surprise to me.

Is there a way to control the ordering of output via CONSTRUCT so that
it is handled in the same way as for SELECT?

This would be a very useful feature for me.

many thanks

mark

Re: Fuskei: ordering in Construct

Posted by Chris Dollin <ch...@epimorphics.com>.
On Thursday, February 27, 2014 01:29:50 PM mark wrote

> Is there a way to control the ordering of output via CONSTRUCT so that
> it is handled in the same way as for SELECT?

CONSTRUCT builds a graph. The triples in a graph are not ordered.
When you render the graph to (eg) Turtle, the renderer can emit
the triples in any order it likes; it usually gets whatever's convenient
for the triple store the graph was built in.

Chris

-- 
"And what you've gained is hard to quantify"    - Mermaid Kiss, /Crayola Skies/

Epimorphics Ltd, http://www.epimorphics.com
Registered address: Court Lodge, 105 High Street, Portishead, Bristol BS20 6PT
Epimorphics Ltd. is a limited company registered in England (number 7016688)


Re: Re: Fuskei: ordering in Construct

Posted by Chris Dollin <ch...@epimorphics.com>.
On Thursday, February 27, 2014 01:47:34 PM mark wrote:

> are there tools to help me with this within fuseki and jena, or am I
> going to have to write my own sorting implementation on the output
> stream?

If you're on a Unixy OS, sort has already been written and may do
what you need.

If you can write Java code, Collections.sort has already be written for
you, so long as you can write a RDFNode Comparator (and have
enough memory).

Chris

-- 
"What I don't understand is this ..."   Trevor Chaplin, /The Beiderbeck Affair/

Epimorphics Ltd, http://www.epimorphics.com
Registered address: Court Lodge, 105 High Street, Portishead, Bristol BS20 6PT
Epimorphics Ltd. is a limited company registered in England (number 7016688)


Re: Fuskei: ordering in Construct

Posted by Martynas Jusevičius <ma...@graphity.org>.
Well my usual use case is pagination, with the results sorted per page
by some variable. So my query is usually like this:

DESCRIBE ?thing
{
  SELECT ?thing
  {
    ?thing dct:title ?title
  }
  ORDER BY ?title
  LIMIT 20
  OFFSET 20
}

In this case we retrieve the second page (assuming 20 per page) of
resources ordered by title. But since the ordering is lost in Model, I
sort again when I'm transforming RDF/XML to XHTML, smth like this:

  <xsl:template match="rdf:RDF">
    <div>
      <xsl:apply-templates> <!-- this will match rdf:Descriptions -->
        <xsl:sort select="dct:title"/>
      </xsl:apply-templates>
    </div>
  </xsl:tempate>

Notice <xsl:sort> with dct:title.

If this seems useful to you, check our Graphity Client on
http://graphity.org which has quite a few predefined XSLT templates
like this.


Martynas
graphityhq.com

On Thu, Feb 27, 2014 at 2:47 PM, mark <ma...@metarelate.net> wrote:
> Hello Martynas
>
> many thanks for the swift response.
>
> When you say:
>> You can do post-processing to sort them the way you want
>
> are there tools to help me with this within fuseki and jena, or am I
> going to have to write my own sorting implementation on the output
> stream?
>
> thank you
> mark
>
> On Thu, 27 Feb 2014 14:34:49 +0100
> Martynas Jusevičius <ma...@graphity.org> wrote:
>
>> Mark,
>>
>> if you are using DESCRIBE or CONSTRUCT queries then the result you get
>> is a Model. And a model is a set of statements which is not ordered.
>> You can do post-processing to sort them the way you want, e.g. when
>> you are presenting data to the user.
>>
>> Martynas
>>
>> On Thu, Feb 27, 2014 at 2:29 PM, mark <ma...@metarelate.net> wrote:
>> > Hello
>> >
>> > SPARQL and fuseki support results ordering using the 'order by'
>> > statements.
>> >
>> > Fuseki implement the ordering of results for SELECT queries
>> > in exactly the way I expect.
>> >
>> > However, if I put the same WHERE clause into a CONSTRUCT query
>> > (output="text") the results I get back are not ordered in a way I
>> > expect at all.
>> >
>> > The results appear to be consistently ordered for identical tdb
>> > content but any change to the tdb appears to lead to changes in
>> > ordering of the .ttl output.
>> >
>> > I do not see how this may be controlled or managed.  I tripped over
>> > this, it came as something of a surprise to me.
>> >
>> > Is there a way to control the ordering of output via CONSTRUCT so
>> > that it is handled in the same way as for SELECT?
>> >
>> > This would be a very useful feature for me.
>> >
>> > many thanks
>> >
>> > mark
>

Re: Fuskei: ordering in Construct

Posted by mark <ma...@metarelate.net>.
Hello Martynas

many thanks for the swift response.

When you say:
> You can do post-processing to sort them the way you want

are there tools to help me with this within fuseki and jena, or am I
going to have to write my own sorting implementation on the output
stream?

thank you
mark

On Thu, 27 Feb 2014 14:34:49 +0100
Martynas Jusevičius <ma...@graphity.org> wrote:

> Mark,
> 
> if you are using DESCRIBE or CONSTRUCT queries then the result you get
> is a Model. And a model is a set of statements which is not ordered.
> You can do post-processing to sort them the way you want, e.g. when
> you are presenting data to the user.
> 
> Martynas
> 
> On Thu, Feb 27, 2014 at 2:29 PM, mark <ma...@metarelate.net> wrote:
> > Hello
> >
> > SPARQL and fuseki support results ordering using the 'order by'
> > statements.
> >
> > Fuseki implement the ordering of results for SELECT queries
> > in exactly the way I expect.
> >
> > However, if I put the same WHERE clause into a CONSTRUCT query
> > (output="text") the results I get back are not ordered in a way I
> > expect at all.
> >
> > The results appear to be consistently ordered for identical tdb
> > content but any change to the tdb appears to lead to changes in
> > ordering of the .ttl output.
> >
> > I do not see how this may be controlled or managed.  I tripped over
> > this, it came as something of a surprise to me.
> >
> > Is there a way to control the ordering of output via CONSTRUCT so
> > that it is handled in the same way as for SELECT?
> >
> > This would be a very useful feature for me.
> >
> > many thanks
> >
> > mark


Re: Fuskei: ordering in Construct

Posted by Martynas Jusevičius <ma...@graphity.org>.
Mark,

if you are using DESCRIBE or CONSTRUCT queries then the result you get
is a Model. And a model is a set of statements which is not ordered.
You can do post-processing to sort them the way you want, e.g. when
you are presenting data to the user.

Martynas

On Thu, Feb 27, 2014 at 2:29 PM, mark <ma...@metarelate.net> wrote:
> Hello
>
> SPARQL and fuseki support results ordering using the 'order by'
> statements.
>
> Fuseki implement the ordering of results for SELECT queries
> in exactly the way I expect.
>
> However, if I put the same WHERE clause into a CONSTRUCT query
> (output="text") the results I get back are not ordered in a way I expect
> at all.
>
> The results appear to be consistently ordered for identical tdb content
> but any change to the tdb appears to lead to changes in ordering of the
> .ttl output.
>
> I do not see how this may be controlled or managed.  I tripped over
> this, it came as something of a surprise to me.
>
> Is there a way to control the ordering of output via CONSTRUCT so that
> it is handled in the same way as for SELECT?
>
> This would be a very useful feature for me.
>
> many thanks
>
> mark