ruby-rdf / rdf

RDF.rb is a pure-Ruby library for working with Resource Description Framework (RDF) data.
http://rubygems.org/gems/rdf
The Unlicense
382 stars 92 forks source link

Make it easier to enumerate serialisers #16

Closed njh closed 11 years ago

njh commented 14 years ago

Hello,

Please can you make it easier to enumerate the available serialisers. It is currently quite difficult to get the name, extensions and mime-type for each of the serialisers.

<link rel="alternate" type="application/rdf+xml" href="http://dbpedia.org/data/Oxford.rdf" title="Structured Descriptor Document (RDF/XML format)" />
<link rel="alternate" type="text/rdf+n3" href="http://dbpedia.org/data/Oxford.n3" title="Structured Descriptor Document (N3/Turtle format)" />
<link rel="alternate" type="application/json+rdf" href="http://dbpedia.org/data/Oxford.jrdf" title="Structured Descriptor Document (RDF/JSON format)" />
<link rel="alternate" type="application/json" href="http://dbpedia.org/data/Oxford.json" title="Structured Descriptor Document (RDF/JSON format)" />

It would be great to be able to do this:

f = RDF::Format.for(:ntriples) => RDF::NTriples::Format f.name => "N-Triples" f.content_types.first => "text/plain" f.file_extensions.first => "nt"

nick.

jfieber commented 14 years ago

The issue is easy access to per-format information.

The content_types and file_extensions methods return all registered types for all formats, which is necessary and useful functionality, but not necessarily what you expect from those named methods. Furthermore, that functionality is mostly for the benifit of the RDF::Format.for method and probably less interesting as a public API.

As-is, f.content_type.first will give you the canonical mime type; it is overloaded as both a getter and setter, but not symmetrically as you can only get the mime types and not the extensions. (I added the overload for MY needs, which didn't include extensions!)

But maybe that is wrong and the content_types and file_extensions methods should return only the mime types and extensions for class on which the method is called, as the RDF::Format.for method doesn't actually need an accessor method for its implementation.

That would absolutely be an API breaking change, but if it is the correct change, better to get it over with sooner rather than later.

On a different tack, I greatly appreciate rigorous regulation of adding gratuitous dependencies, but I do wonder about using the mime-types gem here and having RDF::Format simply a binding of readers and writers to mime type objects from that.

Also note that the existence of a Format doesn't imply the existence of a serializer (writer). In my own use, I developed a few one-way formats (eg, importing something non-RDF into RDF, but not attempting round-trip conversion), and rdf-raptor contains a format for Graphvis which has only a writer.

njh commented 14 years ago

John: Yes, exactly!

njh commented 12 years ago

Another note; because RDF::Writers are auto-loaded, it isn't possible to enumerate them until they have been loaded.

gkellogg commented 11 years ago

Currentlly, you can do the following:

f = RDF::Format.for(:ntriples) f.content_type => ["application/n-triples", "text/plain"]

Note that f.content_types will return all content types, as this is defined in RDF::Format.

I'll add RDF::Format#file_extension, to do the same thing.

You can get available readers or writers through RDF::Format.map(&:reader) and writers the same way. You can then get information specific to each reader/writer.