Re: RDF to CSV

On 25 Jan 2010, at 10:41, Andy Seaborne wrote:
>> 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

Seems reasonable. When we get round to doing CSV we'll do the same.

> 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.

This is exactly what we do too. It was arrived at as the thing that  
worked in the most software with fewest issues.

One additional is that we escape tabs as '\', 't'.

> 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.

Again, ditto.

- Steve

-- 
Steve Harris, Garlik Limited
2 Sheen Road, Richmond, TW9 1AE, UK
+44 20 8973 2465  http://www.garlik.com/
Registered in England and Wales 535 7233 VAT # 849 0517 11
Registered office: Thames House, Portsmouth Road, Esher, Surrey, KT10  
9AD

Received on Monday, 25 January 2010 13:31:47 UTC