Escape special characters in SPARQL queries
Asked Answered
Z

1

7

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

Zumwalt answered 9/11, 2014 at 16:6 Comment(0)
M
8

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 } 
Mesomorph answered 9/11, 2014 at 18:22 Comment(2)
Thanks for the answer. I tried to replace it with the full URI but it still doesn't work. May I ask you to show me how you did it exactly? Could you please paste a link for that through the dbpedia API? Thanks againZumwalt
@JeenBroekstra Which characters need to be escaped in full URI syntax? I assume it is <, >, `\`?Disarming

© 2022 - 2024 — McMap. All rights reserved.