W3C home > Mailing lists > Public > semantic-web@w3.org > May 2009

Re: Methods for referencing URIs

From: Toby A Inkster <tai@g5n.co.uk>
Date: Sat, 2 May 2009 19:01:41 +0100
Message-Id: <9B917FD2-3035-497E-8240-2B0CDE9A6CCE@g5n.co.uk>
Cc: Stephane Corlosquet <stephane.corlosquet@deri.org>, Semantic Web <semantic-web@w3.org>, RDFa <public-rdf-in-xhtml-tf@w3.org>
To: John Graybeal <graybeal@mbari.org>
On 2 May 2009, at 17:56, John Graybeal wrote:

> Although I am not grokking the "full URIs" example in Toby's post


For anyone unfamiliar with the syntax or capitalisation conventions  
of PHP, a brief explanation:

> include 'prefixes.php'; # A bunch of constants
> /* ... */
> $object->rdf_mappings = array(
>    'type' => SIOCT.'Weblog',
>    'title' => DC.'title',
>    'body' => SIOC. 'content',
>    'user_id' => DC.'creator',
>  );


Here I'm assuming that SIOCT, DC and SIOC have been defined as string  
constants in the file 'prefixes.php' -- in PHP, like many other  
programming language, it is convention to define constants as upper  
case. The dot-operator acts as a concatenation, so the array keys are  
assigned the full URIs as values, while the code stays reasonable. A  
disadvantage of this approach is that most RDF vocabularies have  
conventional prefixes which are short and may start with any letter  
of the alphabet, which may result in collisions with other constants  
in your program or even keywords in your programming language. (e.g.  
'void' a Javascript keyword.)

> include 'prefixes.php'; # A class definition
> /* ... */
> $object->rdf_mappings = array(
>    'type' => RDF::sioct('Weblog'),
>    'title' => RDF::dc('title'),
>    'body' => RDF::sioc('content'),
>    'user_id' => RDF::dc('creator'),
>  );


Here I'm assuming that prefixes.php instead of defining constants for  
prefixes, defines a class (in the object-oriented programming sense  
of the word) called 'RDF' which has class methods (as against 'object  
methods' which operate on a particular copy of an object belonging to  
the class) named after the prefixes being used. Each method takes a  
string, and returns a string consisting of the full URI corresponding  
to that prefix and suffix. An example PHP class which fulfils this  
would be:

	class RDF
	{
		public static function dc ($suffix)
		{
			return 'http://purl.org/dc/terms/'.$suffix;
		}
		/* ... and so on ... */
	}

This second approach is probably my preferred one, though in  
retrospect, 'CURIE' might make a better name for it than 'RDF'.

-- 
Toby A Inkster
<mailto:mail@tobyinkster.co.uk>
<http://tobyinkster.co.uk>
Received on Saturday, 2 May 2009 18:02:00 GMT

This archive was generated by hypermail 2.3.1 : Tuesday, 26 March 2013 21:45:29 GMT