开发者

DBpedia and SPARQL: Query with accent marks does not work

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 ca开发者_运维百科n'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.


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


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜