#!/usr/bin/perl # Parse a URI (or URI) into it's parts, and describe them in RDF> # Dan Brickley # # regex from Jo Rabin, http://www.w3.org/2005/Incubator/wcl/matching.html # thanks to: Kjetilk, LeeF and EliasT in #swig # see http://chatlogs.planetrdf.com/swig/2006-06-30#T20-02-35 # # note: we currently use a 404 namespace URI print "\n\n"; foreach my $uri () { next if ($uri =~ m/^#/); next unless ($uri =~ m/\w/); chomp $uri; $uri =~ m!^(([^:/?#]+):)?(//((([^/?#]*)@)?([^/?#:]*)(:([^/?#]*))?))?([^?#]*)(\?([^#]*))?(#(.*))?!; my ($scheme, $authority, $userinfo, $host, $port, $path, $query, $fragment) = ($2, $4, $6, $7, $9, $10, $12, $14); print "\n"; print " $uri \n"; print " \n"; print " $scheme \n" if $scheme; print " $authority \n" if $authority; print " $userinfo \n" if $userinfo; print " $host \n" if $host; print " $port \n" if $port; print " $path \n" if $path; print " $query \n" if $query; print " $fragment \n" if $fragment; print "\n\n"; } print "\n\n"; # resources: # on IRI testing, # http://www.w3.org/2001/Talks/0912-IUC-IRI/paper.html # # http://librdf.org/query?uri=http%3A%2F%2Fspypixel.com%2F2006%2Fwcl%2Furi%2F_data.rdf&query=PREFIX+rdf%3A+%3Chttp%3A%2F%2Fwww.w3.org%2F1999%2F02%2F22-rdf-syntax-ns%23%3E%0D%0APREFIX+u%3A+%3Chttp%3A%2F%2Fwww.w3.org%2F2004%2F12%2Fq%2Fidsyntax%23%3E%0D%0ASELECT+DISTINCT+*%0D%0AWHERE+%7B%0D%0A++%3Fid+rdf%3Atype+u%3AID+.%0D%0A++%3Fid+u%3Afull+%3Ffull+.%0D%0A++%3Fid+u%3AnameFor+%3Fres+.%0D%0A++%3Fid+u%3Ascheme+%3Fscheme+.%0D%0A++%3Fid+u%3Aauthority+%3Fauthority+.%0D%0A++OPTIONAL+%7B+%3Fid+u%3Ahost+%3Fhost+%7D+.%0D%0A++OPTIONAL+%7B+%3Fid+u%3Aport+%3Fport+%7D+.%0D%0A++OPTIONAL+%7B+%3Fid+u%3Apath+%3Fpath+%7D+.%0D%0A++OPTIONAL+%7B+%3Fid+u%3Aquery+%3Fquery+%7D+.%0D%0A++OPTIONAL+%7B+%3Fid+u%3Afragment+%3Ffragment+%7D+.+%0D%0A%7D%0D%0A&language=sparql&Run+Query=Run+Query&.cgifields=language&.cgifields=json&.cgifields=raw # # PREFIX u: # SELECT DISTINCT * # WHERE { # ?id a u:ID . # ?id u:full ?full . # ?id u:nameFor ?res . # ?id u:scheme ?scheme . # ?id u:authority ?authority . # OPTIONAL { ?id u:host ?host } . # OPTIONAL { ?id u:port ?port } . # OPTIONAL { ?id u:path ?path } . # OPTIONAL { ?id u:query ?query } . # OPTIONAL { ?id u:fragment ?fragment } . # } # # URL testing: # http://www.w3.org/Addressing/url_test/url_grammar.tests # URI Test cases from Graham Klyne: # http://www.ninebynine.org/Software/HaskellUtils/Network/URITestDescriptions.html