Re: RDFa API - adding Namespace

This certainly resonate with me as an RDFLib user. The syntax there is a little bit different:

foaf = Namespace('http://xmlns.com/foaf/0.1/')

graph.add((me, foaf['homepage'] , myHomepage))

ie, it uses the dictionary syntax of python, but that is small difference. I do use that feature all the time.

Ivan


On Oct 9, 2010, at 19:44 , 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/");


----
Ivan Herman, W3C Semantic Web Activity Lead
Home: http://www.w3.org/People/Ivan/
mobile: +31-641044153
PGP Key: http://www.ivan-herman.net/pgpkey.html
FOAF: http://www.ivan-herman.net/foaf.rdf

Received on Sunday, 10 October 2010 08:21:40 UTC