Musicbrainz query problem resolved

Thanks to Mischa Tuffield  [mischa.tuffield@garlik.com] for pointing out the need to escape characters like slashes, colons, question marks, hashes, curly brackets.  The angle brackets, text and numbers are preserved.

I'm building a Greasemonkey user script to run in Firefox.  The general architecture of the Greasemonkey HTTP request looks like this:

===== snip  ===============

endpoint = "http://dbtune.org/musicbrainz/sparql";

query = [see discussion below]

GM_xmlhttpRequest({
    method: 'GET',
    url: endpoint + '?query=' + query,
    headers: {
        'User-agent': 'Mozilla/4.0 (compatible) Greasemonkey',
        'Accept': 'text/html',
    },
    onload: function(responseDetails) { 

	  alert(responseDetails.responseText);
	  
    }
==========================


The escaped query worked like a charm the first time that I tried it.

It would seem that the difference between my original query

=====
"prefix foaf: <http://xmlns.com/foaf/0.1/>  prefix rdf:  <http://www.w3.org/1999/02/22-rdf-syntax-ns#>  SELECT ?type WHERE { ?name foaf:name 'Screwtape' . ?name rdf:type ?type  }";
=====

and Mischa's query

=======
prefix foaf%3A <http%3A%2F%2Fxmlns.com%2Ffoaf%2F0.1%2F>  prefix rdf%3A  <http%3A%2F%2Fwww.w3.org%2F1999%2F02%2F22-rdf-syntax-ns%23>  SELECT %3Ftype WHERE { %3Fname foaf%3Aname 'Screwtape' . %3Fname rdf%3Atype %3Ftype  }
=======

is the escaping of characters like slashes, colons, question marks, hashes, curly brackets.  The angle brackets, text and numbers are preserved.


Terry



Terry Brooks
Information School
Suite 370, Mary Gates Hall
Box 352840
Seattle, WA 98195-2840
________________________________________
From: Richard Cyganiak [richard@cyganiak.de]
Sent: Tuesday, August 25, 2009 3:40 AM
To: Terry Brooks
Cc: 'public-lod@w3.org'
Subject: Re: Help with Musicbrainz

Terry,

How exactly are you submitting your HTTP request? What did you do in
order to obtain the error message? I get the same message when I
remove the closing angle bracket on the rdf: namespace URI, or when I
insert whitespace anywhere in that URI. Did any of these things happen
by chance?

(Kurt: It's probably not a problem with escaping the brackets, the
"&lt;" bit is just because the web server tries to respond with an
error message in HTML, and therefore the web server escapes the
brackets in the error message. This doesn't mean they were encoded in
the request.)

Best,
Richard


On 25 Aug 2009, at 00:42, Terry Brooks wrote:

> I'm trying to build a query for Musicbrainz.
>
> At the SPARQL explorer for Musicbrainz,   (http://dbtune.org/musicbrainz/snorql/
>   )this query works:
>
> ==== SNIP =========
>
> SELECT ?type WHERE {
> ?name foaf:name 'Screwtape' . ?name rdf:type ?type .
> }
>
> =============
>
> but  when I try an HTTP request to the SPARQL endpoint ("http://dbtune.org/musicbrainz/sparql
> ";) with the following query, I must  include PREFIX:
>
> "prefix foaf: <http://xmlns.com/foaf/0.1/>  prefix rdf:  <http://www.w3.org/1999/02/22-rdf-syntax-ns#
> >  SELECT ?type WHERE { ?name foaf:name 'Screwtape' . ?name
> rdf:type ?type  }";
>
> and I get a parsing error that seems to indicate some parsing
> problem with the angle brackets:
>
> ====== SNIP ============
>
> <title>Error 400 Parse error:
> prefix foaf: &lt;http://xmlns.com/foaf/0.1/&gt;  prefix rdf:  &lt;http://www.w3.org/1999/02/22-rdf-syntax-ns
>
> Encountered "&lt;" at line 1, column 57.
> Was expecting:
>    &lt;IRIref&gt; ...
>    </title>
> </head>
>
> ===============
>
> Does someone have a working example of an HTTP request to the SPARQL
> endpoint to Musicbrainz that includes more than one PREFIX that
> finesses the angle brackets problem?
>
> Thanks,
>
>
> Terry Brooks
> Information School
> Suite 370, Mary Gates Hall
> Box 352840
> Seattle, WA 98195-2840
>
>
>
>

Received on Tuesday, 25 August 2009 15:18:42 UTC