W3C home > Mailing lists > Public > public-cwm-talk@w3.org > July to September 2006

log:outputString ordering challenge

From: Ralph R. Swick <swick@csail.mit.edu>
Date: Thu, 06 Jul 2006 12:02:42 -0400
Message-Id: <5.1.0.14.2.20060706114823.04bec8d8@127.0.0.1>
To: public-cwm-talk@w3.org

Scenario: use log:outputString to display some properties of the
members of an rdf:Seq container, in order.

Challenge: Yosi came up with the four statements in the rule below
that successfully produce a sort key from the rdf:_n properties.
Is there a shorter way?

(The "properties of the members" in this test data are trivial;
this is greatly simplified from a real case where the members
are nodes with multiple properties and the rule extracts some
of those properties for display.)

% cat memberorder.n3
@prefix rdf:    <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .
@prefix rdfs:   <http://www.w3.org/2000/01/rdf-schema#> .
@prefix xsd:    <http://www.w3.org/2001/XMLSchema#> .

@prefix log:    <http://www.w3.org/2000/10/swap/log#> .
@prefix str:    <http://www.w3.org/2000/10/swap/string#> .

[ a rdf:Seq;
  rdf:_1 "one\n";
  rdf:_2 "two\n";
  rdf:_3 "three\n";
  rdf:_4 "four\n";
  rdf:_5 "five\n";
  rdf:_6 "six\n";
  rdf:_7 "seven\n";
  rdf:_8 "eight\n";
  rdf:_9 "nine\n";
  rdf:_10 "ten\n";
  rdf:_11 "eleven\n";
  rdf:_12 "twelve\n";
  rdf:_13 "thirteen\n";
] .

rdf:_1 a rdfs:ContainerMembershipProperty .
rdf:_2 a rdfs:ContainerMembershipProperty .
rdf:_3 a rdfs:ContainerMembershipProperty .
rdf:_4 a rdfs:ContainerMembershipProperty .
rdf:_5 a rdfs:ContainerMembershipProperty .
rdf:_6 a rdfs:ContainerMembershipProperty .
rdf:_7 a rdfs:ContainerMembershipProperty .
rdf:_8 a rdfs:ContainerMembershipProperty .
rdf:_9 a rdfs:ContainerMembershipProperty .

rdf:_10 a rdfs:ContainerMembershipProperty .
rdf:_11 a rdfs:ContainerMembershipProperty .
rdf:_12 a rdfs:ContainerMembershipProperty .
rdf:_13 a rdfs:ContainerMembershipProperty .

{
  ?s ?p ?v .
  ?p a rdfs:ContainerMembershipProperty .

  # the next four statements construct a key ?k that will sort
  # the same way numerically and lexographically.  Thanks
  # to Yosi Scharf for assistance working this out.
  ?p log:uri ?u.
  (?u ".*?([0-9]*)$") str:scrape ?li .
  (?li xsd:integer) log:dtlit ?n .
  ("%020i" ?n) str:format ?k .
}
log:implies
{
  ?k log:outputString ?v .
}.
% cwm memberorder.n3 --rules -strings
one
two
three
four
five
six
seven
eight
nine
ten
eleven
twelve
thirteen
%
Received on Thursday, 6 July 2006 16:03:25 UTC

This archive was generated by hypermail 2.3.1 : Tuesday, 6 January 2015 20:01:05 UTC