Re: Querying dbpedia from the command line?

----- "Bob DuCharme" <bob@snee.com> wrote:

> From: "Bob DuCharme" <bob@snee.com>
> To: "Peter Ansell" <ansell.peter@gmail.com>
> Cc: public-lod@w3.org
> Sent: Wednesday, September 17, 2008 12:01:08 PM GMT +10:00 Brisbane
> Subject: Re: Querying dbpedia from the command line?
>
> > ----- "Bob DuCharme" <bob@snee.com> wrote:
> > 
> >> Has anyone managed to pass a URL with a SPARQL query to wget or
> curl
> >> and successfully retrieved data from dbpedia? 
> 
>  > Peter Ansell wrote:
> 
> > You need to URLEncode the SPARQL query. I am not sure how to do that
> with a command-line or wget but that is what the browser has done to
> the query when it submitted the form using HTTP GET.
> 
> I had tried several variations on that. (First I realized that [2] in
> my 
> original email had the wrong URL; it should have said the following, 
> without carriage returns:)
> 
> wget -O temp.txt http://DBpedia.org/sparql?query="PREFIX 
> db:<http://dbpedia.org/property/> SELECT * WHERE { ?city db:leaderName
> 
> ?leader ; db:subdivisionName ?subdiv ; db:elevation ?elevation . }
> LIMIT 5"
> 
> 
> Using the very handy escape/unescape page at 
> http://www.xs4all.nl/~jlpoutre/BoT/Javascript/Utils/endecode.html, I 
> made this escaped version
> 
> wget -O temp.txt 
> http://DBpedia.org/sparql?query%3D%22PREFIX%20db%3A%3Chttp%3A%2F%2Fdbpedia.org%2Fproperty%2F%3E%20SELECT%20*%20WHERE%20%7B%20%3Fcity%20db%3AleaderName%20%3Fleader%20%3B%20db%3AsubdivisionName%20%3Fsubdiv%20%3B%20db%3Aelevation%20%3Felevation%20.%20%7D%20LIMIT%205%22

A version of the above that has /sparql?query=PREFIX%20.... works[1], as long as you also take the %22 off the end. You only need to urlencode the actual sparql query, and you don't want (or need) quotes on either end of the query like you have done so far.

[1] http://preview.tinyurl.com/57rvlm

Peter

Received on Wednesday, 17 September 2008 02:16:05 UTC