DBpedia 和 SPARQL:带重音符号的查询不起作用
所以我尝试了很多不同的事情,并一直在寻找解决方案,但没有任何运气...
我的SPARQL查询是
PREFIX dbp: <http://dbpedia.org/resource/>
PREFIX dbpedia2: <http://dbpedia.org/property/>
SELECT ?currentclub
WHERE {
dbp:".$term." dbpedia2:currentclub ?currentclub .
FILTER langMatches(lang(?currentclub), 'en')
}
当$term等于名称中带有重音符号的东西时,它就搞砸了并且没有给出结果。我尝试了很多不同的事情,但似乎无法让其中任何一个发挥作用。希望得到一些帮助。
谢谢
编辑
我正在使用PHP和curl。这是我根据需要下载并修改的东西......这是它与 dbpedia 通信的部分。
$searchUrl = 'http://dbpedia.org/sparql?'
.'query='.urlencode($query)
.'&format='.$format;
上面贴出了$query,使用的格式是json。
编辑2
这是我正在使用的源代码。 https://gist.github.com/380379 也许查看完整的代码会给你一个更好的主意出了什么问题。
我将包含带重音的姓氏的数据库字段更改为“utf8_unicode_ci”,但我仍然陷入困境,找不到任何有效的解决方案。
So I've tried a lot of different things and have been searching for a solution, but haven't had any luck...
My SPARQL query is
PREFIX dbp: <http://dbpedia.org/resource/>
PREFIX dbpedia2: <http://dbpedia.org/property/>
SELECT ?currentclub
WHERE {
dbp:".$term." dbpedia2:currentclub ?currentclub .
FILTER langMatches(lang(?currentclub), 'en')
}
When the $term equals something with an accent mark in the name it gets all screwed up and no results are given. I tried a bunch of different things, but just can't seem to get any of them to work. Hoping for some help.
Thanks
Edit
I'm using PHP and curl. It's something I downloaded and modified for my needs...here's the part where it communicates with dbpedia.
$searchUrl = 'http://dbpedia.org/sparql?'
.'query='.urlencode($query)
.'&format='.$format;
The $query is posted above and the format being used is json.
Edit 2
Here's the source code for what I'm using. https://gist.github.com/380379 maybe looking at the full code will give you a better idea of what is wrong.
I changed my database field that contains the last name with the accent to 'utf8_unicode_ci', but I'm still stuck and can't find any working solutions.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
2 您的查询存在问题:
您不能使用无效的prefix:"something"
形式的 QName。如果您需要在其中连接某些内容,那么您不应该使用引号如果是的话它应该可以工作。如果没有,那么您可以通过使用
\u0000
形式的转义来解决此问题,其中0000
是转义字符的 UTF-8 代码的十六进制表示形式。这在 QName 中应该是允许的Edit
删除了第 1 点,因为已经看到完整的源代码,很明显这只是 PHP 连接语法,而不是无用的 SPARQL 语法
看到完整的源代码后,还不清楚为什么代码应该失败。我唯一可以提出的其他建议是尝试更改代码以发送该术语的 URI 引用而不是 QName:
实际上,我不认为这会产生任何影响,但总是值得一试。
如果错误仍然存在,您可以发布一些查询不起作用的示例术语吗
2 Issues with your query:
You can't have a QName of the formprefix:"something"
that is just invalid. If you need to concatenate something in there then you should not be using the quotesIf it is then it should work. If not then you can work around this by using escapes of the form
\u0000
where0000
is the hex representation of the UTF-8 code for the escaped character. This should be permissible inside a QNameEdit
Removed Point 1 as having seen the full source it is apparant that this was just the PHP concatentation syntax and not dud SPARQL syntax
Having seen the full source it is not obvious why the code should be failing. Only other suggestion I can make is try changing the code to send a URI reference for the term rather than a QName:
Realistically I wouldn't expect that to make any difference but always worth a try.
If the error is still persisting can you post some example term(s) for which the query does not work
尝试记录编码查询,对于法兰西岛(地区),各种重音应该像这样编码:
因此'Î'字符以UTF-8编码,如%C3%8E,转换表可以是检索地址:http://www.utf8-chartable.de/
我不是 PHP 开发人员但应该有一个 UTF-8 编码库可以帮助你。
Try to log the encoded query, for the Île-de-France (region), the various accents should be encoded like this:
Therefore the'Î' char is encoded in UTF-8 like %C3%8E, a conversion table can be retrievet at: http://www.utf8-chartable.de/
I'm not a PHP developer but there should be a UTF-8 encoding library that should help you.