Re: Latest versions of the RDFa DOM API document and JS prototype

On 04/15/2010 11:17 AM, Benjamin Adrian wrote:
> The current document version:
> http://www.w3.org/2010/02/rdfa/sources/rdfa-dom-api/
> The current JS prototype: 
> http://www.w3.org/2010/02/rdfa/sources/rdfa-dom-api/rdfa_dom_api.js

Took a quick look through it - looking better and better...

> - Tell the group if you are missing any features.

I passed the RDFa API by our CTO, who is also an excellent Javascript
developer (and one of the best damn technical minds I have had the
pleasure of knowing), at Digital Bazaar. He took a look at it and had
some comments that we talked through. Keep in mind that he was not very
knowledge-able about RDF or RDFa before the discussion, but was able to
understand the current iteration of the entire API in very little time
(less than 1 hour).

Here are the things that we discovered by discussing the API:

The constructs, like XSD["integer"] may be better implemented as
properties of the global "rdfa" object, instead of as global objects
themselves. So, instead of:

XSD["integer"] => URI("http://www.w3.org/2001/XMLSchema#integer")

something like this:

rdfa.xsd.integer => URI("http://www.w3.org/2001/XMLSchema#integer")

You can add mappings like so:

rdfa.setMapping("xsd", "integer",
                new URI("http://www.w3.org/2001/XMLSchema#integer"));

or like this:

rdfa.xsd = {
  "integer" : new URI("http://www.w3.org/2001/XMLSchema#integer"),
  "string" : new URI("http://www.w3.org/2001/XMLSchema#string"),
  "decimal" : new URI("http://www.w3.org/2001/XMLSchema#decimal"),
  "float" : new URI("http://www.w3.org/2001/XMLSchema#float"),
  "boolean" : new URI("http://www.w3.org/2001/XMLSchema#boolean"),
  "date" : new URI("http://www.w3.org/2001/XMLSchema#date"),
  "time" : new URI("http://www.w3.org/2001/XMLSchema#time"),
  "dateTime" : new URI("http://www.w3.org/2001/XMLSchema#dateTime"),
};

and use them like so:

var x = new TypedLiteral("W3C", rdfa.xsd.string);

or even short-cut it by doing this:

var foaf = rdfa.foaf;
var bk = new RDFTriple("#bk", foaf.name, "Ben Kingsley");

or with Mark's proposal:

// print out all of the people names in a page
var people = rdfa.filterObjectsByType(foaf.Person);
for(i in people)
{
   var p = people[i];
   if(p[foaf.name])
   {
      alert("Found person named: " + p[foaf.name]);
   }
}

We also found out that this construct is only valid in Javascript 1.6,
and is not implemented in the ECMA standard:

for each ([s,p,o] in rdfa.filter(...)) { ... }

bummer, because it would be such a nice construct to use. We tested it
in Google Chrome and it doesn't work. That is going to affect how we do
loop iteration. We may be forced to do something like this:

var triples = rdfa.filter("http://example.org/people#me");
for(i in triples)
{
   // this: yuck!
   var s = triples[i][0];
   var p = triples[i][1];
   var o = triples[i][2];

   // OR this: slightly better, but still gross
   var s = triples[i].subject;
   var p = triples[i].predicate;
   var o = triples[i].object;

   // when we really want to do this:
   [s, p, o] = triples[i];
}

We could override the forEach prototype on arrays that are passed back
via rdfa.filter, so something like this could work:

var triples = rdfa.filter("http://example.org/people#me");
triples.forEach( function(s, p, o)
{
   alert("Subject: " + s + " Predicate: " + p + " Object: " + o);
};

We could also do this, which is close to what Mark is asking for:

var foaf = rdfa.foaf;
var people = rdfa.filterObjectsByType(foaf.Person);
people.each(function(p)
{
   alert("Name: " + p[foaf.name] + " Homepage: " + p[foaf.homepage]);
};

While the above is powerful, I think giving developers access to the
underlying data model (triples) is a requirement, not a nice to have.
While Benjamin and I were talking, we were discussing how you could
probably implement a SPARQL engine using the RDFa DOM API and Javascript
by just using the [s, p, o] construct and rdfa.filter(). I think that's
a very good goal to have, and one that I'm not convinced Mark's proposal
accomplishes.

That said, I think we should have both.

-- manu

-- 
Manu Sporny (skype: msporny, twitter: manusporny)
President/CEO - Digital Bazaar, Inc.
blog: PaySwarming Goes Open Source
http://blog.digitalbazaar.com/2010/02/01/bitmunk-payswarming/

Received on Friday, 16 April 2010 01:44:30 UTC