This relates to this question.
As part of my SPARQL query - I need to address the following resource:
Which contains round bracket characters. ‘(’ and ‘)’
I can do this using the ‘@base’ reference like this:
@base <http://dbpedia.org/resource/> .
@prefix dbo: <http://dbpedia.org/ontology/> .
@prefix dbp: <http://dbpedia.org/property/> .
@prefix dbr: <http://dbpedia.org/resource/> .
@prefix : <http://dbpedia.org/resource/>.
SELECT *
WHERE
{
?person a dbo:Person.
FILTER(
?person IN (<Brian_Cox_(physicist)> )
)
} LIMIT 10
But is there a way of using a prefix instead?
The following gives an error:
SELECT *
WHERE
{
?person a dbo:Person.
FILTER(
?person IN ( dbr:Brian_Cox_(physicist) )
)
} LIMIT 10
Error:
Virtuoso 37000 Error SP030: SPARQL compiler, line 16: syntax error at 'physicist' before ')'
For contrast - the following works when the resource URL doesn’t contain any brackets:
@base <http://dbpedia.org/resource/> .
@prefix dbo: <http://dbpedia.org/ontology/> .
@prefix dbp: <http://dbpedia.org/property/> .
@prefix dbr: <http://dbpedia.org/resource/> .
@prefix : <http://dbpedia.org/resource/>.
SELECT *
WHERE
{
?person a dbo:Person.
FILTER(
?person IN (dbr:Robin_Ince )
)
} LIMIT 10
But I can’t work out if there is a syntax that allows me to ‘escape’ the URI and use the prefix at the same time.
I have tried using URLEncoded characters like this:
@base <http://dbpedia.org/resource/> .
@prefix dbo: <http://dbpedia.org/ontology/> .
@prefix dbp: <http://dbpedia.org/property/> .
@prefix dbr: <http://dbpedia.org/resource/> .
@prefix : <http://dbpedia.org/resource/>.
SELECT *
WHERE
{
?person a dbo:Person.
FILTER(
?person IN ( dbr:Brian_Cox_%28physicist%29)
)
} LIMIT 10
This avoids the SPARQL parse error - but doesn’t match anything.