Re: Experimental RDFa extractor in JS

Hi Gregg,

2012/4/20 Gregg Kellogg <gregg@greggkellogg.net>:
> Niklas, this is great! I think creating JSON-LD from RDFa is a natural thing to do, and of course, we can always get triples out of JSON-LD.
>
> I had been thinking of a CoffeeScript implementation too, but ClojureScript is tempting.

Thanks! Indeed, the approach appears quite natural. And it was fun,
since I took quite the opposite approach from clj-rdfa. Whereas in
Clojure I took the purely functional route (naturally), here I really
indulge in mutating state. It makes for a radically different
solution. And by basically mapping the RDFa structure to a similar
JSON-LD tree, so far it is a much easier implementation (perhaps
simpler, although the inherent complexity of mutating a result tree
somewhat bars me from using that word).

Of course, this also comes from deferring the (simpler) task of
turning the data into proper triples to a subsequent JSON-LD
processor. But that's kind of the gist of this approach. For many
scenarios just using the JSON-LD might be a lot easier. Provided that
the programmer is aware of the structural context (prefixes, terms and
framing) inherent in the specific RDFa usage within the page. It's a
tradeoff. (If the context is unknown, the general form and explicit
information of triples is needed. Which, of course, is the gist of
RDF.)

Best regards,
Niklas


> Gregg
>
> On Apr 19, 2012, at 4:58 PM, Niklas Lindström wrote:
>
>> Hi all!
>>
>> The last couple of days I've been experimenting with a different kind
>> of approach to implementing an RDFa extractor. The result so far is a
>> draft with admittedly rather partial coverage. However, I hope some
>> aspects of it will be of interest even at this stage:
>>
>> 1. It is implemented in pure Javascript. (Well, actually, in some 170
>> lines of CoffeeScript, but the generated result is the same.)
>> 2. It runs both in the browser and on Node (used with jsdom).
>> 3. It does not produce triples. It directly creates a JSON-LD extract
>> (corresponding in shape to the RDFa). This is the difference, and the
>> fun part.
>>
>> Now, it really doesn't handle anything but the most simple RDFa 1.1.
>> Possibly all of Lite, plus @datatype, @rel (including hanging),
>> @inlist, @rev and perhaps one or two more. It only copes with @about
>> if it's alone, it doesn't handle combinations of @rel and @property,
>> and so on. I'll strive to make it a lot more compliant given time of
>> course.
>>
>> - You can check out the code at: https://github.com/niklasl/rdfa-lab
>> - Or enjoy the bookmarklet (only tested in Firefox), available at:
>> http://niklasl.github.com/rdfa-lab/
>>
>> (Just add the latter to your bookmarks and apply on any page
>> containing RDFa. I recommend the JSONView [1] browser add-on for a
>> good experience.)
>>
>> I hope you'll enjoy the little things it can do. (For one, using the
>> resulting JSON-LD directly in a JS application should prove
>> interesting.)
>>
>> Best regards,
>> Niklas
>>
>> [1]: http://jsonview.com/
>>
>

Received on Friday, 20 April 2012 10:00:31 UTC