Re: Methods for referencing URIs

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 UTC