Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Escape special characters in SPARQL queries

I'm trying to query dpbedia to get the categories of some wikipedia articles using Jena and ARQ
For example:

select ?category { dbpedia:ARTICLE_NAME dcterms:subject ?category }  

Here is an example of a working query
SPARQL results

The problem is when there are special characters in ARTICLE_NAME for example "Parma_F.C.", where there is "."

select ?category { dbpedia:Parma_F.C. dcterms:subject ?category } 

ERROR

So, I would like to ask you if someone had a solution for that.
Thanks in advance

like image 996
paskun Avatar asked Nov 09 '14 16:11

paskun


1 Answers

The identifier dbpedia:Parma_F.C. is a so-called prefixed name, that is, an abbreviated form of a full URI. The full syntax rules for it are described in the SPARQL 1.1 Query Language specification.

The problem is specifically the full stop at the end of the prefixed name. According to the SPARQL grammar, a prefixed name cannot end on a full stop unless it's escaped. The fix is simply to use a backslash:

 dbpedia:Parma_F.C\. 

What you can also do as an alternative, is just write out the full URI. The dbpedia prefix maps to the http://dbpedia.org/resource/ namespace, so the full URI in SPARQL would become:

 <http://dbpedia.org/resource/Parma_F.C.>

and the full query would become:

select ?category { <http://dbpedia.org/resource/Parma_F.C.> dcterms:subject ?category } 
like image 192
Jeen Broekstra Avatar answered Oct 01 '22 12:10

Jeen Broekstra