Re: PROPOSAL to close ISSUE-61: Does the RDFa API need a vocabulary helper

Manu Sporny wrote:
> On 01/03/2011 12:42 AM, Ivan Herman wrote:
>>> For example, the following is possible when using the RDF API:
>>> var rdf =; rdf.prefixes.foaf =
>>> ""; var foafname =
>>> rdf.resolve("foaf:name"); // at this point, foafname ==
>>> ""
>>> Given the code above, the following is also possible using the RDF
>>> API:
>>> var short = rdf.prefixes.shrink(foafname); // at this point short
>>> == "foaf:name"
>> The direct counterpart of the original issue/proposal would be to
>> have a definition of prefixes so that I could also say
>> var foafname = rdf.prefixes.foaf('name')
>> Ie, once I have defined the prefix I would not have to repeat it
>> verbatim because it becomes a function of its own right.
> Hmm, this is an interesting twist on what's in the spec right now and
> may address your request below, Ivan.

first, just a quick note that you can currently do:

   rdf.prefixes.foaf + 'name'

however, primarily if you want stable resolution in a modular 
environment then you just instantiate your own PrefixMap or Profile and 
use that in your script/lib/module

   x.foaf + 'name'

moving on to proposal below:

> I haven't tried this out, so there may be something preventing us from
> doing this in JavaScript, but basically, we'd change the PrefixMap
> interface from this:
> omittable getter DOMString get(in DOMString prefix);
> omittable setter void set(in DOMString prefix, in DOMString iri);
> to this (note the change in return type for get()):
> omittable getter PrefixResolver get(in DOMString prefix);
> omittable setter void set(in DOMString prefix, in DOMString iri);
> [Callback]
> interface PrefixResolver
> {
>    DOMString resolve(in DOMString prefix);
> }

sadly that's not possible, even with ECMAScript-262 v5 features, because 
of the setter, it would need to be a defined method such as setPrefix 
which would then define a magic property on the object to enable


However you'd need v5 advanced features and it's far from "normal" js 

That said, in a previous revision of the api, there was another 
(disputed iirc) approach, which was to change the return type of 
Profile::setPrefix from void to a "PrefixResolver", so you'd:

   foaf = rdf.setPrefix('foaf', '');

then you could do:

   rdf.prefixes.foaf + name

and you could still ignore this functionality and just do the 
getter/setter approach if you wanted:

   rdf.prefixes.foaf = ''
   rdf.prefixes.foaf + name

this is something of a happy medium which allows the compact functional 
style implemented in tabulator foaf('name'), and the current dictionary 
type approach.



Received on Thursday, 13 January 2011 09:40:11 UTC