W3C home > Mailing lists > Public > public-rdfa-wg@w3.org > November 2010

Re: RDFa API - adding Namespace

From: Tim Berners-Lee <timbl@w3.org>
Date: Wed, 17 Nov 2010 07:32:12 -0500
Cc: Shane McCarron <shane@aptest.com>, Mark Birbeck <mark.birbeck@webbackplane.com>, RDFA Working Group <public-rdfa-wg@w3.org>
Message-Id: <246C07EC-538E-401D-8DF2-DA3F39A6966B@w3.org>
To: nathan@webr3.org
No intention to pollute the global namespace.  Note python one declares explicitly, in JS I suggest
things like this are hung off both a singe rdf object and the graph object, a bi tlike:

{
	var $rdf = document.rdf;
	var g = $rdf.graph();
var foaf = g.ns("http://xmlns.com/foaf/0.1/");
var RDFS = g.ns("http://www.w3.org/2000/01/rdf-schema#");
var dc = vocab("http://purl.org/dc/elements/1.1/");
var rss = vocab("http://purl.org/rss/1.0/");
var contact = vocab("http://www.w3.org/2000/10/swap/pim/contact#");
	...
}



On 2010-10 -09, at 21:05, Nathan wrote:

> Hi Tim,
> 
> We have one big issue though, in that the web-apps/html working group have said that we should avoid 'polluting' the global namespace and to annotate all interfaces with [NoInterfaceObject], which means we can't do new IRI, new BlankNode and this would include vocab() prefix() and anything like that, this is why we've had to go for data.createIRI() data.context.setMapping() and so forth.
> 
> Essentially [NoInterfaceObject] means that `typeof IRI` must return undefined.
> 
> AFAIK, simply the browsers won't implement unless it's done this way - perhaps one of the others can confirm this as it was before my time as a WG member.
> 
> An implementation could of course implement this functionality quite easily and provide it to users of said implementation...
> 
> Best,
> 
> Nathan
> 
> Tim Berners-Lee wrote:
>> On 2010-10 -09, at 14:25, Shane McCarron wrote:
>>> Is there some way we can NOT call this namespaces?  People will confuse this with XML Namespaces, which it assuredly is not.  "Vocabulary" is the term we use most often.  In this case, what you are doing is defining a "Vocabulary Shortcut".  This is pure syntactic sugar, but I don't mind adding it if there is an audience who expects this sort of thing.  But please, please, please don't call it Namespaces.  Please.
>> There is quite a lot of code written using Here is early in one file:
>> foaf = Namespace("http://xmlns.com/foaf/0.1/")
>> RDFS = Namespace("http://www.w3.org/2000/01/rdf-schema#")
>> dc = Namespace("http://purl.org/dc/elements/1.1/")
>> rss = Namespace("http://purl.org/rss/1.0/")
>> contact = Namespace("http://www.w3.org/2000/10/swap/pim/contact#")
>> Remind you of anything?  Of course isn't XML namespaces cos it isn't XML but the elements of a list
>> we still call elements even though they aren't XML elements.
>> So I am happy to change the name of By the way, in the python code in cwm we have used Namespace() for years now.
>> e.g. in http://www.w3.org/2000/10/swap/delta.py
>> #daml = Namespace("http://www.daml.org/2001/03/daml+oil#")
>> OWL = Namespace("http://www.w3.org/2002/07/owl#")
>> RDF = Namespace("http://www.w3.org/1999/02/22-rdf-syntax-ns#")
>> LOG = Namespace("http://www.w3.org/2000/10/swap/log#")
>> DELTA = Namespace("http://www.w3.org/2004/delta#")
>> (Of course in python you can then say RDF.type as an alternative to RDF('type') as one can override that in python.)
>> So if we have a better name it must be better for the website developer who is writing RDF code in JS, not because it clashes with use of the term in XML.
>> Imagine someone is coding JS for the rdf model only and wants to do it very
>> efficiently with a very natural interface.
>> So maybe foaf = vocab("http://xmlns.com/foaf/0.1/")
>> RDFS = vocab("http://www.w3.org/2000/01/rdf-schema#")
>> dc = vocab("http://purl.org/dc/elements/1.1/")
>> rss = vocab("http://purl.org/rss/1.0/")
>> contact = vocab("http://www.w3.org/2000/10/swap/pim/contact#")
>> ? hmm
>> prefix() ?
>> shortFor()
>> foaf = prefix("http://xmlns.com/foaf/0.1/")
>> RDFS = prefix("http://www.w3.org/2000/01/rdf-schema#")
>> dc = prefix("http://purl.org/dc/elements/1.1/")
>> rss = prefix("http://purl.org/rss/1.0/")
>> contact = prefix("http://www.w3.org/2000/10/swap/pim/contact#")
>> That looks like turtle.
>> Tim
>>> On 10/9/2010 1:02 PM, Nathan wrote:
>>>> Mark,
>>>> 
>>>> I forgot to (cc you in the original mail! and) note that this introduces zero dependencies on "Namespaces" in to the API and both the documentation examples and your code would be free to ignore it, in that people could use either style without anything breaking - similarly it allows "Namespaces" to be used anywhere an IRI is required (since it returns IRI) so the use-cases expand to any method which accepts an IRI.
>>>> 
>>>> Best,
>>>> 
>>>> Nathan
>>>> 
>>>> Nathan wrote:
>>>>> Tim Berners-Lee wrote:
>>>>>> The way the namespaces work I think is nice,
>>>>>> 
>>>>>> You say foaf =  $rdf.Namespace("http://....");
>>>>>> data.add(me, foaf('name'), you);
>>>>>> 
>>>>>> Now I'd make it "ns" rather than Namespace in the spirit of making it all fairly compact.
>>>>> Tim, Mark, Ivan, All,
>>>>> 
>>>>> This is a "minimal change" proposal to add tabulators Namespace functionality in to the RDFa API, together with the use-case which hopefully warrants it's inclusion.
>>>>> 
>>>>> I propose we change the definition of DataContext setMapping to be:
>>>>> 
>>>>> interface DataContext {
>>>>>   CurieResolver setMapping (in DOMString prefix, in DOMString iri);
>>>>> ...
>>>>> };
>>>>> 
>>>>> and add the following interface:
>>>>> 
>>>>> [NoInterfaceObject Callback]
>>>>> interface CurieResolver {
>>>>>   IRI resolve (in DOMString curie);
>>>>> };
>>>>> 
>>>>> This has minimal impact on the RDFa API but makes it much more usable, usage is as follows:
>>>>> 
>>>>> var foaf = context.setMapping('foaf', 'http://xmlns.com/foaf/0.1/');
>>>>> foaf('name'); // returns IRI('http://xmlns.com/foaf/0.1/name')
>>>>> 
>>>>> To illustrate how useful this is, here are two versions of the javascript required to create the following triples:
>>>>> 
>>>>> :me a foaf:Person;
>>>>>   foaf:givenname "Nathan";
>>>>>   foaf:homepage <http://webr3.org/>;
>>>>>   foaf:knows :bob, :sue.
>>>>> 
>>>>> with this proposal:
>>>>> 
>>>>> var t1 = data.createTriple(me, rdf('type') , foaf('Person') );
>>>>> var t2 = data.createTriple(me, foaf('givenname') , myName );
>>>>> var t3 = data.createTriple(me, foaf('homepage') , myHomepage );
>>>>> var t4 = data.createTriple(me, foaf('knows') , thisDoc('bob') );
>>>>> var t5 = data.createTriple(me, foaf('knows') , thisDoc('sue') );
>>>>> 
>>>>> without the proposal (current API usage):
>>>>> var t1 = data.createTriple(me, data.context.resolveCurie('rdf:type') , data.context.resolveCurie('foaf:Person') );
>>>>> var t2 = data.createTriple(me, data.context.resolveCurie('foaf:givenname') , myName );
>>>>> var t3 = data.createTriple(me, data.context.resolveCurie('foaf:homepage') , myHomepage );
>>>>> var t4 = data.createTriple(me, data.context.resolveCurie('foaf:knows') , data.context.resolveCurie(':bob') );
>>>>> var t5 = data.createTriple(me, data.context.resolveCurie('foaf:knows') , data.context.resolveCurie(':sue') );
>>>>> 
>>>>> I sincerely hope that illustrates how beneficial this would be to add, and as a bonus it keeps the entire API type safe with no additional changes needed.
>>>>> 
>>>>> Best,
>>>>> 
>>>>> Nathan
>>>>> 
>>>>> ps: here's the snipped code which makes the above examples work (remove the `var = thisDoc` etc for the usage without this change):
>>>>> 
>>>>> var thisDoc = data.context.setMapping( "" , "http://webr3.org/nathan#" );
>>>>> var rdf = data.context.setMapping( "rdf" , "http://www.w3.org/1999/02/22-rdf-syntax-ns#" );
>>>>> var foaf = data.context.setMapping( "foaf" , "http://xmlns.com/foaf/0.1/" );
>>>>> 
>>>>> var me = data.context.resolveCurie(':me');
>>>>> var myName = data.createPlainLiteral("Nathan");
>>>>> var myHomepage = data.createIRI("http://webr3.org/");
>>>>> 
>>>>> 
>>>>> 
>>> -- 
>>> Shane P. McCarron                          Phone: +1 763 786-8160 x120
>>> Managing Director                            Fax: +1 763 786-8180
>>> ApTest Minnesota                            Inet: shane@aptest.com
>>> 
>>> 
>>> 
> 
> 


Received on Wednesday, 17 November 2010 12:32:20 UTC

This archive was generated by hypermail 2.4.0 : Friday, 17 January 2020 17:05:22 UTC