- From: Andrea Perego <andrea.perego@uninsubria.it>
- Date: Mon, 14 May 2007 09:08:13 +0200
- To: Public CWM <public-cwm-talk@w3.org>
Thanks. Yes, this is what I did. However, this way I had to specify one
rule for each URI component:
#########################################################################
{?rsc a foaf:Document; log:uri ?uri . ?uri string:matches
  "^(([^:/?#]+):)?(//([^/?#]*))?([^?#]*)(\\?([^#]*))?(#(.*))?"} => {
# Scheme
  {(?uri "^([^:/?#]+):") string:scrape ?scheme} => {?rsc uri:scheme
    ?scheme} .
# Authority
  {(?uri "//([^/?#]*)") string:scrape ?authority} => {
    ?rsc uri:authority ?authority .
# Userinfo
    {(?authority "^([^/?#]*)@") string:scrape ?userinfo} => {?rsc
      uri:userinfo ?userinfo} .
# Host
    {(?authority "([^/?#@:]*)(:[0-9]+)?$") string:scrape ?host} => {?rsc
      uri:host ?host} .
# Port
    {(?authority ":([0-9]+)") string:scrape ?port} => {?rsc uri:port
      ?port} .
  } .
# Path
  {(?uri "//[^/?#]*(/[^?#]*)") string:scrape ?path} => {?rsc uri:path
    ?path} .
# Query
  {(?uri "\\?([^#]*)") string:scrape ?query} => {?rsc uri:query ?query}
    .
# Fragment identifier
  {(?uri "#([^#]*)") string:scrape ?fragment} => {?rsc uri:fragment
    ?fragment} .
} .
#########################################################################
Can this be obtained in a simpler way?
Andrea
Tim Berners-Lee wrote:
> You could use string:match   and string:scrape with regexps.
> 
> Tim BL
> 
> On 2007-04 -23, at 04:52, Andrea Perego wrote:
> 
>>
>> I'm trying to use N3+Cwm in order to decompose a URI into its components
>> (scheme, authority, path, etc.).
>>
>> Suppose we have a resource
>>
>> <http://www.example.com/example1?sec=1#note2> a foaf:Document .
>>
>> and we wish to extend it as follows
>>
>> <http://www.example.com/example1?sec=1#note2> a foaf:Document;
>>   uri:scheme   "http";
>>   uri:host     "www.example.com";
>>   uri:path     "/example1";
>>   uri:query    "sec=1";
>>   uri:fragment "note2" .
>>
>> Is it possible to obtain this through a rule? I checked Cwm's built-ins
>> (especially LOG and STRING), but I couldn't find any tip explaining how
>> this can be done.
>>
>> Thanks
>>
>> Andrea
Received on Monday, 14 May 2007 07:05:16 UTC