带有特殊字符的sparql查询
我正在尝试通过 Ajax 向 dbperdia 发送查询。它工作正常,但如果搜索词中有特殊字符,我总是收到一条错误消息。
我的代码看起来像
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";
并且在搜索词中具有特殊字符我收到以下错误消息。
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")}
有什么建议吗?
提前致谢!
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!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您生成的查询无效,这与您通过 AJAX 发送它无关。请注意,Virtuoso 错误消息中的查询包含诸如
resource:Venice,_Italy
之类的内容,这是非法的 SPARQL 语法。一种解决方法是在此处使用完整的 URI,因此您应该构建完整的 URI,而不是像当前的 JS 那样使用构建 QName,例如,
而不是像当前那样构建 QName:
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.
Instead of QNames like you do currently: