Reputation: 15220
I am trying to send a query through Ajax to dbperdia. It works fine but if the search term has special characters in it i get always an error message.
My code looks like
var IKS_QUERY = "PREFIX ontology: <http://dbpedia.org/ontology/> PREFIX property: <http://dbpedia.org/property/> PREFIX resource: <http://dbpedia.org/resource/> PREFIX position:<http://www.w3.org/2003/01/geo/wgs84_pos#> SELECT DISTINCT ?Abstract ?ThumbnailURL WHERE { resource:"+where+" ontology:abstract ?Abstract. resource:"+where+" ontology:thumbnail ?ThumbnailURL. FILTER (lang(?Abstract)=\"en\")}";
var IKS_URL = "http://dbpedia.org/sparql?default-graph-uri=http%3A%2F%2Fdbpedia.org&query=" + escape(IKS_QUERY) + "&format=json";
and having special charactes in search term I get the following error message.
Virtuoso 37000 Error SP030: SPARQL compiler, line 3: syntax error at ',' before '_Italy'
SPARQL query:
define sql:big-data-const 0
#output-format:application/sparql-results+json
define input:default-graph-uri <http://dbpedia.org> PREFIX ontology: <http://dbpedia.org/ontology/> PREFIX property: <http://dbpedia.org/property/> PREFIX resource: <http://dbpedia.org/resource/> PREFIX position:<http://www.w3.org/2003/01/geo/wgs84_pos#> SELECT DISTINCT ?Abstract ?ThumbnailURL WHERE { resource:Venice,_Italy ontology:abstract ?Abstract. resource:wherePlaceHolder ontology:thumbnail ?ThumbnailURL. FILTER (lang(?Abstract)="en")}
any suggestions?
Thanks in advance!
Upvotes: 1
Views: 2043
Reputation: 28675
Your generated query is invalid, this has nothing to do with you sending it over AJAX. Notice that the query in the Virtuoso error message has things like resource:Venice,_Italy
which is illegal SPARQL syntax.
One workaround is to use full URIs here so instead of using building QNames as your current JS does you should build full URIs e.g.
<http://dbpedia.org/resource/" + where + ">
Instead of QNames like you do currently:
resource:" + where + "
Upvotes: 3