Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Querying with Spaces Sparql

Say if I want to return the result "having fun" of the triple. I don't know how to account for the space in between the words. Below is a query I tried but it didn't work. Let me know if anyone can spot what I doing wrong

<rdf:Description rdf:about="http://website.com/urls/playing games">
    <owl:sameAs rdf:resource="http://website.com/urls/having fun"/>
</rdf:Description>

"PREFIX owl: <http://www.w3.org/2002/07/owl#> SELECT * WHERE { ?y owl:sameAs+ <http://website.com/urls/playing fun> }";
like image 983
Sam Avatar asked Jan 29 '12 17:01

Sam


2 Answers

Short answer: You can't, at least not directly.

Slightly longer answer: RDF itself uses RDF URI references. The SPARQL query language, on the other hand, uses IRIs (the reason is that RDF predates IRIs and the notion of RDF URI references was developed in anticipation of what IRIs were expected to eventually look like. They almost got it right :)).

Unfortunately, there is a discrepancy between the definitions of RDF URI references and IRIs, and you have just hit one of the cases: while RDF URI references allow whitespaces, IRIs do not. The SPARQL syntax can not cope with URI references such as the one in your example. Have a look at this discussion for more details.

Your best bet? Avoid using spaces in URI refs. Replace them with underscores or just remove them.

All that being said, there is a workaround to make your query work:

PREFIX owl: <http://www.w3.org/2002/07/owl#> 
SELECT ?y 
WHERE { 
   ?y owl:sameAs+ ?x
   FILTER (str(?x) = "http://website.com/urls/playing fun")
}
like image 53
Jeen Broekstra Avatar answered Sep 30 '22 14:09

Jeen Broekstra


  1. It's owl:sameAs not owl:sameas. Note capital A.
  2. You can't have spaces in IRIs.
like image 44
user205512 Avatar answered Sep 30 '22 14:09

user205512