W3C home > Mailing lists > Public > public-lod@w3.org > March 2010

SPARQL: sorting resources by label?

From: Axel Rauschmayer <axel@rauschma.de>
Date: Sat, 13 Mar 2010 04:16:46 +0100
Message-Id: <27FA8DD3-5019-40E5-8844-EC7D06964544@rauschma.de>
To: public-lod@w3.org
The closest I get is the following SPARQL query:

> SELECT DISTINCT ?subj ?label
> WHERE {
>     GRAPH ?graph {
>         ?subj ?pred ?obj .
>         OPTIONAL {
>             ?subj ?labelPred ?label .
>             FILTER (
>                 (?labelPred = <http://www.w3.org/2000/01/rdf-schema#label>) # (1)
>             )
>             FILTER( isLiteral(?label) )
>         }
>     }
>     FILTER (?graph = <http://hypergraphs.de/TestGraph>)
> }
> ORDER BY ?label ?subj

Comments:

- This solution also works for multiple label predicates (i.e., if there are subproperties of rdfs:label), then the unary disjunction (1) has more components.

- ?graph is necessary, because Sesame does not support datasets and I want to restrict the query to all graphs that are currently "visible".

- This query returns unlabeled resources first (?label is unbound), then labeled resources. Better would be to show labeled resources first. Best would be to mix them, where unlabeled resources are sorted according to their qname.

Can this be improved?

Thanks for any comments or suggestions...

Axel

-- 
Axel.Rauschmayer@ifi.lmu.de
http://www.pst.ifi.lmu.de/~rauschma/
Received on Saturday, 13 March 2010 03:17:20 UTC

This archive was generated by hypermail 2.3.1 : Sunday, 31 March 2013 14:24:25 UTC