RDFa in Ruby, a First Stab
A new draft of RDFa [1] has been out for about a month now, and it got me to thinking about RDF again. This time, the geek in me saw the opportunity to use easily use RDF in my Atom based applications. Instead of using embedded micro formats in Atom Entries, I can create semantic relationship using preexisting ontologies (e.g. - DublinCore) in an easy to read format.
The XML generation side had near zero work thanks to Ruby On Rails’ rxml format. But I was lacking a parser to read in the RDF statements even though there were a few Ruby RDF Stores available. The only RDFa parser I found was written in Python– rdfadict.
So, I just set aside parts of the last two days and came up with my own super simple Ruby RDFa parser; I read and reread the RDFa Syntax draft document, which is still far from complete; I skipped implementation of parts of the spec: xml:base, reification, and nested CURIEs; and got something to just work. (Note: rdfadict uses XPath for its implementation. Instead, I used an iterative approach to traverse XML documents).
Basic parsing works; I also made it flexible enough for custom integration; I just need to spend time to write up the documentation and write up more test cases. I’ll move forward with it as the RDFa spec develops and when I get feedback from anyone that uses this library.
But for now, the code is hosted here: http://code.google.com/p/ruby-rdfa/.
Posted in Web
![[del.icio.us]](http://badpopcorn.com/blog/wp-content/plugins/bookmarkify/delicious.png)
![[Digg]](http://badpopcorn.com/blog/wp-content/plugins/bookmarkify/digg.png)
![[Google]](http://badpopcorn.com/blog/wp-content/plugins/bookmarkify/google.png)
![[StumbleUpon]](http://badpopcorn.com/blog/wp-content/plugins/bookmarkify/stumbleupon.png)
![[Windows Live]](http://badpopcorn.com/blog/wp-content/plugins/bookmarkify/windowslive.png)
![[Yahoo!]](http://badpopcorn.com/blog/wp-content/plugins/bookmarkify/yahoo.png)
![[Email]](http://badpopcorn.com/blog/wp-content/plugins/bookmarkify/email.png)
Nice work! Although a new draft of the primer came out just yesterday.
So just to understand what you’re doing…are you saying that when delivering content by an Atom feed, the content has metadata in it? What sort of content is it? Is it any place that others can consume it at the moment?
All the best,
Mark
Comment by Mark Birbeck — March 13, 2007 @ 7:02 pm
Hi Mark,
I’ve only started creating some test feeds to flesh out how RDFa in Atom looks. I think there are a few general ways that a developer will use RDF in Entry Resources. Pardon some missing namespaces, the following examples are illustrative.
1. To make the Atom Entry info available as RDF. For example:
<entry about=”http://example.com/myentry/id”>
<author>
<name property=”dc:author”>John Smith</name>
</author>
</entry>
2. For other metadata. That is, I have an Entry document that represents some abstract Blog Post. I want to add a geolocation to it.
<entry about=”http://example.com/myentry/id”
xmlns:geo=”geonamespace”>
<author>
<name property=”dc:author”>John Smith</name>
</author>
<meta property=’geo:lat’>51.47026</meta>
<meta property=’geo:long’>-2.59466</meta>
</entry>
3. Represent the actual resource. For example, an entry that represents some resource with the listed attributes– in this case a wooden plank.
<entry about=”http://example.com/myentry/id”
xmlns:myns=”http://example.com/myns#”>
<content type=”xhtml”>
<div>
<span property=”myns:length”>10feet</span>
<span property=”myns:width”>12feet</span>
<span property=”myns:height”>1inch</span>
<span property=”myns:material”>wood</span>
</div>
</content>
</entry>
As for #2, I still am thinking about the pros/cons/differences of RDFa and Atom Extensions. For example:
<entry about=”http://example.com/myentry/id”
xmlns:geo=”geonamespace”>
<meta property=’geo:lat’>51.47026</meta>
<meta property=’geo:long’>-2.59466</meta>
</entry>
vs
<entry about=”http://example.com/myentry/id”
xmlns:geo=”geonamespace”>
<geo :lat>51.47026</geo>
<geo :long>-2.59466</geo>
</entry>
And thanks for the heads up, I shall look at the new draft.
Comment by Ben — March 14, 2007 @ 2:46 pm