Re: RDF/RDFa API: Structuring graph data

Hi Manu,

Manu Sporny wrote:
> var library = jsonld.toObject(jsonLdText, objectFrame);

That's very JSON-LD specific, and the problem, as you noted, affects 
all RDF(a).

I'd put it simply, that we need to be able to turn a graph, in to a 
tree, or in to a set of objects.

Very roughly, each "Object" would need to be a standard object where 
the properties are (terms,curies,uris) and each value is either a js 
primitive type or another object, the "Object" would need a "getID" 
method returning the subject, and possibly "getTypes"/"hasType".

   graph.toObjects(?filter,?profile)

filter allows you to select objects by filter (say by rdf:type or x:age)

profile allows you to pass in an optional profile, where every 
property encountered is passed through the "shrink" method, thus 
meaning the properties of the returned objects are simple terms or curies.

And thus, usage would be (for any RDF)

  graph.toObjects( bookFilter, myterms ).forEach( function(book) {
   book.contains.forEach( function(chapter) {
    console.log("Book: " + book.title + " Chapter: " + chapter.title);
   });
  });

There is however directionality to take in to account, since we're 
dealing with graphs, so it may be prudent to include rev links as 
well, such that one could do:

  graph.toObjects( chapterFilter ).forEach( function(chapter) {
   console.log("Book: " + chapter.rev.contains.title + " Chapter: " + 
chapter.title);
  });

We can do this kind of thing with out any increased memory footprint 
since each object is just a reference to an object, which also removes 
recursion problems.

That said, it may be even easier to take a selector type approach, 
syntax such as:

   select("Book.title Book.contains.title")

Best,

Nathan

Received on Thursday, 27 January 2011 01:31:05 UTC