Querying with Spaces Sparql
Asked Answered
A

2

6

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> }";
Antiphrasis answered 29/1, 2012 at 17:28 Comment(0)
A
9

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")
}
Attenuator answered 29/1, 2012 at 20:50 Comment(1)
great answer probably going to avoid the spacesAntiphrasis
S
2
  1. It's owl:sameAs not owl:sameas. Note capital A.
  2. You can't have spaces in IRIs.
Sumerian answered 29/1, 2012 at 20:55 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.