0

I want to query the endpoint of wordnet from java code using http get. I get the connection to the endpoint "wordnet.rkbexplorer.com" but I get an error, that sparsql-query is not correct. The query itself is executed, when I just type it on the website of wordnet.rkbexplorer.com. Is the syntax of my URL for GTTP GET not correct? I have not much experience in that area.

My code:

URL url = new URL("http://wordnet.rkbexplorer.com/sparql/?query="+query);
HttpURLConnection con = (HttpURLConnection) url.openConnection();
con.setRequestMethod("GET");
String query =  "PREFIX id:   <http://wordnet.rkbexplorer.com/id/> "
              + "PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#> "
              + "SELECT * WHERE { ?s rdfs:label ?o } LIMIT 10";

Error:

error at URI 3store:default#:1 - syntax error, unexpected $end, expecting identifier
Martijn Pieters
  • 1,048,767
  • 296
  • 4,058
  • 3,343
Salvadora
  • 359
  • 1
  • 3
  • 11

1 Answers1

0

This can be debugged with something like Firebug. Its network tab shows what's sent to the server on the HTTP level. In this case you can see the form on the web page is using POST. The server seems to expect POST, and this works:

curl --data "query=PREFIX id:   <http://wordnet.rkbexplorer.com/id/> PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#> SELECT * WHERE { ?s rdfs:label ?o } LIMIT 10" "http://wordnet.rkbexplorer.com/sparql/"

So just switch your code to use POST instead of GET.

Daniel Naber
  • 1,594
  • 12
  • 19
  • Hi Daniel. There is an info on the website of the endpoint, that http get is also possible: "You can also make HTTP GET requests to /sparql/?query=...". I would like to try it. My Java-Code for HTTP POST works, but maybe I have some small error in my code for http get, which I can't find. – Salvadora Dec 10 '12 at 12:46
  • This seems to be an encoding issue with the GET request. For example, this works for me: curl "http://southampton.rkbexplorer.com/sparql/?query=PREFIX+rdfs%3A+%3Chttp%3A%2F%2Fwww.w3.org%2F2000%2F01%2Frdf-schema%23%3E%0D%0ASELECT+*+WHERE+%7B+%3Fs+rdfs%3Alabel+%3Fo+%7D+LIMIT+10%0D%0A%0D%0A" – Daniel Naber Dec 10 '12 at 17:07
  • Problem solved by adding: query=URLEncoder.encode(query, "UTF-8"). I also thought, that encoding was the problem, but your comment was helpful anyway. Thank You Daniel! – Salvadora Dec 10 '12 at 23:11