Skip to main content

developerWorks >  XML  >  Forums  >  Exploring Semantic Web Technologies  >  developerWorks

SPARQL - Special characters    Point your RSS reader here for a feed of the latest messages in this thread


     

 
 

My developerWorks
 Welcome, Guest
Sign in or register
Permlink Replies: 6 - Pages: 1 - Last Post: Nov 8, 2009 11:16 AM Last Post By: Haba
Haba

Posts: 7
Registered: Sep 29, 2009 04:48:11 PM
SPARQL - Special characters
Posted: Nov 04, 2009 10:04:33 AM
Click to report abuse...   Click to reply to this thread Reply
Hi,

How can I represent characters such as parenthesis in a SPARQL query? For example, how could I post this query without any errors:

PREFIX db: <http://dbpedia.org/resource/>
SELECT * WHERE {
db:Orange_(fruit) ?pf1 db:Fruit
}

Thank you,
Pedro

robertc

Posts: 38
Registered: Feb 29, 2008 06:35:32 PM
Re: SPARQL - Special characters
Posted: Nov 07, 2009 09:44:50 AM   in response to: Haba in response to: Haba's post
Click to report abuse...   Click to reply to this thread Reply
Hi Pedro. If you have a literal value you can enclose it in quotes, this query reports no syntax errors for me:

PREFIX db: <http://dbpedia.org/resource/>
SELECT * WHERE {
"db:Orange_(fruit)" ?pf1 db:Fruit
}

Rob
Haba

Posts: 7
Registered: Sep 29, 2009 04:48:11 PM
Re: SPARQL - Special characters
Posted: Nov 07, 2009 05:12:53 PM   in response to: robertc in response to: robertc's post
Click to report abuse...   Click to reply to this thread Reply
The problem is it's not a literal value. It is a DBpedia resource: http://dbpedia.org/resource/Orange_(fruit)

Any thoughts?

Thanks
Haba

Posts: 7
Registered: Sep 29, 2009 04:48:11 PM
Re: SPARQL - Special characters
Posted: Nov 07, 2009 05:24:50 PM   in response to: Haba in response to: Haba's post
Click to report abuse...   Click to reply to this thread Reply
Actually, I would think that this should work: http://dbpedia.org/resource/Orange_%28fruit%29
But apparently '%' isn't accepted either: 37000 Error SP030: SPARQL compiler, line 0: Invalid character in SPARQL expression at '%'
robertc

Posts: 38
Registered: Feb 29, 2008 06:35:32 PM
Re: SPARQL - Special characters
Posted: Nov 07, 2009 08:05:55 PM   in response to: Haba in response to: Haba's post
Click to report abuse...   Click to reply to this thread Reply
Hi Pedro. So did you try putting that in quotes like the example I gave? Or is this resource appearing somewhere other than in the query you posted?

Rob

--Edit: OK, I'm seeing the same error as you now. Don't know why it worked for me earlier...

Message was edited by: robertc
robertc

Posts: 38
Registered: Feb 29, 2008 06:35:32 PM
Re: SPARQL - Special characters
Posted: Nov 07, 2009 08:40:35 PM   in response to: Haba in response to: Haba's post
Click to report abuse...   Click to reply to this thread Reply
Hi Pedro. I'm not sure if it's working, because I can't get it to return any data, but I think the correct syntax is to put angle brackets around the resource:

PREFIX db: <http://dbpedia.org/resource/>
SELECT * WHERE {
<db:Orange_(fruit)> ?pf1 db:Fruit
}

When I use the above there are no errors, but all that appears on the results page is the column header pf1.

Rob

--edit Using the SPARQL Explorer I generated this example, which would imply a query like this is the correct form:

PREFIX db: <http://dbpedia.org/resource/>
SELECT * WHERE {
<db:Orange_%28fruit%29> ?pf1 db:Fruit
}

Still no results for me, though.

Message was edited by: robertc
Haba

Posts: 7
Registered: Sep 29, 2009 04:48:11 PM
Re: SPARQL - Special characters
Posted: Nov 08, 2009 11:16:02 AM   in response to: robertc in response to: robertc's post
Click to report abuse...   Click to reply to this thread Reply
It seems to me, after some testing against the dbpedia sparql endpoint, that substituting the parenthesis with %28 and %29 works only when prefixes are not used, and the resources are enclosed in ... Can anyone confirm this behavior?
 Tags
Help

Use the search field to find all types of content in My developerWorks with that tag.

Use the slider bar to see more or fewer tags.

Popular tags shows the top tags for this particular type of content or application that you're viewing.

My tags shows your tags for this particular type of content or application that you're viewing.

 

MoreLess 


Point your RSS reader here for a feed of the latest messages in all forums