DBpedia 和 SPARQL:带重音符号的查询不起作用

发布于 2024-10-20 13:05:50 字数 937 浏览 6 评论 0原文

所以我尝试了很多不同的事情,并一直在寻找解决方案,但没有任何运气...

我的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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

晨光如昨 2024-10-27 13:05:50

2 您的查询存在问题:

  1. 您不能使用无效的 prefix:"something" 形式的 QName。如果您需要在其中连接某些内容,那么您不应该使用引号
  2. 您确定您的查询(尤其是重音符号)采用 UTF-8 格式吗?
    如果是的话它应该可以工作。如果没有,那么您可以通过使用 \u0000 形式的转义来解决此问题,其中 0000 是转义字符的 UTF-8 代码的十六进制表示形式。这在 QName 中应该是允许的

Edit

删除了第 1 点,因为已经看到完整的源代码,很明显这只是 PHP 连接语法,而不是无用的 SPARQL 语法

看到完整的源代码后,还不清楚为什么代码应该失败。我唯一可以提出的其他建议是尝试更改代码以发送该术语的 URI 引用而不是 QName:

 $query =
   "PREFIX dbp: <http://dbpedia.org/resource/>
PREFIX dbp2: <http://dbpedia.org/ontology/>
SELECT ?abstract
WHERE {
<http://dbpedia.org/resource/".$term."> dbp2:abstract ?abstract .
FILTER langMatches(lang(?abstract), 'en')
}";

实际上,我不认为这会产生任何影响,但总是值得一试。

如果错误仍然存​​在,您可以发布一些查询不起作用的示例术语吗

2 Issues with your query:

  1. You can't have a QName of the form prefix:"something" that is just invalid. If you need to concatenate something in there then you should not be using the quotes
  2. Are you sure your query and particularly the accents are in UTF-8?
    If it is then it should work. If not then you can work around this by using escapes of the form \u0000 where 0000 is the hex representation of the UTF-8 code for the escaped character. This should be permissible inside a QName

Edit

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:

 $query =
   "PREFIX dbp: <http://dbpedia.org/resource/>
PREFIX dbp2: <http://dbpedia.org/ontology/>
SELECT ?abstract
WHERE {
<http://dbpedia.org/resource/".$term."> dbp2:abstract ?abstract .
FILTER langMatches(lang(?abstract), 'en')
}";

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

暮色兮凉城 2024-10-27 13:05:50

尝试记录编码查询,对于法兰西岛(地区),各种重音应该像这样编码:

select distinct ?p ?o  where {
  <http://dbpedia.org/resource/%C3%8Ele-de-France_(region)> ?p ?o
}

因此'Î'字符以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:

select distinct ?p ?o  where {
  <http://dbpedia.org/resource/%C3%8Ele-de-France_(region)> ?p ?o
}

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文