RDF.rb and format discovery

Hi, 

I was looking into supporting more formats for FOAFSSL-ruby, including
the recently released rdf-rdfa and rdf-n3 gems.

But what I found looks like hell:

 - there doesn't seem to be a reliable way of discovering the FOAF
file format,
 - different formats will fail with different errors,
 - when no format is given, RDF::Graph won't detect the right one (and
give unpredictable results)

The original way of doing it in FOAFSSL-ruby is to try it, and
fallback to a different format on failure.  It works, but it's so ugly
my grand-mother died.  When I tried to add new formats, I had to find
another solution.

I went for the following (ugly) algorithm (now, my grand-mother is
already dead):

 1. lookup the file extension in the given WebID
 2. lookup the Content-Type after an HTTP HEAD to the WebID
 3. GET the file and identify it from its contents
 4. fail if the format isn't known by now.

That gives a pretty good image of a house of cards, if any.

Any idea how to deal properly with auto-discovery of formats?

==
hk

Received on Wednesday, 30 June 2010 09:04:24 UTC