Re: RDF to CSV

On 25/01/2010 9:56 AM, Steve Harris wrote:
> On 25 Jan 2010, at 04:34, Dave Beckett wrote:
>> vasavi kamdar wrote:
>>> Hi,
>>>
>>> Can any one please help me with converting an RDF file to CSV
>>> Thanks and Regards,
>>> Vasavi Kamdar
>>>
>>> The great pleasure in life is doing what people say you cannot do...
> ...
>> Of course if you want to just do a conversion, you'll need to clearly
>> think
>> what goal you want to achieve. Turning a graph into a table (CSV) is more
>> like running a query to the graph and getting back a sequence of
>> results so
>> you might want to use SPARQL for that.
>
> Right, some SPARQL stores (I don't know which ones offhand) can output
> CSV results directly, just by requesting with the correct mime type.
>
> 4store can only do TSV, but it's easy to convert.
>
> The UNIX sparql-query tool[1] can produce text files from any SPARQL
> store, but I don't think it does CSV, would be easy enough to add that
> though.
>
> - Steve
>
> [1] http://github.com/tialaramex/sparql-query
>

I recently added CSV and TSV for SPARQL queries to Jena/ARQ:

The CSV format is pragmatic.
One row of variable names, without the "?"
Then rows of strings and numbers.
No lang tags or datatypes on literals, no markers to tell strings and 
URIs apart.
End of line is \r\n as required by RFC 4180

The TSV format is more RDFy.
The first row is variable names with ?
Then rows of RDF terms in Turtle format.
Literals have quotes, and lang tags/datatypes are added.
URIs have <> round them.
End of line is \n - but I'm not sure that is what is meant by EOL in the 
defn.  It might be strictly CR+LF as various internet protocols use that.

All suggestions welcome - there aren't very strong reasons for the choices.

Used with Joseki, and the appropriate MIME types, should get back the 
requested format. Adding "&output=csv" or "&format=tsv" to the request 
also gets the named format, as it is not always quite so simple to 
modify the HTTP request header.

	Andy

Received on Monday, 25 January 2010 10:41:34 UTC