[BioRuby] [GSoC][NeXML and RDF API] RDF API

Anurag Priyam anurag08priyam at gmail.com
Sun Jul 25 16:27:12 EDT 2010


>
>
> I would like you all to have a rough overview of graph.rb,
> mixins/enumerable.rb and mixins/queryable.rb
>

As in to get an idea of what the API has to offer. Just reading the examples
in the doc or sifting through method names should be good enough.


> http://github.com/yeban/bioruby/blob/rdf/lib/bio/rdf/graph.rb
> http://github.com/yeban/bioruby/blob/rdf/lib/bio/rdf/mixins/enumerable.rb
> http://github.com/yeban/bioruby/blob/rdf/lib/bio/rdf/mixins/queryable.rb
>
>
A thing to notice here would be that Enumerable and Queryable mixins provide
most of the functionality to a Graph object. Both these modules build on top
of 'each' iterator.


> So a graph contains RDF::Statements that can be enumerated and queried over
> in various movies.
>

I really do no know how the word *movies* got in when I wanted to write
*ways*. Maybe, because I was discussing the Inception movie with my friend
while composing the last mail :P. I am sorry.


>
> Then have a look at the Annotatable module:
> http://github.com/yeban/bioruby/blob/rdf/lib/bio/rdf/mixins/annotatable.rb
>
> To make a class annotatable this module just needs to be included. Say:
> class Bio::NeXML::Otu
>   include Bio::RDF::Annotatable
> end
>
>
With the above snippet we have all the annotation functionality available to
any class.


> The idea is to add an instance variable( @graph ) to Otu that stores a
> RDF::Graph object and delegate methods that begin with 'rdf_' to @graph.
> This way all the API defined for a Graph is available to an Annotatable
> object( by prefixing the method names with an 'rdf_' )
>
> otu = Bio::NeXML::Otu.new( 't1')
> otu.annotate do |g|
>   g << [ otu, CDAO[ :label ], "XXX" ]
>   g << [ otu, CDAO[ :discoverer ], "Moo" ]
> end
>
> otu.rdf_query( :predicate => CDAO[ :label ] ) { |s| puts s.subject }
>
> is same as
>
> otu.annotation.query(:predicate => CDAO[ :label ]) { |s| puts s.subject }
>

Another solution could be to define an 'each' iterator in Annotatable and
mixin the Enumerable and Queryable( mentioned above ) module. With the
former solution the advantage is that all the RDF related methods for a
class start with 'rdf_'; sounds more contextual. While with the later
solution chances are quite good that somebody would override the 'each'
iterator or any other method defined by the RDF API.

I find delegation to be quite an elegant solution in this case, though the
method I have employed for delegation might not be good( method_missing ).

A problem that I am facing with delegation is testing. Should I write tests(
specs, in this case ) for each possible 'rdf_*' function that can be called
on Annotatable?

it "should delegate Annotatable#query to Graph#query"

These tests will become very redundant, essentially doing the same thing
again and again. I was thinking in this direction:

http://github.com/yeban/bioruby/blob/rdf/spec/rdf/annotatable.rb#L44

Suggestions or pointers?

-- 
Anurag Priyam,
3rd Year Undergraduate,
Department of Mechanical Engineering,
IIT Kharagpur.
+91-9775550642


More information about the BioRuby mailing list