When using JENA I can use the following to perform SPARQL within R:

url = paste("http://some.web.nl:1234/main/query?query=",queryENC,"&output=csv&stylesheet=", sep = "")
results = getURL(url)

But maybe I am overlooking this but how do I perform this towards a graphdb endpoint? TSV or CSV is not a problem but other formats are as far as I can tell.

asked 19 Jun '15, 08:15

jjkoehorst's gravatar image

accept rate: 0%

edited 19 Jun '15, 08:16

If I understand your problem correctly you are looking for a way to specify the output format for the query result, correct? In Jena, you can do this with the output= parameter on your URL, but it's important to note that that is not a standardized mechanism, and will not work on SPARQL endpoint implementations other than Jena.

The standard way to specify the output format is to add a HTTP "Accept" header to your request. The value of this header should be the media type of the format you want. For example:

Accept: text/csv

to get a CSV file back, or:

Accept: application/sparql-results+json

to get JSON data back. I am not very familiar with R as a language, but from what I get after a quick Google search, you can specify HTTP headers as an extra option in your getURL call (see this link for examples), so I think you need something like this:

url = paste("http://some.web.nl:1234/main/query?query=",queryENC)
results = getURL(url, httpHeader = c(Accept = "text/csv"))

As an aside: you might want to have a look at the httr library, which seems to offer a lot of convenient additional options for doing http requests in R.


answered 19 Jun '15, 18:55

Jeen%20Broekstra's gravatar image

Jeen Broekstra
accept rate: 66%

edited 19 Jun '15, 18:55

Your answer
toggle preview

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here



Answers and Comments

Markdown Basics

  • *italic* or _italic_
  • **bold** or __bold__
  • link:[text](http://url.com/ "title")
  • image?![alt text](/path/img.jpg "title")
  • numbered list: 1. Foo 2. Bar
  • to add a line break simply add two spaces to where you would like the new line to be.
  • basic HTML tags are also supported



Asked: 19 Jun '15, 08:15

Seen: 5,796 times

Last updated: 22 Feb, 06:45

powered by BitNami OSQA